diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index f740f4dbe..89382d10e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -8,7 +8,6 @@ import java.util.List; import javax.annotation.Nullable; import com.simibubi.create.Create; -import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticNetwork; import com.simibubi.create.content.contraptions.RotationPropagator; import com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel; @@ -22,6 +21,7 @@ import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.render.instancing.IInstanceRendered; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.client.resources.I18n; @@ -38,7 +38,7 @@ import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; public abstract class KineticTileEntity extends SmartTileEntity - implements ITickableTileEntity, IHaveGoggleInformation, IHaveHoveringInformation { + implements ITickableTileEntity, IHaveGoggleInformation, IHaveHoveringInformation, IInstanceRendered { public @Nullable Long network; public @Nullable BlockPos source; 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 b0c50866c..bfb3ce64e 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 @@ -8,6 +8,7 @@ import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; 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.utility.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBufferCache.Compartment; @@ -22,11 +23,12 @@ 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; @EventBusSubscriber(value = Dist.CLIENT) -public class KineticTileEntityRenderer extends SafeTileEntityRenderer { +public class KineticTileEntityRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public static final Compartment KINETIC_TILE = new Compartment<>(); public static boolean rainbowMode = false; @@ -43,27 +45,35 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer { final BlockPos pos = te.getPos(); Axis axis = ((IRotate) te.getBlockState() .getBlock()).getRotationAxis(te.getBlockState()); - data.setPackedLight(light) - .setRotationalSpeed(te.getSpeed()) - .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) - .setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector()) - .setPosition(pos); + data + .setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos())) + .setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos())) + .setRotationalSpeed(te.getSpeed()) + .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) + .setRotationAxis(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis).getUnitVector()) + .setPosition(pos); }); } 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 235d44ee4..636a7f89d 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 @@ -14,6 +14,7 @@ import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java index 66d85ce92..d978ac439 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockRenderer.java @@ -7,9 +7,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity.Animation; import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index 4fe26b14b..48ff5a7d4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -19,6 +19,7 @@ import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -37,7 +38,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -public class DeployerRenderer extends SafeTileEntityRenderer { +public class DeployerRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public DeployerRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -49,10 +50,17 @@ public class DeployerRenderer extends SafeTileEntityRenderer renderItem(te, partialTicks, ms, buffer, light, overlay); FilteringRenderer.renderOnTileEntity(te, partialTicks, ms, buffer, light, overlay); renderComponents(te, partialTicks, ms, buffer, light, overlay); + + addInstanceData(te); + } + + @Override + public void addInstanceData(DeployerTileEntity te) { + KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te)); } 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,7 +110,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), light); + KineticTileEntityRenderer.renderRotatingKineticBlock(te, getRenderedBlockState(te)); BlockState blockState = te.getBlockState(); BlockPos pos = te.getPos(); 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 004f0e560..e26d8b77d 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 @@ -15,6 +15,7 @@ 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; public class EncasedFanRenderer extends KineticTileEntityRenderer { @@ -25,18 +26,24 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + addInstanceData(te); + } + + @Override + public void addInstanceData(KineticTileEntity te) { Direction direction = te.getBlockState() - .get(FACING); + .get(FACING); + + BlockPos inFront = te.getPos().offset(direction); + int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, inFront); + int skyLight = te.getWorld().getLightLevel(LightType.SKY, inFront); - int lightBehind = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction.getOpposite())); - int lightInFront = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction)); - RotatingBuffer shaftHalf = - AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite()); + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite()); RotatingBuffer fanInner = - AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite()); + AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(te.getBlockState(), direction.getOpposite()); - renderRotatingBuffer(te, shaftHalf, lightBehind); + renderRotatingBuffer(te, shaftHalf); fanInner.setupInstance(data -> { final BlockPos pos = te.getPos(); Direction.Axis axis = ((IRotate) te.getBlockState() @@ -48,12 +55,12 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { if (speed < 0) speed = MathHelper.clamp(speed, -64 * 20, -80); - data.setPackedLight(lightInFront) + data.setBlockLight(blockLight) + .setSkyLight(skyLight) .setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) .setPosition(pos); }); } - } 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 0fefa1716..563fe72b2 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 @@ -9,9 +9,11 @@ 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.utility.AngleHelper; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; 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 ee20c59b9..67dd39cb0 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 @@ -5,7 +5,9 @@ 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.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class MillstoneRenderer extends KineticTileEntityRenderer { 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 1789da7a5..902e25c47 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 @@ -4,7 +4,9 @@ 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.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; public class CreativeMotorRenderer extends KineticTileEntityRenderer { 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 52c99aec9..05d1ba113 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 @@ -12,6 +12,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRe import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.*; +import com.simibubi.create.foundation.utility.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; import net.minecraft.block.BlockState; @@ -29,7 +30,7 @@ import net.minecraft.util.Rotation; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -public class SawRenderer extends SafeTileEntityRenderer { +public class SawRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public SawRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -41,7 +42,13 @@ 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); + + addInstanceData(te); + } + + @Override + public void addInstanceData(SawTileEntity te) { + KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te)); } protected void renderBlade(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light){ @@ -79,7 +86,7 @@ public class SawRenderer extends SafeTileEntityRenderer { } protected void renderShaft(SawTileEntity te, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te), light); + KineticTileEntityRenderer.renderRotatingBuffer(te, getRotatedModel(te)); } protected void renderItems(SawTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java index 8ca710438..d9d22dc20 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntityRenderer.java @@ -53,8 +53,8 @@ public abstract class AbstractContraptionEntityRenderer { +public class SpeedControllerRenderer extends SmartTileEntityRenderer implements IInstancedTileEntityRenderer { public SpeedControllerRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -20,7 +21,12 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer { +public class BeltRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { public BeltRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -45,6 +47,17 @@ public class BeltRenderer extends SafeTileEntityRenderer { protected void renderSafe(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + BlockState blockState = te.getBlockState(); + if (!AllBlocks.BELT.has(blockState)) + return; + + addInstanceData(te); + + renderItems(te, partialTicks, ms, buffer, light, overlay); + } + + @Override + public void addInstanceData(BeltTileEntity te) { BlockState blockState = te.getBlockState(); if (!AllBlocks.BELT.has(blockState)) return; @@ -73,13 +86,13 @@ public class BeltRenderer extends SafeTileEntityRenderer { for (boolean bottom : Iterate.trueAndFalse) { AllBlockPartials beltPartial = diagonal - ? start ? AllBlockPartials.BELT_DIAGONAL_START + ? start ? AllBlockPartials.BELT_DIAGONAL_START : end ? AllBlockPartials.BELT_DIAGONAL_END : AllBlockPartials.BELT_DIAGONAL_MIDDLE - : bottom + : bottom ? start ? AllBlockPartials.BELT_START_BOTTOM - : end ? AllBlockPartials.BELT_END_BOTTOM : AllBlockPartials.BELT_MIDDLE_BOTTOM + : end ? AllBlockPartials.BELT_END_BOTTOM : AllBlockPartials.BELT_MIDDLE_BOTTOM : start ? AllBlockPartials.BELT_START - : end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE; + : end ? AllBlockPartials.BELT_END : AllBlockPartials.BELT_MIDDLE; BeltBuffer beltBuffer = beltPartial.renderOnBelt(blockState); SpriteShiftEntry spriteShift = @@ -88,8 +101,8 @@ public class BeltRenderer extends SafeTileEntityRenderer { beltBuffer.setupInstance(data -> { float speed = te.getSpeed(); if (((axisDirection == AxisDirection.NEGATIVE) ^ upward) ^ - ((alongX && !diagonal) || (alongZ && diagonal)) ^ - vertical) + ((alongX && !diagonal) || (alongZ && diagonal)) ^ + vertical) speed = -speed; float rotX = !diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0; @@ -97,8 +110,9 @@ public class BeltRenderer extends SafeTileEntityRenderer { float rotZ = sideways ? 90 : (vertical ? 180 : 0); data.setPosition(te.getPos()) + .setBlockLight(te.getWorld().getLightLevel(LightType.BLOCK, te.getPos())) + .setSkyLight(te.getWorld().getLightLevel(LightType.SKY, te.getPos())) .setRotation(rotX, rotY, rotZ) - .setPackedLight(light) .setRotationalSpeed(speed) .setScrollTexture(spriteShift) .setScrollMult(diagonal ? 3f / 8f : 0.5f); @@ -113,7 +127,7 @@ public class BeltRenderer extends SafeTileEntityRenderer { // TODO 1.15 find a way to cache this model matrix computation MatrixStack modelTransform = new MatrixStack(); Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) - .rotateY(); + .rotateY(); if (sideways) dir = Direction.UP; MatrixStacker msr = MatrixStacker.of(modelTransform); @@ -126,15 +140,14 @@ public class BeltRenderer extends SafeTileEntityRenderer { msr.unCentre(); RotatingBuffer rotatingBuffer = CreateClient.kineticRenderer - .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); - KineticTileEntityRenderer.renderRotatingBuffer(te, rotatingBuffer, light); + .renderDirectionalPartialInstanced(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); + KineticTileEntityRenderer.renderRotatingBuffer(te, rotatingBuffer); } - renderItems(te, partialTicks, ms, buffer, light, overlay); } protected void renderItems(BeltTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, - int light, int overlay) { + int light, int overlay) { if (!te.isController()) return; if (te.beltLength == 0) 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 e126f3b08..2b9660e6a 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 @@ -14,6 +14,7 @@ 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 { @@ -24,10 +25,19 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { + + addInstanceData(te); + } + + @Override + public void addInstanceData(KineticTileEntity te) { Block block = te.getBlockState().getBlock(); final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState()); final BlockPos pos = te.getPos(); + int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()); + int skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos()); + for (Direction direction : Iterate.directions) { Axis axis = direction.getAxis(); if (boxAxis != axis) @@ -46,7 +56,8 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { speed *= modifier; - data.setPackedLight(light) + data.setBlockLight(blockLight) + .setSkyLight(skyLight) .setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) @@ -54,5 +65,4 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { }); } } - } 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 70f8428c5..94705946b 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 @@ -13,6 +13,7 @@ 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; public class GearboxRenderer extends KineticTileEntityRenderer { @@ -26,6 +27,9 @@ public class GearboxRenderer extends KineticTileEntityRenderer { final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); final BlockPos pos = te.getPos(); + int blockLight = te.getWorld().getLightLevel(LightType.BLOCK, te.getPos()); + int skyLight = te.getWorld().getLightLevel(LightType.SKY, te.getPos()); + for (Direction direction : Iterate.directions) { final Axis axis = direction.getAxis(); if (boxAxis == axis) @@ -45,7 +49,8 @@ public class GearboxRenderer extends KineticTileEntityRenderer { speed *= -1; } - data.setPackedLight(light) + data.setBlockLight(blockLight) + .setSkyLight(skyLight) .setRotationalSpeed(speed) .setRotationOffset(getRotationOffsetForPosition(te, pos, axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) 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 5f22cc9fa..a41f7a4cc 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 @@ -8,8 +8,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; import com.simibubi.create.foundation.utility.*; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; import com.simibubi.create.foundation.utility.render.SuperByteBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java b/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java index 01f01de38..8e626ee6e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java +++ b/src/main/java/com/simibubi/create/foundation/utility/AnimationTickHolder.java @@ -11,7 +11,8 @@ public class AnimationTickHolder { } public static float getRenderTick() { - return ticks + Minecraft.getInstance().getRenderPartialTicks(); + Minecraft mc = Minecraft.getInstance(); + return ticks + (mc.isGamePaused() ? mc.renderPartialTicksPaused : mc.getRenderPartialTicks()); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java index c246c854a..99bc7dabe 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastContraptionRenderer.java @@ -24,7 +24,7 @@ import java.util.concurrent.ExecutionException; public class FastContraptionRenderer extends ContraptionRenderer { - private static final Cache renderers = CacheBuilder.newBuilder().build(); + private static final Cache renderers = CacheBuilder.newBuilder().build(); private ArrayList renderLayers = new ArrayList<>(); @@ -105,7 +105,7 @@ public class FastContraptionRenderer extends ContraptionRenderer { private static FastContraptionRenderer getRenderer(World world, Contraption c) { try { - return renderers.get(c, () -> new FastContraptionRenderer(world, c)); + return renderers.get(c.entity.getEntityId(), () -> new FastContraptionRenderer(world, c)); } catch (ExecutionException e) { e.printStackTrace(); return null; @@ -120,13 +120,20 @@ public class FastContraptionRenderer extends ContraptionRenderer { ShaderHelper.useShader(Shader.CONTRAPTION_STRUCTURE, ShaderHelper.getViewProjectionCallback(event)); int shader = ShaderHelper.getShaderHandle(Shader.CONTRAPTION_STRUCTURE); + ArrayList toRemove = new ArrayList<>(); + for (FastContraptionRenderer renderer : renderers.asMap().values()) { - renderer.render(shader); + if (renderer.c.entity.isAlive()) + renderer.render(shader); + else + toRemove.add(renderer.c.entity.getEntityId()); } ShaderHelper.releaseShader(); CreateClient.kineticRenderer.teardown(); + + renderers.invalidateAll(toRemove); } public static void invalidateAll() { diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java index 9b70af249..804bd174c 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/FastKineticRenderer.java @@ -6,10 +6,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.Create; -import com.simibubi.create.foundation.utility.render.instancing.BeltBuffer; -import com.simibubi.create.foundation.utility.render.instancing.InstanceBuffer; -import com.simibubi.create.foundation.utility.render.instancing.RotatingBuffer; +import com.simibubi.create.foundation.utility.render.instancing.*; import com.simibubi.create.foundation.utility.render.shader.Shader; import com.simibubi.create.foundation.utility.render.shader.ShaderCallback; import com.simibubi.create.foundation.utility.render.shader.ShaderHelper; @@ -18,11 +15,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.texture.Texture; +import net.minecraft.client.renderer.tileentity.TileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.inventory.container.PlayerContainer; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; -import net.minecraftforge.api.distmarker.Dist; +import net.minecraft.world.World; import net.minecraftforge.client.event.RenderWorldLastEvent; -import net.minecraftforge.fml.common.Mod; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL13; @@ -36,13 +35,14 @@ import java.util.function.Supplier; import static com.simibubi.create.foundation.utility.render.SuperByteBufferCache.PARTIAL; -@Mod.EventBusSubscriber(modid = Create.ID, value = Dist.CLIENT) public class FastKineticRenderer { Map, Cache> rotating; Map, Cache> belts; Queue runs; + boolean rebuild; + public FastKineticRenderer() { rotating = new HashMap<>(); belts = new HashMap<>(); @@ -52,7 +52,29 @@ public class FastKineticRenderer { registerCompartment(SuperByteBufferCache.DIRECTIONAL_PARTIAL); } + public void buildTileEntityBuffers(World world) { + + List tileEntities = world.loadedTileEntityList; + + if (!tileEntities.isEmpty()) { + for (TileEntity te : tileEntities) { + if (te instanceof IInstanceRendered) { + TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(te); + + if (renderer instanceof IInstancedTileEntityRenderer) { + addInstancedData(te, (IInstancedTileEntityRenderer) renderer); + } + } + } + } + } + + private void addInstancedData(T te, IInstancedTileEntityRenderer renderer) { + renderer.addInstanceData(te); + } + public void tick() { + // TODO: (later) detect changes in lighting with a mixin to ClientChunkProvider.markLightChanged() for (Cache cache : rotating.values()) { for (RotatingBuffer renderer : cache.asMap().values()) { renderer.clearInstanceData(); @@ -64,6 +86,8 @@ public class FastKineticRenderer { renderer.clearInstanceData(); } } + +// rebuild = true; } public void enqueue(Runnable run) { @@ -72,6 +96,11 @@ public class FastKineticRenderer { public void renderInstances(RenderWorldLastEvent event) { GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; +// +// if (rebuild) { +// buildTileEntityBuffers(Minecraft.getInstance().world); +// rebuild = false; +// } setup(gameRenderer); diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java b/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java deleted file mode 100644 index 12212d29d..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/render/LightUtil.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.simibubi.create.foundation.utility.render; - -import net.minecraft.client.renderer.LightTexture; - -public class LightUtil { - public static float getProperBlockLight(int packedLight) { - return LightTexture.getBlockLightCoordinates(packedLight) / (float) 0xF; - } - - public static float getProperSkyLight(int packedLight) { - return LightTexture.getSkyLightCoordinates(packedLight) / (float) 0xF; - } -} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java new file mode 100644 index 000000000..082d018e1 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BasicData.java @@ -0,0 +1,46 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.util.math.BlockPos; + +import java.nio.ByteBuffer; + +public class BasicData> extends InstanceData { + + private float x; + private float y; + private float z; + private float blockLight; + private float skyLight; + + public D setBlockLight(int blockLight) { + this.blockLight = blockLight / 15f; + return (D) this; + } + + public D setSkyLight(int skyLight) { + this.skyLight = skyLight / 15f; + return (D) this; + } + + public D setPosition(Vector3f pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return (D) this; + } + + public D setPosition(BlockPos pos) { + this.x = pos.getX(); + this.y = pos.getY(); + this.z = pos.getZ(); + return (D) this; + } + + @Override + public void write(ByteBuffer buf) { + putVec3(buf, x, y, z); + + putVec2(buf, blockLight, skyLight); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java index b07c90d81..d8f7839d4 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltBuffer.java @@ -1,15 +1,8 @@ package com.simibubi.create.foundation.utility.render.instancing; -import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.utility.render.LightUtil; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.math.BlockPos; -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; -import java.nio.ByteBuffer; - -public class BeltBuffer extends InstanceBuffer { +public class BeltBuffer extends InstanceBuffer { public BeltBuffer(BufferBuilder buf) { super(buf); } @@ -24,84 +17,4 @@ public class BeltBuffer extends InstanceBuffer { return BeltData.FORMAT; } - public static class BeltData extends InstanceData { - public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC3, VEC2, FLOAT, VEC2, VEC4, FLOAT); - - private float x; - private float y; - private float z; - private float rotX; - private float rotY; - private float rotZ; - private int packedLight; - private float rotationalSpeed; - private float sourceU; - private float sourceV; - private float minU; - private float minV; - private float maxU; - private float maxV; - private float scrollMult; - - public BeltData setPosition(BlockPos pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public BeltData setRotation(float rotX, float rotY, float rotZ) { - this.rotX = rotX; - this.rotY = rotY; - this.rotZ = rotZ; - return this; - } - - public BeltData setPackedLight(int packedLight) { - this.packedLight = packedLight; - return this; - } - - public BeltData setRotationalSpeed(float rotationalSpeed) { - this.rotationalSpeed = rotationalSpeed; - return this; - } - - public BeltData setScrollTexture(SpriteShiftEntry spriteShift) { - TextureAtlasSprite source = spriteShift.getOriginal(); - TextureAtlasSprite target = spriteShift.getTarget(); - - this.sourceU = source.getMinU(); - this.sourceV = source.getMinV(); - this.minU = target.getMinU(); - this.minV = target.getMinV(); - this.maxU = target.getMaxU(); - this.maxV = target.getMaxV(); - - return this; - } - - public BeltData setScrollMult(float scrollMult) { - this.scrollMult = scrollMult; - return this; - } - - @Override - public void write(ByteBuffer buf) { - float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight); - float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight); - - putVec3(buf, x, y, z); - - putVec3(buf, rotX, rotY, rotZ); - - putVec2(buf, blockLightCoordinates, skyLightCoordinates); - putFloat(buf, rotationalSpeed); - - putVec2(buf, sourceU, sourceV); - putVec4(buf, minU, minV, maxU, maxV); - - putFloat(buf, scrollMult); - } - } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java new file mode 100644 index 000000000..079e56174 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/BeltData.java @@ -0,0 +1,70 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.math.BlockPos; + +import java.nio.ByteBuffer; + +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; + +public class BeltData extends BasicData { + public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, VEC3, FLOAT, VEC2, VEC4, FLOAT); + + private float rotX; + private float rotY; + private float rotZ; + private float rotationalSpeed; + private float sourceU; + private float sourceV; + private float minU; + private float minV; + private float maxU; + private float maxV; + private float scrollMult; + + public BeltData setRotation(float rotX, float rotY, float rotZ) { + this.rotX = rotX; + this.rotY = rotY; + this.rotZ = rotZ; + return this; + } + + public BeltData setRotationalSpeed(float rotationalSpeed) { + this.rotationalSpeed = rotationalSpeed; + return this; + } + + public BeltData setScrollTexture(SpriteShiftEntry spriteShift) { + TextureAtlasSprite source = spriteShift.getOriginal(); + TextureAtlasSprite target = spriteShift.getTarget(); + + this.sourceU = source.getMinU(); + this.sourceV = source.getMinV(); + this.minU = target.getMinU(); + this.minV = target.getMinV(); + this.maxU = target.getMaxU(); + this.maxV = target.getMaxV(); + + return this; + } + + public BeltData setScrollMult(float scrollMult) { + this.scrollMult = scrollMult; + return this; + } + + @Override + public void write(ByteBuffer buf) { + super.write(buf); + + putVec3(buf, rotX, rotY, rotZ); + + putFloat(buf, rotationalSpeed); + + putVec2(buf, sourceU, sourceV); + putVec4(buf, minU, minV, maxU, maxV); + + putFloat(buf, scrollMult); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java new file mode 100644 index 000000000..3db9de2ae --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstanceRendered.java @@ -0,0 +1,4 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +public interface IInstanceRendered { +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java new file mode 100644 index 000000000..7b0393689 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/IInstancedTileEntityRenderer.java @@ -0,0 +1,13 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.tileentity.TileEntity; + +import java.util.function.Supplier; + +public interface IInstancedTileEntityRenderer { + + void addInstanceData(T te); +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java deleted file mode 100644 index 7c4ed9e8e..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/InstancedTileEntityRenderer.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.simibubi.create.foundation.utility.render.instancing; - -import net.minecraft.tileentity.TileEntity; - -import java.util.function.Supplier; - -public abstract class InstancedTileEntityRenderer { - - public abstract D getInstanceData(T te); - - public abstract InstanceBuffer getModel(T te); -} diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java index 7af85110e..cbed7078b 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingBuffer.java @@ -1,24 +1,8 @@ package com.simibubi.create.foundation.utility.render.instancing; -import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.utility.render.LightUtil; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.Vector3f; -import net.minecraft.client.renderer.vertex.VertexFormatElement; -import net.minecraft.util.math.BlockPos; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL20; -import org.lwjgl.opengl.GL40; -import java.nio.Buffer; -import java.nio.ByteBuffer; - -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; -import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.FLOAT; - -public class RotatingBuffer extends InstanceBuffer { +public class RotatingBuffer extends InstanceBuffer { public RotatingBuffer(BufferBuilder buf) { super(buf); } @@ -33,74 +17,4 @@ public class RotatingBuffer extends InstanceBuffer return RotatingData.FORMAT; } - public static class RotatingData extends InstanceData { - public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, FLOAT, FLOAT, VEC3); - - private float x; - private float y; - private float z; - private int packedLight; - private float rotationalSpeed; - private float rotationOffset; - private float rotationAxisX; - private float rotationAxisY; - private float rotationAxisZ; - - public RotatingData setPackedLight(int packedLight) { - this.packedLight = packedLight; - return this; - } - - public RotatingData setRotationalSpeed(float rotationalSpeed) { - this.rotationalSpeed = rotationalSpeed; - return this; - } - - public RotatingData setRotationOffset(float rotationOffset) { - this.rotationOffset = rotationOffset; - return this; - } - - public RotatingData setPosition(Vector3f pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public RotatingData setPosition(BlockPos pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - return this; - } - - public RotatingData setRotationAxis(Vector3f axis) { - this.rotationAxisX = axis.getX(); - this.rotationAxisY = axis.getY(); - this.rotationAxisZ = axis.getZ(); - return this; - } - - public RotatingData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { - this.rotationAxisX = rotationAxisX; - this.rotationAxisY = rotationAxisY; - this.rotationAxisZ = rotationAxisZ; - return this; - } - - @Override - public void write(ByteBuffer buf) { - float blockLightCoordinates = LightUtil.getProperBlockLight(packedLight); - float skyLightCoordinates = LightUtil.getProperSkyLight(packedLight); - - putVec3(buf, x, y, z); - - putVec2(buf, blockLightCoordinates, skyLightCoordinates); - putFloat(buf, rotationalSpeed); - putFloat(buf, rotationOffset); - - putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ); - } - } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java new file mode 100644 index 000000000..0d556af4b --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/render/instancing/RotatingData.java @@ -0,0 +1,51 @@ +package com.simibubi.create.foundation.utility.render.instancing; + +import net.minecraft.client.renderer.Vector3f; +import net.minecraft.util.math.BlockPos; + +import java.nio.ByteBuffer; + +import static com.simibubi.create.foundation.utility.render.instancing.VertexAttribute.*; + +public class RotatingData extends BasicData { + public static VertexFormat FORMAT = new VertexFormat(VEC3, VEC2, FLOAT, FLOAT, VEC3); + + private float rotationalSpeed; + private float rotationOffset; + private float rotationAxisX; + private float rotationAxisY; + private float rotationAxisZ; + + public RotatingData setRotationalSpeed(float rotationalSpeed) { + this.rotationalSpeed = rotationalSpeed; + return this; + } + + public RotatingData setRotationOffset(float rotationOffset) { + this.rotationOffset = rotationOffset; + return this; + } + + public RotatingData setRotationAxis(Vector3f axis) { + this.rotationAxisX = axis.getX(); + this.rotationAxisY = axis.getY(); + this.rotationAxisZ = axis.getZ(); + return this; + } + + public RotatingData setRotationAxis(float rotationAxisX, float rotationAxisY, float rotationAxisZ) { + this.rotationAxisX = rotationAxisX; + this.rotationAxisY = rotationAxisY; + this.rotationAxisZ = rotationAxisZ; + return this; + } + + @Override + public void write(ByteBuffer buf) { + super.write(buf); + putFloat(buf, rotationalSpeed); + putFloat(buf, rotationOffset); + + putVec3(buf, rotationAxisX, rotationAxisY, rotationAxisZ); + } +} diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index afe714db0..fe4188c5e 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -6,8 +6,8 @@ layout (location = 1) in vec3 aNormal; layout (location = 2) in vec2 aTexCoords; layout (location = 3) in vec3 instancePos; -layout (location = 4) in vec3 rotationDegrees; -layout (location = 5) in vec2 light; +layout (location = 4) in vec2 light; +layout (location = 5) in vec3 rotationDegrees; layout (location = 6) in float speed; layout (location = 7) in vec2 sourceUV; layout (location = 8) in vec4 scrollTexture; diff --git a/src/main/resources/assets/create/shader/contraption_static.vert b/src/main/resources/assets/create/shader/contraption_static.vert index 3f758039b..673d3bdde 100644 --- a/src/main/resources/assets/create/shader/contraption_static.vert +++ b/src/main/resources/assets/create/shader/contraption_static.vert @@ -38,14 +38,16 @@ mat4 contraptionRotation() { } void main() { - vec4 rotatedPos = contraptionRotation() * vec4(aPos - vec3(0.5), 1); + mat4 rotation = contraptionRotation(); + + vec4 rotatedPos = rotation * vec4(aPos - vec3(0.5), 1); vec4 worldPos = rotatedPos + vec4(cPos + vec3(0.5), 0); vec3 boxCoord = (worldPos.xyz - cPos - cSize * 0.5) / cSize; - //Light = texture(lightVolume, boxCoord).rg; - Normal = aNormal; + Light = vec2(1.); + Normal = normalize((rotation * vec4(aNormal, 0.)).xyz); TexCoords = aTexCoords; gl_Position = projection * view * worldPos; }