diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 8bd192394..99e2b08ec 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -1,25 +1,27 @@ package com.simibubi.create.content.contraptions.base; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlocks; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; -import com.simibubi.create.foundation.render.Compartment; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; +import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.Compartment; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; 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.minecraft.world.LightType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @@ -36,11 +38,20 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer(te)); + public static void renderRotatingKineticBlock(KineticTileEntity te, BlockState renderedState, MatrixStack ms, + IVertexBuilder buffer, int light) { + SuperByteBuffer superByteBuffer = CreateClient.bufferCache.renderBlockIn(KINETIC_TILE, renderedState); + renderRotatingBuffer(te, superByteBuffer, ms, buffer, light); + } + + public static void renderRotatingBuffer(KineticTileEntity te, SuperByteBuffer superBuffer, MatrixStack ms, + IVertexBuilder buffer, int light) { + standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, buffer); } public static float getAngleForTe(KineticTileEntity te, final BlockPos pos, Axis axis) { @@ -105,5 +116,8 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer> renderMaterial = contraption.getActorMaterial(); + + BlockState state = context.state; + InstancedModel model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); + + model.setupInstance(data -> { + Direction facing = state.get(DrillBlock.FACING); + float eulerX = AngleHelper.verticalAngle(facing) + ((facing.getAxis() == Direction.Axis.Y) ? 180 : 0); + float eulerY = facing.getHorizontalAngle(); + data.setPosition(context.localPos) + .setBlockLight(contraption.renderWorld.getLightLevel(LightType.BLOCK, context.localPos)) + .setRotationOffset(0) + .setRotationAxis(0, 0, 1) + .setLocalRotation(eulerX, eulerY, 0); + }); + } + @Override protected InstancedModel getModel() { return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(modelManager, tile.getBlockState()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java index 2ec0ed260..9aed18005 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java @@ -42,7 +42,7 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour { @Override public void addInstance(RenderedContraption contraption, MovementContext context) { - DrillRenderer.addInstanceForContraption(contraption, context); + DrillInstance.addInstanceForContraption(contraption, context); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index 5a124d5a2..57e858cde 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -1,28 +1,23 @@ package com.simibubi.create.content.contraptions.components.actors; +import static net.minecraft.state.properties.BlockStateProperties.FACING; + import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.contraption.ContraptionProgram; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RenderMaterial; -import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; + import net.minecraft.block.BlockState; 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.world.LightType; - -import static net.minecraft.state.properties.BlockStateProperties.FACING; public class DrillRenderer extends KineticTileEntityRenderer { @@ -30,26 +25,13 @@ public class DrillRenderer extends KineticTileEntityRenderer { super(dispatcher); } - protected static SuperByteBuffer getRotatingModel(BlockState state) { - return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(state); + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(te.getBlockState()); } - public static void addInstanceForContraption(RenderedContraption contraption, MovementContext context) { - RenderMaterial> renderMaterial = contraption.getActorMaterial(); - - BlockState state = context.state; - InstancedModel model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); - - model.setupInstance(data -> { - Direction facing = state.get(DrillBlock.FACING); - float eulerX = AngleHelper.verticalAngle(facing) + ((facing.getAxis() == Direction.Axis.Y) ? 180 : 0); - float eulerY = facing.getHorizontalAngle(); - data.setPosition(context.localPos) - .setBlockLight(contraption.renderWorld.getLightLevel(LightType.BLOCK, context.localPos)) - .setRotationOffset(0) - .setRotationAxis(0, 0, 1) - .setLocalRotation(eulerX, eulerY, 0); - }); + protected static SuperByteBuffer getRotatingModel(BlockState state) { + return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(state); } public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index 8c706264b..7311e30c7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -1,9 +1,10 @@ package com.simibubi.create.content.contraptions.components.actors; +import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; + import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.contraption.RenderedContraption; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RenderMaterial; @@ -11,7 +12,9 @@ import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingAct import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -22,8 +25,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.LightType; -import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; - public class HarvesterRenderer extends SafeTileEntityRenderer { public HarvesterRenderer(TileEntityRendererDispatcher dispatcher) { @@ -82,4 +83,7 @@ public class HarvesterRenderer extends SafeTileEntityRenderer { @@ -151,12 +152,12 @@ public class MechanicalCrafterRenderer extends SafeTileEntityRenderer { public DeployerRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); } - @Override - public boolean isGlobalRenderer(DeployerTileEntity te) { - return true; - } - @Override protected void renderSafe(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { renderItem(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); renderComponents(te, partialTicks, ms, buffer, light, overlay); - } protected void renderItem(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, - int light, int overlay) { + int light, int overlay) { BlockState deployerState = te.getBlockState(); Vec3d offset = getHandOffset(te, partialTicks, deployerState).add(VecHelper.getCenterOf(BlockPos.ZERO)); ms.push(); @@ -102,6 +102,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer protected void renderComponents(DeployerTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); + KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te), ms, vb, light); BlockState blockState = te.getBlockState(); BlockPos pos = te.getPos(); @@ -111,10 +112,10 @@ public class DeployerRenderer extends SafeTileEntityRenderer SuperByteBuffer hand = te.getHandPose() .renderOn(blockState); - transform(te.getWorld(), (SuperByteBuffer) pole.translate(offset.x, offset.y, offset.z), blockState, pos, true).renderInto(ms, - vb); - transform(te.getWorld(), (SuperByteBuffer) hand.translate(offset.x, offset.y, offset.z), blockState, pos, false).renderInto(ms, - vb); + transform(te.getWorld(), pole.translate(offset.x, offset.y, offset.z), blockState, pos, true).renderInto(ms, + vb); + transform(te.getWorld(), hand.translate(offset.x, offset.y, offset.z), blockState, pos, false).renderInto(ms, + vb); } protected Vec3d getHandOffset(DeployerTileEntity te, float partialTicks, BlockState blockState) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index 6c857986c..cf65e08f5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -1,20 +1,21 @@ package com.simibubi.create.content.contraptions.components.fan; +import static net.minecraft.state.properties.BlockStateProperties.FACING; + import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.world.LightType; - -import static net.minecraft.state.properties.BlockStateProperties.FACING; public class EncasedFanRenderer extends KineticTileEntityRenderer { @@ -25,7 +26,29 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - super.renderSafe(te, partialTicks, ms, buffer, light, overlay); + Direction direction = te.getBlockState() + .get(FACING); + IVertexBuilder vb = buffer.getBuffer(RenderType.getCutoutMipped()); + + int lightBehind = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction.getOpposite())); + int lightInFront = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction)); + + SuperByteBuffer shaftHalf = + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction.getOpposite()); + SuperByteBuffer fanInner = + AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouth(te.getBlockState(), direction.getOpposite()); + + float time = AnimationTickHolder.getRenderTick(); + float speed = te.getSpeed() * 5; + if (speed > 0) + speed = MathHelper.clamp(speed, 80, 64 * 20); + if (speed < 0) + speed = MathHelper.clamp(speed, -64 * 20, -80); + float angle = (time * speed * 3 / 10f) % 360; + angle = angle / 180f * (float) Math.PI; + + standardKineticRotationTransform(shaftHalf, te, lightBehind).renderInto(ms, vb); + kineticRotationTransform(fanInner, te, direction.getAxis(), angle, lightInFront).renderInto(ms, vb); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 9c4d6b6be..76453c14e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -1,15 +1,16 @@ package com.simibubi.create.content.contraptions.components.flywheel; +import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; + import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -21,8 +22,6 @@ import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.Rotation; import net.minecraft.util.math.MathHelper; -import static com.simibubi.create.content.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; - public class FlywheelRenderer extends KineticTileEntityRenderer { public FlywheelRenderer(TileEntityRendererDispatcher dispatcher) { @@ -74,6 +73,12 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { wheel.renderInto(ms, vb); } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), te.getBlockState() + .get(HORIZONTAL_FACING) + .getOpposite()); + } protected SuperByteBuffer transformConnector(SuperByteBuffer buffer, boolean upper, boolean rotating, float angle, boolean flip) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java index 624c58fa5..f9fa65b7b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillstoneRenderer.java @@ -1,10 +1,11 @@ package com.simibubi.create.content.contraptions.components.millstone; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class MillstoneRenderer extends KineticTileEntityRenderer { @@ -13,5 +14,9 @@ public class MillstoneRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return CreateClient.bufferCache.renderPartial(AllBlockPartials.MILLSTONE_COG, te.getBlockState()); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 859e0528b..04231f98d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -5,10 +5,9 @@ import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -23,11 +22,6 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { super(dispatcher); } - @Override - public boolean isGlobalRenderer(KineticTileEntity te) { - return true; - } - @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { @@ -37,6 +31,9 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); + SuperByteBuffer superBuffer = AllBlockPartials.SHAFTLESS_COGWHEEL.renderOn(blockState); + standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb); + int packedLightmapCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), blockState, pos); float renderedHeadOffset = mixer.getRenderedHeadOffset(partialTicks); float speed = mixer.getRenderedHeadRotationSpeed(partialTicks); @@ -54,4 +51,5 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { .light(packedLightmapCoords) .renderInto(ms, vb); } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index 127e1b754..215cf1b57 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -3,8 +3,8 @@ package com.simibubi.create.content.contraptions.components.motor; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class CreativeMotorRenderer extends KineticTileEntityRenderer { @@ -13,5 +13,9 @@ public class CreativeMotorRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState()); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java index 60f7d437f..58a7a6c83 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java @@ -19,11 +19,6 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer { super(dispatcher); } - @Override - public boolean isGlobalRenderer(KineticTileEntity tile) { - return true; - } - @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index b59db0d26..0f2f52189 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -1,18 +1,20 @@ package com.simibubi.create.content.contraptions.components.saw; +import static net.minecraft.state.properties.BlockStateProperties.FACING; + import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; + import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -28,8 +30,6 @@ import net.minecraft.util.Rotation; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import static net.minecraft.state.properties.BlockStateProperties.FACING; - public class SawRenderer extends SafeTileEntityRenderer { public SawRenderer(TileEntityRendererDispatcher dispatcher) { @@ -42,7 +42,7 @@ public class SawRenderer extends SafeTileEntityRenderer { renderBlade(te, ms, buffer, light); renderItems(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); - + renderShaft(te, ms, buffer, light, overlay); } protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light){ @@ -79,8 +79,9 @@ public class SawRenderer extends SafeTileEntityRenderer { ms.pop(); } - protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - //KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te)); + protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, + int overlay) { + KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te), ms, buffer.getBuffer(RenderType.getSolid()), light); } protected void renderItems(SawTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, @@ -124,6 +125,14 @@ public class SawRenderer extends SafeTileEntityRenderer { } } + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + BlockState state = te.getBlockState(); + if (state.get(FACING).getAxis().isHorizontal()) + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(state.rotate(Rotation.CLOCKWISE_180)); + return CreateClient.bufferCache.renderBlockIn(KineticTileEntityRenderer.KINETIC_TILE, + getRenderedBlockState(te)); + } + protected BlockState getRenderedBlockState(KineticTileEntity te) { return KineticTileEntityRenderer.shaft(KineticTileEntityRenderer.getRotationAxisOf(te)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index 90fbb0a77..b1c071ea3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -4,11 +4,9 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; -import net.minecraft.block.BlockState; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -44,4 +42,11 @@ public class BearingRenderer extends KineticTileEntityRenderer { superBuffer.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), te.getBlockState() + .get(BearingBlock.FACING) + .getOpposite()); + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java index 35f53c01d..b14b30539 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java @@ -4,11 +4,10 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -51,4 +50,9 @@ public class PumpRenderer extends KineticTileEntityRenderer { } } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouth(te.getBlockState()); + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 448d97cac..c33b9770e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -1,23 +1,29 @@ package com.simibubi.create.content.contraptions.relays.belt; import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSpriteShifts; +import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.ShadowRenderHelper; +import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.instancing.BeltData; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.Vector3f; import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -39,21 +45,108 @@ public class BeltRenderer extends SafeTileEntityRenderer { super(dispatcher); } + @Override + public boolean isGlobalRenderer(BeltTileEntity te) { + return BeltBlock.canTransportObjects(te.getBlockState()); + } + @Override protected void renderSafe(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, - int light, int overlay) { + int light, int overlay) { BlockState blockState = te.getBlockState(); if (!AllBlocks.BELT.has(blockState)) return; -// addInstanceData(new InstanceContext.World<>(te)); - renderItems(te, partialTicks, ms, buffer, light, overlay); - } + BeltSlope beltSlope = blockState.get(BeltBlock.SLOPE); + BeltPart part = blockState.get(BeltBlock.PART); + Direction facing = blockState.get(BeltBlock.HORIZONTAL_FACING); + AxisDirection axisDirection = facing.getAxisDirection(); - @Override - public boolean isGlobalRenderer(BeltTileEntity te) { - return te.isController(); + boolean downward = beltSlope == BeltSlope.DOWNWARD; + boolean upward = beltSlope == BeltSlope.UPWARD; + boolean diagonal = downward || upward; + boolean start = part == BeltPart.START; + boolean end = part == BeltPart.END; + boolean sideways = beltSlope == BeltSlope.SIDEWAYS; + boolean alongX = facing.getAxis() == Axis.X; + + MatrixStacker msr = MatrixStacker.of(ms); + IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); + float renderTick = AnimationTickHolder.getRenderTick(); + + ms.push(); + msr.centre(); + msr.rotateY(AngleHelper.horizontalAngle(facing) + (upward ? 180 : 0) + (sideways ? 270 : 0)); + msr.rotateZ(sideways ? 90 : 0); + msr.rotateX(!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0); + msr.unCentre(); + + if (downward || beltSlope == BeltSlope.VERTICAL && axisDirection == AxisDirection.POSITIVE) { + boolean b = start; + start = end; + end = b; + } + + for (boolean bottom : Iterate.trueAndFalse) { + + AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); + + SuperByteBuffer beltBuffer = beltPartial.renderOn(blockState) + .light(light); + + SpriteShiftEntry spriteShift = getSpriteShiftEntry(diagonal, bottom); + + // UV shift + float speed = te.getSpeed(); + if (speed != 0) { + float time = renderTick * axisDirection.getOffset(); + if (diagonal && (downward ^ alongX) || !sideways && !diagonal && alongX + || sideways && axisDirection == AxisDirection.NEGATIVE) + speed = -speed; + + float scrollMult = diagonal ? 3f / 8f : 0.5f; + + float spriteSize = spriteShift.getTarget().getMaxV() - spriteShift.getTarget().getMinV(); + + double scroll = speed * time / (36 * 16); + scroll = scroll - Math.floor(scroll); + scroll = scroll * spriteSize * scrollMult; + + beltBuffer.shiftUVScrolling(spriteShift, (float) scroll); + } + + beltBuffer.renderInto(ms, vb); + + // Diagonal belt do not have a separate bottom model + if (diagonal) + break; + } + ms.pop(); + + if (te.hasPulley()) { + // TODO 1.15 find a way to cache this model matrix computation + MatrixStack modelTransform = new MatrixStack(); + Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) + .rotateY(); + if (sideways) + dir = Direction.UP; + msr = MatrixStacker.of(modelTransform); + msr.centre(); + if (dir.getAxis() == Axis.X) + msr.rotateY(90); + if (dir.getAxis() == Axis.Y) + msr.rotateX(90); + msr.rotateX(90); + msr.unCentre(); + + SuperByteBuffer superBuffer = CreateClient.bufferCache + .renderDirectionalPartial(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); + KineticTileEntityRenderer.standardKineticRotationTransform(superBuffer, te, light) + .renderInto(ms, vb); + } + + renderItems(te, partialTicks, ms, buffer, light, overlay); } public static SpriteShiftEntry getSpriteShiftEntry(boolean diagonal, boolean bottom) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index 67897372e..c0f10c1e3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -5,16 +5,17 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.block.Block; 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.math.BlockPos; -import net.minecraft.world.LightType; public class SplitShaftRenderer extends KineticTileEntityRenderer { @@ -25,7 +26,32 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - super.renderSafe(te, partialTicks, ms, buffer, light, overlay); + Block block = te.getBlockState().getBlock(); + final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); + final BlockPos pos = te.getPos(); + float time = AnimationTickHolder.getRenderTick(); + + for (Direction direction : Iterate.directions) { + Axis axis = direction.getAxis(); + if (boxAxis != axis) + continue; + + float offset = getRotationOffsetForPosition(te, pos, axis); + float angle = (time * te.getSpeed() * 3f / 10) % 360; + float modifier = 1; + + if (te instanceof SplitShaftTileEntity) + modifier = ((SplitShaftTileEntity) te).getRotationSpeedModifier(direction); + + angle *= modifier; + angle += offset; + angle = angle / 180f * (float) Math.PI; + + SuperByteBuffer superByteBuffer = + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction); + kineticRotationTransform(superByteBuffer, te, axis, angle, light); + superByteBuffer.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); + } } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 509f15ef2..5279893fd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -1,23 +1,20 @@ package com.simibubi.create.content.contraptions.relays.gearbox; -import com.google.common.collect.Lists; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.Pair; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.LightType; - -import java.util.List; public class GearboxRenderer extends KineticTileEntityRenderer { @@ -28,7 +25,34 @@ public class GearboxRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - super.renderSafe(te, partialTicks, ms, buffer, light, overlay); + final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); + final BlockPos pos = te.getPos(); + float time = AnimationTickHolder.getRenderTick(); + + for (Direction direction : Iterate.directions) { + final Axis axis = direction.getAxis(); + if (boxAxis == axis) + continue; + + SuperByteBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction); + float offset = getRotationOffsetForPosition(te, pos, axis); + float angle = (time * te.getSpeed() * 3f / 10) % 360; + + if (te.getSpeed() != 0 && te.hasSource()) { + BlockPos source = te.source.subtract(te.getPos()); + Direction sourceFacing = Direction.getFacingFromVector(source.getX(), source.getY(), source.getZ()); + if (sourceFacing.getAxis() == direction.getAxis()) + angle *= sourceFacing == direction ? 1 : -1; + else if (sourceFacing.getAxisDirection() == direction.getAxisDirection()) + angle *= -1; + } + + angle += offset; + angle = angle / 180f * (float) Math.PI; + + kineticRotationTransform(shaft, te, axis, angle, light); + shaft.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); + } } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index e039892be..4c38e7b14 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -6,13 +6,12 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.InstancedModel; -import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; +import com.simibubi.create.foundation.render.SuperByteBuffer; + import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -30,11 +29,6 @@ public class ArmRenderer extends KineticTileEntityRenderer { super(dispatcher); } - @Override - public boolean isGlobalRenderer(KineticTileEntity te) { - return true; - } - @Override protected void renderSafe(KineticTileEntity te, float pt, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { @@ -123,4 +117,9 @@ public class ArmRenderer extends KineticTileEntityRenderer { ms.pop(); } + @Override + protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { + return AllBlockPartials.ARM_COG.renderOn(te.getBlockState()); + } + } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java index f95e3cfa6..8f4c954fc 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java @@ -25,8 +25,8 @@ public class CancelTileEntityRenderMixin { */ @Inject(at = @At("RETURN"), method = "getTileEntities", cancellable = true) private void noRenderInstancedTiles(CallbackInfoReturnable> cir) { - List tiles = cir.getReturnValue(); - - tiles.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderAsTE()); +// List tiles = cir.getReturnValue(); +// +// tiles.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderAsTE()); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java index dde2c5a9d..bdd6c9ae1 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.render; import java.nio.Buffer; import java.nio.ByteBuffer; +import java.util.function.Consumer; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; @@ -29,9 +30,7 @@ public class SuperByteBuffer extends TemplateBuffer { private MatrixStack transforms; // Vertex Texture Coords - private boolean shouldShiftUV; - private SpriteShiftEntry spriteShift; - private float uTarget, vTarget; + private SpriteShiftFunc spriteShiftFunc; // Vertex Lighting private boolean shouldLight; @@ -105,12 +104,8 @@ public class SuperByteBuffer extends TemplateBuffer { float u = getU(buffer, i); float v = getV(buffer, i); - if (shouldShiftUV) { - float targetU = spriteShift.getTarget() - .getInterpolatedU((getUnInterpolatedU(spriteShift.getOriginal(), u) / sheetSize) + uTarget * 16); - float targetV = spriteShift.getTarget() - .getInterpolatedV((getUnInterpolatedV(spriteShift.getOriginal(), v) / sheetSize) + vTarget * 16); - builder.texture(targetU, targetV); + if (spriteShiftFunc != null) { + spriteShiftFunc.shift(builder, u, v); } else builder.texture(u, v); @@ -131,7 +126,7 @@ public class SuperByteBuffer extends TemplateBuffer { } transforms = new MatrixStack(); - shouldShiftUV = false; + spriteShiftFunc = null; shouldColor = false; shouldLight = false; } @@ -159,20 +154,29 @@ public class SuperByteBuffer extends TemplateBuffer { } public SuperByteBuffer shiftUV(SpriteShiftEntry entry) { - shouldShiftUV = true; - spriteShift = entry; - uTarget = 0; - vTarget = 0; - sheetSize = 1; + this.spriteShiftFunc = (builder, u, v) -> { + float targetU = entry.getTarget().getInterpolatedU((getUnInterpolatedU(entry.getOriginal(), u))); + float targetV = entry.getTarget().getInterpolatedV((getUnInterpolatedV(entry.getOriginal(), v))); + builder.texture(targetU, targetV); + }; + return this; + } + + public SuperByteBuffer shiftUVScrolling(SpriteShiftEntry entry, float scrollV) { + this.spriteShiftFunc = (builder, u, v) -> { + float targetU = u - entry.getOriginal().getMinU() + entry.getTarget().getMinU(); + float targetV = v - entry.getOriginal().getMinV() + entry.getTarget().getMinV() + scrollV; + builder.texture(targetU, targetV); + }; return this; } public SuperByteBuffer shiftUVtoSheet(SpriteShiftEntry entry, float uTarget, float vTarget, int sheetSize) { - shouldShiftUV = true; - spriteShift = entry; - this.uTarget = uTarget; - this.vTarget = vTarget; - this.sheetSize = sheetSize; + this.spriteShiftFunc = (builder, u, v) -> { + float targetU = entry.getTarget().getInterpolatedU((getUnInterpolatedU(entry.getOriginal(), u) / sheetSize) + uTarget * 16); + float targetV = entry.getTarget().getInterpolatedV((getUnInterpolatedV(entry.getOriginal(), v) / sheetSize) + vTarget * 16); + builder.texture(targetU, targetV); + }; return this; } @@ -220,4 +224,9 @@ public class SuperByteBuffer extends TemplateBuffer { return ((Buffer) template).limit() == 0; } + @FunctionalInterface + public interface SpriteShiftFunc { + void shift(IVertexBuilder builder, float u, float v); + } + } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java index 52d15de52..c7d0aad5a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderer.java @@ -42,14 +42,15 @@ public abstract class InstancedTileRenderer

{ if (instance != null) { return (TileEntityInstance) instance; } else if (create) { - TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); - - if (renderer != null) { - FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(tile); - instances.put(tile, renderer); - } - - return renderer; + return null; +// TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); +// +// if (renderer != null) { +// FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(tile); +// instances.put(tile, renderer); +// } +// +// return renderer; } else { return null; } diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index 423c41cb4..25bb34fd1 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -11,7 +11,7 @@ layout (location = 5) in vec3 networkTint; layout (location = 6) in float speed; layout (location = 7) in float offset; layout (location = 8) in vec3 eulerAngles; -layout (location = 9) in vec2 uv; +layout (location = 9) in vec2 sourceTexture; layout (location = 10) in vec4 scrollTexture; layout (location = 11) in float scrollMult; @@ -81,7 +81,7 @@ void main() { float scroll = fract(speed * uTime / (36 * 16) + offset) * scrollSize * scrollMult; Diffuse = diffuse(norm); - TexCoords = aTexCoords - uv + scrollTexture.xy + vec2(0, scroll); + TexCoords = aTexCoords - sourceTexture + scrollTexture.xy + vec2(0, scroll); Light = light; gl_Position = uViewProjection * worldPos;