diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index a9f508b83..34aa965af 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -121,10 +121,6 @@ public class OverdriveThatMatters { // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); 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 MinecraftForge.EVENT_BUS.register(this); @@ -179,16 +175,4 @@ public class OverdriveThatMatters { MinecraftForge.EVENT_BUS.register(AndroidGui.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())); - } } diff --git a/src/main/java/ru/dbotthepony/mc/otm/Registry.java b/src/main/java/ru/dbotthepony/mc/otm/Registry.java index 11a7f0533..cdaab1af9 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/Registry.java +++ b/src/main/java/ru/dbotthepony/mc/otm/Registry.java @@ -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.BlockEntitySphereDebugger; 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.core.Fraction; import ru.dbotthepony.mc.otm.item.*; @@ -823,6 +824,7 @@ public class Registry { @SuppressWarnings("unused") public static void registerRenderers(final FMLClientSetupEvent event) { BlockEntityRenderers.register(BLACK_HOLE, BlackHoleRenderer::new); + BlockEntityRenderers.register(GRAVITATION_STABILIZER, GravitationStabilizerRenderer::new); } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/BlackHoleRenderer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/BlackHoleRenderer.kt index 9d69b1846..6257de0ac 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/BlackHoleRenderer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/BlackHoleRenderer.kt @@ -6,12 +6,14 @@ import com.mojang.math.Matrix4f import net.minecraft.client.Minecraft import net.minecraft.client.renderer.GameRenderer 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.BlockEntityRendererProvider import net.minecraft.resources.ResourceLocation import net.minecraft.world.phys.Vec3 import org.lwjgl.opengl.GL30 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.core.* @@ -63,8 +65,8 @@ private fun beam(matrix4f: Matrix4f, builder: BufferBuilder, fwdRotation: Double private fun quadY(z: Double): Array { return arrayOf( Vector(0.0, -BEAM_WIDTH, z), - Vector(64.0, -BEAM_WIDTH, z), - Vector(64.0, BEAM_WIDTH, z), + Vector(BlockEntityGravitationStabilizer.RANGE.toDouble(), -BEAM_WIDTH, z), + Vector(BlockEntityGravitationStabilizer.RANGE.toDouble(), BEAM_WIDTH, z), Vector(0.0, BEAM_WIDTH, z) ) } @@ -72,14 +74,12 @@ private fun quadY(z: Double): Array { private fun quadZ(y: Double): Array { return arrayOf( Vector(0.0, y, -BEAM_WIDTH), - Vector(64.0, y, -BEAM_WIDTH), - Vector(64.0, y, BEAM_WIDTH), + Vector(BlockEntityGravitationStabilizer.RANGE.toDouble(), y, -BEAM_WIDTH), + Vector(BlockEntityGravitationStabilizer.RANGE.toDouble(), 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 { override fun render( blockEntityBlackHole: BlockEntityBlackHole, @@ -110,7 +110,7 @@ class BlackHoleRenderer(private val context: BlockEntityRendererProvider.Context if (ply != null && ply.mainHandItem.item == Registry.Items.GRAVITATION_STABILIZER) { RenderSystem.setShader(GameRenderer::getPositionTexShader) - RenderSystem.setShaderTexture(0, BEACON_BEAM) + RenderSystem.setShaderTexture(0, BeaconRenderer.BEAM_LOCATION) RenderSystem.disableCull() val builder = Tesselator.getInstance().builder diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt new file mode 100644 index 000000000..59b7fe849 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/Ext.kt @@ -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) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/GravitationStabilizerRenderer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/GravitationStabilizerRenderer.kt new file mode 100644 index 000000000..b6a1db565 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/GravitationStabilizerRenderer.kt @@ -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 { + 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) + } + } + } +}