diff --git a/build.gradle b/build.gradle index ed2b406a9..3365d3119 100644 --- a/build.gradle +++ b/build.gradle @@ -83,7 +83,7 @@ repositories { } dependencies { - minecraft 'net.minecraftforge:forge:1.15.2-31.1.27' + minecraft 'net.minecraftforge:forge:1.15.2-31.1.36' // compile against the JEI API but do not include it at runtime compileOnly fg.deobf("mezz.jei:jei-1.15.2:6.0.0.2:api") diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index e5e95a7ed..d847c29fd 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -5,14 +5,15 @@ import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FAC import java.util.Map; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.SuperByteBuffer; import net.minecraft.block.BlockState; +import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.util.Direction; -import net.minecraft.util.Direction.Axis; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.event.ModelRegistryEvent; @@ -120,9 +121,13 @@ public enum AllBlockPartials { } public SuperByteBuffer renderOnDirectional(BlockState referenceState, Direction facing) { - SuperByteBuffer renderPartial = CreateClient.bufferCache.renderPartial(this, referenceState); - renderPartial.rotateCentered(Axis.X, AngleHelper.rad(AngleHelper.verticalAngle(facing))); - renderPartial.rotateCentered(Axis.Y, AngleHelper.rad(AngleHelper.horizontalAngle(facing))); + MatrixStack ms = new MatrixStack(); + // TODO 1.15 find a way to cache this model matrix computation + ms.translate(0.5, 0.5, 0.5); + ms.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(AngleHelper.rad(AngleHelper.horizontalAngle(facing)))); + ms.multiply(Vector3f.POSITIVE_X.getRadialQuaternion(AngleHelper.rad(AngleHelper.verticalAngle(facing)))); + ms.translate(-0.5, -0.5, -0.5); + SuperByteBuffer renderPartial = CreateClient.bufferCache.renderDirectionalPartial(this, referenceState, facing, ms); return renderPartial; } diff --git a/src/main/java/com/simibubi/create/ClientEvents.java b/src/main/java/com/simibubi/create/ClientEvents.java index ac1b10b86..514875425 100644 --- a/src/main/java/com/simibubi/create/ClientEvents.java +++ b/src/main/java/com/simibubi/create/ClientEvents.java @@ -18,9 +18,11 @@ import com.simibubi.create.modules.contraptions.relays.belt.BeltConnectorItemHan import com.simibubi.create.modules.curiosities.zapper.terrainzapper.TerrainZapperRenderHandler; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.item.ItemStack; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.InputEvent.KeyInputEvent; @@ -70,13 +72,23 @@ public class ClientEvents { @SubscribeEvent public static void onRenderWorld(RenderWorldLastEvent event) { MatrixStack ms = event.getMatrixStack(); - IRenderTypeBuffer buffer = Minecraft.getInstance().getBufferBuilders().getEntityVertexConsumers(); + ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); + Vec3d view = info.getProjectedView(); + + ms.push(); + ms.translate(-view.getX(), -view.getY(), -view.getZ()); + + IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getBufferBuilders().getEntityVertexConsumers(); CreateClient.schematicHandler.render(ms, buffer, 0xF000F0, OverlayTexture.DEFAULT_UV); CreateClient.schematicAndQuillHandler.render(ms, buffer); CreateClient.schematicHologram.render(ms, buffer); KineticDebugger.renderSourceOutline(ms, buffer); ChassisRangeDisplay.renderOutlines(event.getPartialTicks(), ms, buffer); TerrainZapperRenderHandler.render(ms, buffer); + + ms.pop(); + + buffer.draw(); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java index f1a839a34..183a4e242 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java @@ -1,11 +1,14 @@ package com.simibubi.create.foundation.utility; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; +import com.mojang.datafixers.util.Pair; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.BufferBuilder.DrawState; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.Vector4f; @@ -14,7 +17,6 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.AxisDirection; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; public class SuperByteBuffer { @@ -44,11 +46,12 @@ public class SuperByteBuffer { private int r, g, b, a; public SuperByteBuffer(BufferBuilder buf) { - ByteBuffer original = ObfuscationReflectionHelper.getPrivateValue(BufferBuilder.class, buf, "field_179001_a"); // FIXME speedup - original.rewind(); + Pair state = buf.popData(); + ByteBuffer original = state.getSecond(); + original.order(ByteOrder.nativeOrder()); // Vanilla bug, endianness does not carry over into sliced buffers this.original = original; - - this.mutable = GLAllocation.createDirectByteBuffer(original.capacity()); + + this.mutable = GLAllocation.createDirectByteBuffer(state.getFirst().getCount() * buf.getVertexFormat().getSize()); this.mutable.order(original.order()); this.mutable.limit(original.limit()); mutable.put(this.original); @@ -61,8 +64,8 @@ public class SuperByteBuffer { original.rewind(); mutable.rewind(); - Matrix4f t = transforms.peek().getModel(); - t.multiply(input.peek().getModel()); + Matrix4f t = input.peek().getModel().copy(); + t.multiply(transforms.peek().getModel()); for (int vertex = 0; vertex < vertexCount(original); vertex++) { Vector4f pos = new Vector4f(getX(original, vertex), getY(original, vertex), getZ(original, vertex), 1F); @@ -94,6 +97,7 @@ public class SuperByteBuffer { shouldShiftUV = false; shouldColor = false; shouldLight = false; + mutable.rewind(); return mutable; } @@ -134,7 +138,7 @@ public class SuperByteBuffer { } public SuperByteBuffer rotateCentered(Direction axis, float radians) { - return translate(-.5f, -.5f, -.5f).rotate(axis, radians).translate(.5f, .5f, .5f); + return translate(.5f, .5f, .5f).rotate(axis, radians).translate(-.5f, -.5f, -.5f); } public SuperByteBuffer shiftUV(TextureAtlasSprite from, TextureAtlasSprite to) { @@ -245,7 +249,8 @@ public class SuperByteBuffer { } protected void putLight(ByteBuffer buffer, int index, int packedLight) { - buffer.putInt(getBufferPosition(index) + 24, packedLight); + buffer.putShort(getBufferPosition(index) + 24, (short) (packedLight & 0xFF)); + buffer.putShort(getBufferPosition(index) + 26, (short) ((packedLight >> 16) & 0xFF)); } protected void putColor(ByteBuffer buffer, int index, byte r, byte g, byte b, byte a) { diff --git a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBufferCache.java b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBufferCache.java index 88f9d13d6..adb1a16cd 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBufferCache.java +++ b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBufferCache.java @@ -7,6 +7,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; +import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; import com.google.common.cache.Cache; @@ -22,6 +23,7 @@ import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraftforge.client.model.data.EmptyModelData; @@ -32,6 +34,7 @@ public class SuperByteBufferCache { public static final Compartment GENERIC_TILE = new Compartment<>(); public static final Compartment PARTIAL = new Compartment<>(); + public static final Compartment> DIRECTIONAL_PARTIAL = new Compartment<>(); Map, Cache> cache; @@ -39,6 +42,7 @@ public class SuperByteBufferCache { cache = new HashMap<>(); registerCompartment(GENERIC_TILE); registerCompartment(PARTIAL); + registerCompartment(DIRECTIONAL_PARTIAL); } public SuperByteBuffer renderBlock(BlockState toRender) { @@ -48,6 +52,18 @@ public class SuperByteBufferCache { public SuperByteBuffer renderPartial(AllBlockPartials partial, BlockState referenceState) { return get(PARTIAL, partial, () -> standardModelRender(partial.get(), referenceState)); } + + public SuperByteBuffer renderPartial(AllBlockPartials partial, BlockState referenceState, MatrixStack modelTransform) { + return get(PARTIAL, partial, () -> standardModelRender(partial.get(), referenceState, modelTransform)); + } + + public SuperByteBuffer renderDirectionalPartial(AllBlockPartials partial, BlockState referenceState, Direction dir) { + return get(DIRECTIONAL_PARTIAL, Pair.of(dir, partial), () -> standardModelRender(partial.get(), referenceState)); + } + + public SuperByteBuffer renderDirectionalPartial(AllBlockPartials partial, BlockState referenceState, Direction dir, MatrixStack modelTransform) { + return get(DIRECTIONAL_PARTIAL, Pair.of(dir, partial), () -> standardModelRender(partial.get(), referenceState, modelTransform)); + } public SuperByteBuffer renderBlockIn(Compartment compartment, BlockState toRender) { return get(compartment, toRender, () -> standardBlockRender(toRender)); @@ -82,16 +98,16 @@ public class SuperByteBufferCache { } private SuperByteBuffer standardModelRender(IBakedModel model, BlockState referenceState) { + return standardModelRender(model, referenceState, new MatrixStack()); + } + + private SuperByteBuffer standardModelRender(IBakedModel model, BlockState referenceState, MatrixStack ms) { BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); BlockModelRenderer blockRenderer = dispatcher.getBlockModelRenderer(); - BufferBuilder builder = new BufferBuilder(0); + BufferBuilder builder = new BufferBuilder(DefaultVertexFormats.BLOCK.getIntegerSize()); Random random = new Random(); - MatrixStack ms = new MatrixStack(); - ms.push(); - ms.translate(0, 1, 0); - builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); - blockRenderer.renderModelFlat(Minecraft.getInstance().world, model, referenceState, BlockPos.ZERO.down(), ms, + blockRenderer.renderModelFlat(Minecraft.getInstance().world, model, referenceState, BlockPos.ZERO.up(255), ms, builder, true, random, 42, OverlayTexture.DEFAULT_UV, EmptyModelData.INSTANCE); builder.finishDrawing(); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/KineticDebugger.java b/src/main/java/com/simibubi/create/modules/contraptions/KineticDebugger.java index 5b03361aa..a8d98a300 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/KineticDebugger.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/KineticDebugger.java @@ -3,17 +3,21 @@ package com.simibubi.create.modules.contraptions; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.config.AllConfigs; +import com.simibubi.create.modules.contraptions.base.IRotate; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; +import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.world.ClientWorld; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.World; @@ -28,6 +32,7 @@ public class KineticDebugger { World world = Minecraft.getInstance().world; BlockPos toOutline = te.hasSource() ? te.source : te.getPos(); + BlockState state = te.getBlockState(); VoxelShape shape = world.getBlockState(toOutline).getShape(world, toOutline); IVertexBuilder vb = buffer.getBuffer(RenderType.getLines()); @@ -38,6 +43,27 @@ public class KineticDebugger { ms.scale(f, f, f); WorldRenderer.func_228431_a_(ms, vb, shape, 0, 0, 0, te.hasSource() ? .5f : 1, .75f, .75f, 1); + + Vec3i offset = te.getPos().subtract(toOutline); + ms.translate(offset.getX(), offset.getY(), offset.getZ()); + + if (state.getBlock() instanceof IRotate) { + Axis axis = ((IRotate)state.getBlock()).getRotationAxis(state); + switch (axis) { + case X: + vb.vertex(ms.peek().getModel(), 0, 0.5f, 0.5f).color(1f, 1f, 1f, 1f).endVertex(); + vb.vertex(ms.peek().getModel(), 1, 0.5f, 0.5f).color(1f, 1f, 1f, 1f).endVertex(); + break; + case Y: + vb.vertex(ms.peek().getModel(), 0.5f, 0, 0.5f).color(1f, 1f, 1f, 1f).endVertex(); + vb.vertex(ms.peek().getModel(), 0.5f, 1, 0.5f).color(1f, 1f, 1f, 1f).endVertex(); + break; + case Z: + vb.vertex(ms.peek().getModel(), 0.5f, 0.5f, 0).color(1f, 1f, 1f, 1f).endVertex(); + vb.vertex(ms.peek().getModel(), 0.5f, 0.5f, 1).color(1f, 1f, 1f, 1f).endVertex(); + break; + } + } ms.pop(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/DirectionalAxisKineticBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/base/DirectionalAxisKineticBlock.java index ed131dfd3..49b8c9b23 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/DirectionalAxisKineticBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/DirectionalAxisKineticBlock.java @@ -109,7 +109,7 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc if (pistonAxis == Axis.Z) return alongFirst ? Axis.X : Axis.Y; - return super.getRotationAxis(state); + throw new IllegalStateException("Unknown axis??"); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java index 486f97d9e..1de9a9e9c 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java @@ -11,7 +11,6 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; -import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; @@ -58,11 +57,6 @@ public abstract class KineticBlock extends Block implements IRotate { return false; } - @Override - public Axis getRotationAxis(BlockState state) { - return null; - } - // Block @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntityRenderer.java index b8d091ba5..ed4e4fe5c 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntityRenderer.java @@ -12,13 +12,10 @@ import com.simibubi.create.foundation.utility.SuperByteBufferCache.Compartment; import com.simibubi.create.modules.contraptions.KineticDebugger; import net.minecraft.block.BlockState; -import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.math.BlockPos; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @@ -64,7 +61,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer