Graviational stabilizer renderer
This commit is contained in:
parent
35e8b554c5
commit
1b4cf9498a
@ -121,10 +121,6 @@ public class OverdriveThatMatters {
|
|||||||
// Register the setup method for modloading
|
// Register the setup method for modloading
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupClient);
|
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupClient);
|
||||||
// Register the enqueueIMC method for modloading
|
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
|
|
||||||
// Register the processIMC method for modloading
|
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
|
|
||||||
|
|
||||||
// Register ourselves for server and other game events we are interested in
|
// Register ourselves for server and other game events we are interested in
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
@ -179,16 +175,4 @@ public class OverdriveThatMatters {
|
|||||||
MinecraftForge.EVENT_BUS.register(AndroidGui.class);
|
MinecraftForge.EVENT_BUS.register(AndroidGui.class);
|
||||||
MinecraftForge.EVENT_BUS.register(EventHandler.class);
|
MinecraftForge.EVENT_BUS.register(EventHandler.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enqueueIMC(final InterModEnqueueEvent event) {
|
|
||||||
// some example code to dispatch IMC to another mod
|
|
||||||
InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processIMC(final InterModProcessEvent event) {
|
|
||||||
// some example code to receive and process InterModComms from other mods
|
|
||||||
LOGGER.info("Got IMC {}", event.getIMCStream().
|
|
||||||
map(m->m.messageSupplier().get()).
|
|
||||||
collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityBlackHole;
|
|||||||
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityExplosionDebugger;
|
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityExplosionDebugger;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntitySphereDebugger;
|
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntitySphereDebugger;
|
||||||
import ru.dbotthepony.mc.otm.client.render.BlackHoleRenderer;
|
import ru.dbotthepony.mc.otm.client.render.BlackHoleRenderer;
|
||||||
|
import ru.dbotthepony.mc.otm.client.render.GravitationStabilizerRenderer;
|
||||||
import ru.dbotthepony.mc.otm.client.render.SkinElement;
|
import ru.dbotthepony.mc.otm.client.render.SkinElement;
|
||||||
import ru.dbotthepony.mc.otm.core.Fraction;
|
import ru.dbotthepony.mc.otm.core.Fraction;
|
||||||
import ru.dbotthepony.mc.otm.item.*;
|
import ru.dbotthepony.mc.otm.item.*;
|
||||||
@ -823,6 +824,7 @@ public class Registry {
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static void registerRenderers(final FMLClientSetupEvent event) {
|
public static void registerRenderers(final FMLClientSetupEvent event) {
|
||||||
BlockEntityRenderers.register(BLACK_HOLE, BlackHoleRenderer::new);
|
BlockEntityRenderers.register(BLACK_HOLE, BlackHoleRenderer::new);
|
||||||
|
BlockEntityRenderers.register(GRAVITATION_STABILIZER, GravitationStabilizerRenderer::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,12 +6,14 @@ import com.mojang.math.Matrix4f
|
|||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.client.renderer.GameRenderer
|
import net.minecraft.client.renderer.GameRenderer
|
||||||
import net.minecraft.client.renderer.MultiBufferSource
|
import net.minecraft.client.renderer.MultiBufferSource
|
||||||
|
import net.minecraft.client.renderer.blockentity.BeaconRenderer
|
||||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
|
||||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
|
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
import net.minecraft.world.phys.Vec3
|
import net.minecraft.world.phys.Vec3
|
||||||
import org.lwjgl.opengl.GL30
|
import org.lwjgl.opengl.GL30
|
||||||
import ru.dbotthepony.mc.otm.Registry
|
import ru.dbotthepony.mc.otm.Registry
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityGravitationStabilizer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityBlackHole
|
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityBlackHole
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
|
|
||||||
@ -63,8 +65,8 @@ private fun beam(matrix4f: Matrix4f, builder: BufferBuilder, fwdRotation: Double
|
|||||||
private fun quadY(z: Double): Array<Vector> {
|
private fun quadY(z: Double): Array<Vector> {
|
||||||
return arrayOf(
|
return arrayOf(
|
||||||
Vector(0.0, -BEAM_WIDTH, z),
|
Vector(0.0, -BEAM_WIDTH, z),
|
||||||
Vector(64.0, -BEAM_WIDTH, z),
|
Vector(BlockEntityGravitationStabilizer.RANGE.toDouble(), -BEAM_WIDTH, z),
|
||||||
Vector(64.0, BEAM_WIDTH, z),
|
Vector(BlockEntityGravitationStabilizer.RANGE.toDouble(), BEAM_WIDTH, z),
|
||||||
Vector(0.0, BEAM_WIDTH, z)
|
Vector(0.0, BEAM_WIDTH, z)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -72,14 +74,12 @@ private fun quadY(z: Double): Array<Vector> {
|
|||||||
private fun quadZ(y: Double): Array<Vector> {
|
private fun quadZ(y: Double): Array<Vector> {
|
||||||
return arrayOf(
|
return arrayOf(
|
||||||
Vector(0.0, y, -BEAM_WIDTH),
|
Vector(0.0, y, -BEAM_WIDTH),
|
||||||
Vector(64.0, y, -BEAM_WIDTH),
|
Vector(BlockEntityGravitationStabilizer.RANGE.toDouble(), y, -BEAM_WIDTH),
|
||||||
Vector(64.0, y, BEAM_WIDTH),
|
Vector(BlockEntityGravitationStabilizer.RANGE.toDouble(), y, BEAM_WIDTH),
|
||||||
Vector(0.0, y, BEAM_WIDTH)
|
Vector(0.0, y, BEAM_WIDTH)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val BEACON_BEAM = ResourceLocation("minecraft", "textures/entity/beacon_beam.png")
|
|
||||||
|
|
||||||
class BlackHoleRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<BlockEntityBlackHole> {
|
class BlackHoleRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<BlockEntityBlackHole> {
|
||||||
override fun render(
|
override fun render(
|
||||||
blockEntityBlackHole: BlockEntityBlackHole,
|
blockEntityBlackHole: BlockEntityBlackHole,
|
||||||
@ -110,7 +110,7 @@ class BlackHoleRenderer(private val context: BlockEntityRendererProvider.Context
|
|||||||
|
|
||||||
if (ply != null && ply.mainHandItem.item == Registry.Items.GRAVITATION_STABILIZER) {
|
if (ply != null && ply.mainHandItem.item == Registry.Items.GRAVITATION_STABILIZER) {
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
||||||
RenderSystem.setShaderTexture(0, BEACON_BEAM)
|
RenderSystem.setShaderTexture(0, BeaconRenderer.BEAM_LOCATION)
|
||||||
RenderSystem.disableCull()
|
RenderSystem.disableCull()
|
||||||
|
|
||||||
val builder = Tesselator.getInstance().builder
|
val builder = Tesselator.getInstance().builder
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.client.render
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer
|
||||||
|
import com.mojang.math.Matrix4f
|
||||||
|
import ru.dbotthepony.mc.otm.core.Vector
|
||||||
|
|
||||||
|
fun VertexConsumer.normal(vector: Vector) = normal(vector.x.toFloat(), vector.y.toFloat(), vector.z.toFloat())
|
||||||
|
fun VertexConsumer.vertex(matrix4f: Matrix4f, vector: Vector) = vertex(matrix4f, vector.x.toFloat(), vector.y.toFloat(), vector.z.toFloat())
|
||||||
|
fun VertexConsumer.color(color: RGBAColor) = color(color.r, color.g, color.b, color.a)
|
@ -0,0 +1,160 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.client.render
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.*
|
||||||
|
import com.mojang.math.Matrix4f
|
||||||
|
import net.minecraft.client.renderer.MultiBufferSource
|
||||||
|
import net.minecraft.client.renderer.RenderType
|
||||||
|
import net.minecraft.client.renderer.blockentity.BeaconRenderer
|
||||||
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
|
||||||
|
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
|
||||||
|
import net.minecraft.client.renderer.texture.OverlayTexture
|
||||||
|
import net.minecraft.core.Direction
|
||||||
|
import ru.dbotthepony.mc.otm.block.BlockBlackHole
|
||||||
|
import ru.dbotthepony.mc.otm.block.BlockMatteryRotatable
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityGravitationStabilizer
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityBlackHole
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState
|
||||||
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
|
import kotlin.math.PI
|
||||||
|
|
||||||
|
private val BEAM_RENDER_TYPE_INNER = RenderType.beaconBeam(BeaconRenderer.BEAM_LOCATION, false)
|
||||||
|
private val BEAM_RENDER_TYPE_OUTER = RenderType.beaconBeam(BeaconRenderer.BEAM_LOCATION, true)
|
||||||
|
|
||||||
|
class GravitationStabilizerRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<BlockEntityGravitationStabilizer> {
|
||||||
|
override fun render(
|
||||||
|
tile: BlockEntityGravitationStabilizer,
|
||||||
|
p_112308_: Float,
|
||||||
|
poseStack: PoseStack,
|
||||||
|
p_112310_: MultiBufferSource,
|
||||||
|
p_112311_: Int,
|
||||||
|
p_112312_: Int
|
||||||
|
) {
|
||||||
|
if (tile.blockState.getValue(WorkerState.SEMI_WORKER_STATE) != WorkerState.WORKING)
|
||||||
|
return
|
||||||
|
|
||||||
|
var len = 64.0
|
||||||
|
val normal = tile.blockState.getValue(BlockMatteryRotatable.FACING_FULL).normal
|
||||||
|
val level = tile.level
|
||||||
|
|
||||||
|
if (level != null) {
|
||||||
|
for (i in 1 .. BlockEntityGravitationStabilizer.RANGE) {
|
||||||
|
val pos = tile.blockPos + normal * i
|
||||||
|
|
||||||
|
if (level.getBlockEntity(tile.blockPos + pos) is BlockEntityBlackHole || level.getBlockState(pos).block is BlockBlackHole) {
|
||||||
|
len = i.toDouble()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
poseStack.pushPose()
|
||||||
|
poseStack.translate(0.5, 0.5, 0.5)
|
||||||
|
|
||||||
|
val matrix = poseStack.last().pose()
|
||||||
|
|
||||||
|
run {
|
||||||
|
val rotation = (System.currentTimeMillis().toDouble() / 1000.0) % (PI * 2)
|
||||||
|
val consumer = p_112310_.getBuffer(BEAM_RENDER_TYPE_INNER)
|
||||||
|
|
||||||
|
when (tile.blockState.getValue(BlockMatteryRotatable.FACING_FULL)) {
|
||||||
|
Direction.DOWN -> ray(matrix, consumer, len, rotation, -PI / 2, 0.0, RAY_RADIUS_INNER)
|
||||||
|
Direction.UP -> ray(matrix, consumer, len, rotation, PI / 2, 0.0, RAY_RADIUS_INNER)
|
||||||
|
Direction.NORTH -> ray(matrix, consumer, len, rotation, 0.0, PI / 2, RAY_RADIUS_INNER)
|
||||||
|
Direction.SOUTH -> ray(matrix, consumer, len, rotation, 0.0, -PI / 2, RAY_RADIUS_INNER)
|
||||||
|
Direction.WEST -> ray(matrix, consumer, len, rotation, 0.0, PI, RAY_RADIUS_INNER)
|
||||||
|
Direction.EAST -> ray(matrix, consumer, len, rotation, 0.0, 0.0, RAY_RADIUS_INNER)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run {
|
||||||
|
val consumer = p_112310_.getBuffer(BEAM_RENDER_TYPE_OUTER)
|
||||||
|
val rotation = (-System.currentTimeMillis().toDouble() / 700.0) % (PI * 2)
|
||||||
|
|
||||||
|
when (tile.blockState.getValue(BlockMatteryRotatable.FACING_FULL)) {
|
||||||
|
Direction.DOWN -> ray(matrix, consumer, len, rotation, -PI / 2, 0.0, RAY_RADIUS_OUTER, OUTER_COLOR)
|
||||||
|
Direction.UP -> ray(matrix, consumer, len, rotation, PI / 2, 0.0, RAY_RADIUS_OUTER, OUTER_COLOR)
|
||||||
|
Direction.NORTH -> ray(matrix, consumer, len, rotation, 0.0, PI / 2, RAY_RADIUS_OUTER, OUTER_COLOR)
|
||||||
|
Direction.SOUTH -> ray(matrix, consumer, len, rotation, 0.0, -PI / 2, RAY_RADIUS_OUTER, OUTER_COLOR)
|
||||||
|
Direction.WEST -> ray(matrix, consumer, len, rotation, 0.0, PI, RAY_RADIUS_OUTER, OUTER_COLOR)
|
||||||
|
Direction.EAST -> ray(matrix, consumer, len, rotation, 0.0, 0.0, RAY_RADIUS_OUTER, OUTER_COLOR)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
poseStack.popPose()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldRenderOffScreen(p_112306_: BlockEntityGravitationStabilizer) = true
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val OUTER_COLOR = RGBAColor(140, 140, 255, 110)
|
||||||
|
private const val RAY_RADIUS_INNER = 0.2
|
||||||
|
private const val RAY_RADIUS_OUTER = 0.24
|
||||||
|
private const val k = 2.414213562373095 // 1.0 + sqrt(2.0)
|
||||||
|
private const val kSquared = 1.3065629648763766 // sqrt(k / (k - 1))
|
||||||
|
private const val PI_STEP = PI / 4
|
||||||
|
|
||||||
|
private fun quad(
|
||||||
|
matrix4f: Matrix4f,
|
||||||
|
builder: VertexConsumer,
|
||||||
|
len: Double,
|
||||||
|
fwdRotation: Double,
|
||||||
|
rightRotation: Double,
|
||||||
|
topRotation: Double,
|
||||||
|
anim: Float,
|
||||||
|
rayRadius: Double,
|
||||||
|
color: RGBAColor
|
||||||
|
) {
|
||||||
|
val rayWidth = rayRadius / kSquared
|
||||||
|
|
||||||
|
var a = Vector(0.0, -rayRadius, -rayWidth / 1.84)
|
||||||
|
var b = Vector(len, -rayRadius, -rayWidth / 1.84)
|
||||||
|
var c = Vector(len, -rayRadius, rayWidth / 1.84)
|
||||||
|
var d = Vector(0.0, -rayRadius, rayWidth / 1.84)
|
||||||
|
var normal = VECTOR_DOWN
|
||||||
|
|
||||||
|
if (fwdRotation != 0.0) {
|
||||||
|
a = a.rotateAroundAxis(VECTOR_FORWARD, fwdRotation)
|
||||||
|
b = b.rotateAroundAxis(VECTOR_FORWARD, fwdRotation)
|
||||||
|
c = c.rotateAroundAxis(VECTOR_FORWARD, fwdRotation)
|
||||||
|
d = d.rotateAroundAxis(VECTOR_FORWARD, fwdRotation)
|
||||||
|
normal = normal.rotateAroundAxis(VECTOR_FORWARD, fwdRotation)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rightRotation != 0.0) {
|
||||||
|
a = a.rotateAroundAxis(VECTOR_RIGHT, rightRotation)
|
||||||
|
b = b.rotateAroundAxis(VECTOR_RIGHT, rightRotation)
|
||||||
|
c = c.rotateAroundAxis(VECTOR_RIGHT, rightRotation)
|
||||||
|
d = d.rotateAroundAxis(VECTOR_RIGHT, rightRotation)
|
||||||
|
normal = normal.rotateAroundAxis(VECTOR_RIGHT, rightRotation)
|
||||||
|
} else if (topRotation != 0.0) {
|
||||||
|
a = a.rotateAroundAxis(VECTOR_UP, topRotation)
|
||||||
|
b = b.rotateAroundAxis(VECTOR_UP, topRotation)
|
||||||
|
c = c.rotateAroundAxis(VECTOR_UP, topRotation)
|
||||||
|
d = d.rotateAroundAxis(VECTOR_UP, topRotation)
|
||||||
|
normal = normal.rotateAroundAxis(VECTOR_UP, topRotation)
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.vertex(matrix4f, b).color(color).uv(0f, anim).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(15728880).normal(normal).endVertex()
|
||||||
|
builder.vertex(matrix4f, c).color(color).uv(1f, anim).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(15728880).normal(normal).endVertex()
|
||||||
|
builder.vertex(matrix4f, d).color(color).uv(1f, anim + len.toFloat()).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(15728880).normal(normal).endVertex()
|
||||||
|
builder.vertex(matrix4f, a).color(color).uv(0f, anim + len.toFloat()).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(15728880).normal(normal).endVertex()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ray(
|
||||||
|
matrix4f: Matrix4f,
|
||||||
|
builder: VertexConsumer,
|
||||||
|
len: Double,
|
||||||
|
fwdRotation: Double,
|
||||||
|
rightRotation: Double,
|
||||||
|
topRotation: Double,
|
||||||
|
rayRadius: Double,
|
||||||
|
color: RGBAColor = RGBAColor.WHITE
|
||||||
|
) {
|
||||||
|
val anim = (((System.currentTimeMillis().toDouble() / 100.0) % 100.0).toFloat() / 100f) * len.toFloat()
|
||||||
|
|
||||||
|
for (i in 0 until 8) {
|
||||||
|
quad(matrix4f, builder, len, i * PI_STEP + fwdRotation, rightRotation, topRotation, anim, rayRadius, color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user