diff --git a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java index ee8517b93..4dd93b679 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java @@ -12,6 +12,8 @@ import net.minecraft.client.renderer.Vector4f; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.Direction; +import net.minecraft.util.Direction.Axis; +import net.minecraft.util.Direction.AxisDirection; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; public class SuperByteBuffer { @@ -99,6 +101,7 @@ public class SuperByteBuffer { if (original.limit() == 0) return; if (!(buffer instanceof BufferBuilder)) { + // TODO add "slow" path that writes all the data instead of using bulk put throw new IllegalArgumentException("Unsupported buffer type!"); } ((BufferBuilder)buffer).putBulkData(build(input)); @@ -113,15 +116,25 @@ public class SuperByteBuffer { return this; } - public SuperByteBuffer rotate(Direction axis, float angle) { - if (angle == 0) - return this; - transforms.multiply(axis.getUnitVector().getDegreesQuaternion(angle)); - return this; + @Deprecated + public SuperByteBuffer rotate(Axis axis, float radians) { + return rotate(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis), radians); } - public SuperByteBuffer rotateCentered(Direction axis, float angle) { - return translate(-.5f, -.5f, -.5f).rotate(axis, angle).translate(.5f, .5f, .5f); + public SuperByteBuffer rotate(Direction axis, float radians) { + if (radians == 0) + return this; + transforms.multiply(axis.getUnitVector().getRadialQuaternion(radians)); + return this; + } + + @Deprecated + public SuperByteBuffer rotateCentered(Axis axis, float radians) { + return rotateCentered(Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis), radians); + } + + public SuperByteBuffer rotateCentered(Direction axis, float radians) { + return translate(-.5f, -.5f, -.5f).rotate(axis, radians).translate(.5f, .5f, .5f); } public SuperByteBuffer shiftUV(TextureAtlasSprite from, TextureAtlasSprite to) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntityRenderer.java index 6dd08a981..48cd00041 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntityRenderer.java @@ -65,7 +65,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer .25f ? magnet : halfMagnet, x, y, z, offset, pos, buffer); + renderAt(te.getWorld(), offset > .25f ? magnet : halfMagnet, offset, pos, ms, vb); float f = offset % 1; if (offset > .75f && (f < .25f || f > .75f)) - renderAt(halfRope, x, y, z, f > .75f ? f - 1 : f, pos, buffer); + renderAt(te.getWorld(), halfRope, f > .75f ? f - 1 : f, pos, ms, vb); if (!pulley.running) return; for (int i = 0; i < offset - 1.25f; i++) - renderAt(rope, x, y, z, offset - i - 1, pos, buffer); + renderAt(te.getWorld(), rope, offset - i - 1, pos, ms, vb); } - public void renderAt(SuperByteBuffer partial, double x, double y, double z, float offset, BlockPos pulleyPos, - BufferBuilder buffer) { + public void renderAt(IWorld world, SuperByteBuffer partial, float offset, BlockPos pulleyPos, + MatrixStack ms, IVertexBuilder buffer) { BlockPos actualPos = pulleyPos.down((int) offset); - int light = getWorld().getBlockState(actualPos).getPackedLightmapCoords(getWorld(), actualPos); - partial.translate(x, y - offset, z).light(light).renderInto(buffer); + int light = world.getBlockState(actualPos).getPackedLightmapCoords(world, actualPos); + partial.translate(0, -offset, 0).light(light).renderInto(ms, buffer); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/crank/HandCrankTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/crank/HandCrankTileEntityRenderer.java index e5434d921..ad4238b39 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/crank/HandCrankTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/crank/HandCrankTileEntityRenderer.java @@ -2,29 +2,36 @@ package com.simibubi.create.modules.contraptions.components.crank; import static net.minecraft.state.properties.BlockStateProperties.FACING; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.utility.SuperByteBuffer; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; import net.minecraft.block.BlockState; -import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; public class HandCrankTileEntityRenderer extends KineticTileEntityRenderer { + public HandCrankTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { + super(dispatcher); + } + @Override - public void renderFast(KineticTileEntity te, double x, double y, double z, float partialTicks, - int destroyStage, BufferBuilder buffer) { - super.renderFast(te, x, y, z, partialTicks, destroyStage, buffer); + protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, + int light, int overlay) { + super.renderSafe(te, partialTicks, ms, buffer, light, overlay); BlockState state = te.getBlockState(); Direction facing = state.get(FACING); SuperByteBuffer handle = AllBlockPartials.HAND_CRANK_HANDLE.renderOnDirectional(state, facing.getOpposite()); HandCrankTileEntity crank = (HandCrankTileEntity) te; kineticRotationTransform(handle, te, facing.getAxis(), - (crank.independentAngle + partialTicks * crank.chasingVelocity) / 360, getWorld()); - handle.translate(x, y, z).renderInto(buffer); + (crank.independentAngle + partialTicks * crank.chasingVelocity) / 360); + handle.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/fan/EncasedFanTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/fan/EncasedFanTileEntityRenderer.java index 2bd095254..e8fd8ff66 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/fan/EncasedFanTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/fan/EncasedFanTileEntityRenderer.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.components.fan; import static net.minecraft.state.properties.BlockStateProperties.FACING; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.SuperByteBuffer; @@ -9,14 +10,20 @@ import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.math.MathHelper; public class EncasedFanTileEntityRenderer extends KineticTileEntityRenderer { + public EncasedFanTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { + super(dispatcher); + } + @Override - public void renderFast(KineticTileEntity te, double x, double y, double z, float partialTicks, - int destroyStage, BufferBuilder buffer) { + protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, + int light, int overlay) { Direction direction = te.getBlockState().get(FACING); SuperByteBuffer superBuffer = AllBlockPartials.SHAFT_HALF.renderOnDirectional(te.getBlockState(), direction.getOpposite()); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/flywheel/FlywheelRenderer.java index 52b060d9c..6a9bf76c2 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/flywheel/FlywheelRenderer.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.components.flywheel; import static com.simibubi.create.modules.contraptions.base.HorizontalKineticBlock.HORIZONTAL_FACING; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.SuperByteBuffer; @@ -11,6 +12,9 @@ import com.simibubi.create.modules.contraptions.components.flywheel.FlywheelBloc import net.minecraft.block.BlockState; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.AxisDirection; @@ -19,10 +23,14 @@ import net.minecraft.util.Rotation; public class FlywheelRenderer extends KineticTileEntityRenderer { + public FlywheelRenderer(TileEntityRendererDispatcher dispatcher) { + super(dispatcher); + } + @Override - public void renderFast(KineticTileEntity te, double x, double y, double z, float partialTicks, int destroyStage, - BufferBuilder buffer) { - super.renderFast(te, x, y, z, partialTicks, destroyStage, buffer); + protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, + int light, int overlay) { + super.renderSafe(te, partialTicks, ms, buffer, light, overlay); BlockState blockState = te.getBlockState(); FlywheelTileEntity wte = (FlywheelTileEntity) te; @@ -33,7 +41,7 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { if (FlywheelBlock.isConnected(blockState)) { Direction connection = FlywheelBlock.getConnection(blockState); - int light = blockState.getPackedLightmapCoords(getWorld(), te.getPos().offset(connection)); + int light = blockState.getPackedLightmapCoords(te.getWorld(), te.getPos().offset(connection)); float rotation = connection.getAxis() == Axis.X ^ connection.getAxisDirection() == AxisDirection.NEGATIVE ? -angle : angle; @@ -49,9 +57,8 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { false, rotation, flip), connection).translate(x, y, z).light(light).renderInto(buffer); } - kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING).getAxis(), AngleHelper.rad(angle), - getWorld()); - wheel.translate(x, y, z).renderInto(buffer); + kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING).getAxis(), AngleHelper.rad(angle)); + wheel.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/mixer/MechanicalMixerTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/mixer/MechanicalMixerTileEntityRenderer.java index 47a7d82d6..537b8d1c3 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/mixer/MechanicalMixerTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/mixer/MechanicalMixerTileEntityRenderer.java @@ -1,5 +1,7 @@ package com.simibubi.create.modules.contraptions.components.mixer; +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.SuperByteBuffer; @@ -8,33 +10,37 @@ import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; public class MechanicalMixerTileEntityRenderer extends KineticTileEntityRenderer { @Override - public void renderFast(KineticTileEntity te, double x, double y, double z, float partialTicks, - int destroyStage, BufferBuilder buffer) { + protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, + int light, int overlay) { BlockState blockState = te.getBlockState(); MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) te; BlockPos pos = te.getPos(); + IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); + SuperByteBuffer superBuffer = AllBlockPartials.SHAFTLESS_COGWHEEL.renderOn(blockState); - standardKineticRotationTransform(superBuffer, te, getWorld()).translate(x, y, z).renderInto(buffer); + standardKineticRotationTransform(superBuffer, te).renderInto(ms, vb); - int packedLightmapCoords = blockState.getPackedLightmapCoords(getWorld(), pos); + int packedLightmapCoords = blockState.getPackedLightmapCoords(te.getWorld(), pos); float renderedHeadOffset = mixer.getRenderedHeadOffset(partialTicks); float speed = mixer.getRenderedHeadRotationSpeed(partialTicks); float time = AnimationTickHolder.getRenderTick(); float angle = (float) (((time * speed * 6 / 10f) % 360) / 180 * (float) Math.PI); SuperByteBuffer poleRender = AllBlockPartials.MECHANICAL_MIXER_POLE.renderOn(blockState); - poleRender.translate(x, y - renderedHeadOffset, z).light(packedLightmapCoords).renderInto(buffer); + poleRender.translate(0, -renderedHeadOffset, 0).light(packedLightmapCoords).renderInto(ms, vb); SuperByteBuffer headRender = AllBlockPartials.MECHANICAL_MIXER_HEAD.renderOn(blockState); - headRender.rotateCentered(Axis.Y, angle).translate(x, y - renderedHeadOffset, z).light(packedLightmapCoords) - .renderInto(buffer); + headRender.rotateCentered(Axis.Y, angle).translate(0, -renderedHeadOffset, 0).light(packedLightmapCoords) + .renderInto(ms, vb); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/motor/MotorTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/motor/MotorTileEntityRenderer.java index aded2b19b..44cf94442 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/motor/MotorTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/motor/MotorTileEntityRenderer.java @@ -5,8 +5,14 @@ import com.simibubi.create.foundation.utility.SuperByteBuffer; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; + public class MotorTileEntityRenderer extends KineticTileEntityRenderer { + public MotorTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { + super(dispatcher); + } + @Override protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { return AllBlockPartials.SHAFT_HALF.renderOnHorizontal(te.getBlockState()); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/press/MechanicalPressTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/press/MechanicalPressTileEntityRenderer.java index 53997a1d9..362573c8a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/press/MechanicalPressTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/press/MechanicalPressTileEntityRenderer.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.components.press; import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.utility.SuperByteBuffer; @@ -10,23 +11,30 @@ import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.math.BlockPos; public class MechanicalPressTileEntityRenderer extends KineticTileEntityRenderer { + public MechanicalPressTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { + super(dispatcher); + } + @Override - public void renderFast(KineticTileEntity te, double x, double y, double z, float partialTicks, - int destroyStage, BufferBuilder buffer) { - super.renderFast(te, x, y, z, partialTicks, destroyStage, buffer); + protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, + int light, int overlay) { + super.renderSafe(te, partialTicks, ms, buffer, light, overlay); BlockPos pos = te.getPos(); BlockState blockState = te.getBlockState(); - int packedLightmapCoords = blockState.getPackedLightmapCoords(getWorld(), pos); + int packedLightmapCoords = blockState.getPackedLightmapCoords(te.getWorld(), pos); float renderedHeadOffset = ((MechanicalPressTileEntity) te).getRenderedHeadOffset(partialTicks); SuperByteBuffer headRender = AllBlockPartials.MECHANICAL_PRESS_HEAD.renderOnHorizontal(blockState); - headRender.translate(x, y - renderedHeadOffset, z).light(packedLightmapCoords).renderInto(buffer); + headRender.translate(0, -renderedHeadOffset, 0).light(packedLightmapCoords).renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/EncasedShaftTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/EncasedShaftTileEntityRenderer.java index 3a3221008..3a6d788c0 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/EncasedShaftTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/EncasedShaftTileEntityRenderer.java @@ -5,10 +5,15 @@ import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; import net.minecraft.block.BlockState; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; public class EncasedShaftTileEntityRenderer extends KineticTileEntityRenderer { + public EncasedShaftTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { + super(dispatcher); + } + @Override protected BlockState getRenderedBlockState(KineticTileEntity te) { return AllBlocks.SHAFT.get().getDefaultState().with(BlockStateProperties.AXIS, diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/SplitShaftTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/SplitShaftTileEntityRenderer.java index 4788aca94..f28d935f3 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/SplitShaftTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/encased/SplitShaftTileEntityRenderer.java @@ -1,5 +1,6 @@ package com.simibubi.create.modules.contraptions.relays.encased; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.SuperByteBuffer; @@ -8,16 +9,23 @@ import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; import net.minecraft.block.Block; -import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; public class SplitShaftTileEntityRenderer extends KineticTileEntityRenderer { + public SplitShaftTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { + super(dispatcher); + } + @Override - public void renderFast(KineticTileEntity te, double x, double y, double z, float partialTicks, int destroyStage, - BufferBuilder buffer) { + 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(); @@ -41,9 +49,8 @@ public class SplitShaftTileEntityRenderer extends KineticTileEntityRenderer { SuperByteBuffer superByteBuffer = AllBlockPartials.SHAFT_HALF.renderOnDirectional(te.getBlockState(), direction); - kineticRotationTransform(superByteBuffer, te, axis, angle, getWorld()); - superByteBuffer.translate(x, y, z).renderInto(buffer); - + kineticRotationTransform(superByteBuffer, te, axis, angle); + superByteBuffer.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeTileEntityRenderer.java index ca504251d..3bdc11a81 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeTileEntityRenderer.java @@ -1,5 +1,7 @@ package com.simibubi.create.modules.contraptions.relays.gauge; +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.foundation.utility.SuperByteBuffer; @@ -10,6 +12,8 @@ import com.simibubi.create.modules.contraptions.relays.gauge.GaugeBlock.Type; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; @@ -24,19 +28,19 @@ public class GaugeTileEntityRenderer extends KineticTileEntityRenderer { } @Override - public void renderFast(KineticTileEntity te, double x, double y, double z, float partialTicks, - int destroyStage, BufferBuilder buffer) { + protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, + int light, int overlay) { + super.renderSafe(te, partialTicks, ms, buffer, light, overlay); BlockState gaugeState = te.getBlockState(); - super.renderFast(te, x, y, z, partialTicks, destroyStage, buffer); GaugeTileEntity gaugeTE = (GaugeTileEntity) te; - int lightCoords = gaugeState.getPackedLightmapCoords(getWorld(), te.getPos()); + int lightCoords = gaugeState.getPackedLightmapCoords(te.getWorld(), te.getPos()); SuperByteBuffer headBuffer = (type == Type.SPEED ? AllBlockPartials.GAUGE_HEAD_SPEED : AllBlockPartials.GAUGE_HEAD_STRESS).renderOn(gaugeState); SuperByteBuffer dialBuffer = AllBlockPartials.GAUGE_DIAL.renderOn(gaugeState); for (Direction facing : Direction.values()) { - if (!((GaugeBlock) gaugeState.getBlock()).shouldRenderHeadOnFace(getWorld(), te.getPos(), gaugeState, + if (!((GaugeBlock) gaugeState.getBlock()).shouldRenderHeadOnFace(te.getWorld(), te.getPos(), gaugeState, facing)) continue; @@ -45,8 +49,9 @@ public class GaugeTileEntityRenderer extends KineticTileEntityRenderer { dialBuffer.translate(0, dialPivot, dialPivot).rotate(Axis.X, (float) (Math.PI / 2 * -progress)).translate(0, -dialPivot, -dialPivot); - rotateBufferTowards(dialBuffer, facing).light(lightCoords).translate(x, y, z).renderInto(buffer); - rotateBufferTowards(headBuffer, facing).light(lightCoords).translate(x, y, z).renderInto(buffer); + IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); + rotateBufferTowards(dialBuffer, facing).light(lightCoords).renderInto(ms, vb); + rotateBufferTowards(headBuffer, facing).light(lightCoords).renderInto(ms, vb); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/gearbox/GearboxTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/gearbox/GearboxTileEntityRenderer.java index 36f189084..38d3469b3 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/gearbox/GearboxTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/gearbox/GearboxTileEntityRenderer.java @@ -1,12 +1,15 @@ package com.simibubi.create.modules.contraptions.relays.gearbox; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.SuperByteBuffer; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer; -import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; @@ -14,9 +17,13 @@ import net.minecraft.util.math.BlockPos; public class GearboxTileEntityRenderer extends KineticTileEntityRenderer { + public GearboxTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { + super(dispatcher); + } + @Override - public void renderFast(KineticTileEntity te, double x, double y, double z, float partialTicks, - int destroyStage, BufferBuilder buffer) { + protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, + int light, int overlay) { final Axis boxAxis = te.getBlockState().get(BlockStateProperties.AXIS); final BlockPos pos = te.getPos(); float time = AnimationTickHolder.getRenderTick(); @@ -42,8 +49,8 @@ public class GearboxTileEntityRenderer extends KineticTileEntityRenderer { angle += offset; angle = angle / 180f * (float) Math.PI; - kineticRotationTransform(shaft, te, axis, angle, getWorld()); - shaft.translate(x, y, z).renderInto(buffer); + kineticRotationTransform(shaft, te, axis, angle); + shaft.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } } diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/SchematicHologram.java b/src/main/java/com/simibubi/create/modules/schematics/client/SchematicHologram.java index 8f5f13f4b..617b0e183 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/SchematicHologram.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/SchematicHologram.java @@ -1,14 +1,19 @@ package com.simibubi.create.modules.schematics.client; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; import org.lwjgl.opengl.GL11; +import org.lwjgl.system.MemoryUtil; +import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.datafixers.util.Pair; import com.simibubi.create.foundation.type.Cuboid; import com.simibubi.create.modules.schematics.SchematicWorld; @@ -20,13 +25,11 @@ import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.BlockRendererDispatcher; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.RegionRenderCacheBuilder; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.client.renderer.vertex.VertexFormatElement; -import net.minecraft.client.renderer.vertex.VertexFormatElement.Usage; import net.minecraft.entity.Entity; -import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.gen.feature.template.PlacementSettings; @@ -37,8 +40,8 @@ import net.minecraftforge.client.model.data.EmptyModelData; public class SchematicHologram { private final RegionRenderCacheBuilder bufferCache = new RegionRenderCacheBuilder(); - private final boolean[] usedBlockRenderLayers = new boolean[BlockRenderLayer.values().length]; - private final boolean[] startedBufferBuilders = new boolean[BlockRenderLayer.values().length]; + private final Set usedBlockRenderLayers = new HashSet<>(RenderType.getBlockLayers().size()); + private final Set startedBufferBuilders = new HashSet<>(RenderType.getBlockLayers().size()); private boolean active; private boolean changed; private SchematicWorld schematic; @@ -85,8 +88,8 @@ public class SchematicHologram { } private void redraw(Minecraft minecraft) { - Arrays.fill(usedBlockRenderLayers, false); - Arrays.fill(startedBufferBuilders, false); + usedBlockRenderLayers.clear(); + startedBufferBuilders.clear(); final SchematicWorld blockAccess = schematic; final BlockRendererDispatcher blockRendererDispatcher = minecraft.getBlockRendererDispatcher(); @@ -97,15 +100,13 @@ public class SchematicHologram { blockAccess.getBounds().getOrigin().add(blockAccess.getBounds().getSize()))) { BlockPos pos = localPos.add(anchor); BlockState state = blockAccess.getBlockState(pos); - for (BlockRenderLayer blockRenderLayer : BlockRenderLayer.values()) { - if (!state.getBlock().canRenderInLayer(state, blockRenderLayer)) { + for (RenderType blockRenderLayer : RenderType.getBlockLayers()) { + if (!RenderTypeLookup.canRenderInLayer(state, blockRenderLayer)) { continue; } ForgeHooksClient.setRenderLayer(blockRenderLayer); - final int blockRenderLayerId = blockRenderLayer.ordinal(); - final BufferBuilder bufferBuilder = bufferCache.getBuilder(blockRenderLayerId); - if (!startedBufferBuilders[blockRenderLayerId]) { - startedBufferBuilders[blockRenderLayerId] = true; + final BufferBuilder bufferBuilder = bufferCache.get(blockRenderLayer); + if (startedBufferBuilders.add(blockRenderLayer)) { // Copied from RenderChunk { bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); @@ -120,8 +121,9 @@ public class SchematicHologram { state = Blocks.QUARTZ_SLAB.getDefaultState(); } - usedBlockRenderLayers[blockRenderLayerId] |= blockRendererDispatcher.renderBlock(state, pos, - blockAccess, bufferBuilder, minecraft.world.rand, EmptyModelData.INSTANCE); + if (blockRendererDispatcher.renderModel(state, pos, blockAccess, new MatrixStack(), bufferBuilder, true, minecraft.world.rand, EmptyModelData.INSTANCE)) { + usedBlockRenderLayers.add(blockRenderLayer); + } blockstates.add(state); // if (Config.isShaders()) // SVertexBuilder.popEntity(bufferBuilder); @@ -130,11 +132,11 @@ public class SchematicHologram { } // finishDrawing - for (int blockRenderLayerId = 0; blockRenderLayerId < usedBlockRenderLayers.length; blockRenderLayerId++) { - if (!startedBufferBuilders[blockRenderLayerId]) { + for (RenderType layer : RenderType.getBlockLayers()) { + if (!startedBufferBuilders.contains(layer)) { continue; } - bufferCache.getBuilder(blockRenderLayerId).finishDrawing(); + bufferCache.get(layer).finishDrawing(); } } @@ -152,50 +154,35 @@ public class SchematicHologram { double renderPosY = view.y; double renderPosZ = view.z; - GlStateManager.enableAlphaTest(); - GlStateManager.enableBlend(); + RenderSystem.enableAlphaTest(); + RenderSystem.enableBlend(); Minecraft.getInstance().getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE); - for (int blockRenderLayerId = 0; blockRenderLayerId < usedBlockRenderLayers.length; blockRenderLayerId++) { - if (!usedBlockRenderLayers[blockRenderLayerId]) { + for (RenderType layer : RenderType.getBlockLayers()) { + if (!usedBlockRenderLayers.contains(layer)) { continue; } - final BufferBuilder bufferBuilder = bufferCache.getBuilder(blockRenderLayerId); - GlStateManager.pushMatrix(); - GlStateManager.translated(-renderPosX, -renderPosY, -renderPosZ); + final BufferBuilder bufferBuilder = bufferCache.get(layer); + RenderSystem.pushMatrix(); + RenderSystem.translated(-renderPosX, -renderPosY, -renderPosZ); drawBuffer(bufferBuilder); - GlStateManager.popMatrix(); + RenderSystem.popMatrix(); } - GlStateManager.disableAlphaTest(); - GlStateManager.disableBlend(); + RenderSystem.disableAlphaTest(); + RenderSystem.disableBlend(); } } - // Coppied from the Tesselator's vboUploader - Draw everything but don't + // Coppied from WorldVertexBufferUploader - Draw everything but don't // reset the buffer private static void drawBuffer(final BufferBuilder bufferBuilder) { - if (bufferBuilder.getVertexCount() > 0) { + Pair pair = bufferBuilder.popData(); + BufferBuilder.DrawState state = pair.getFirst(); - VertexFormat vertexformat = bufferBuilder.getVertexFormat(); - int size = vertexformat.getSize(); - ByteBuffer bytebuffer = bufferBuilder.getByteBuffer(); - List list = vertexformat.getElements(); - - for (int index = 0; index < list.size(); ++index) { - VertexFormatElement vertexformatelement = list.get(index); - Usage usage = vertexformatelement.getUsage(); - bytebuffer.position(vertexformat.getOffset(index)); - usage.preDraw(vertexformat, index, size, bytebuffer); - } - - GlStateManager.drawArrays(bufferBuilder.getDrawMode(), 0, bufferBuilder.getVertexCount()); - - for (int index = 0; index < list.size(); ++index) { - VertexFormatElement vertexformatelement = list.get(index); - Usage usage = vertexformatelement.getUsage(); - usage.postDraw(vertexformat, index, size, bytebuffer); - } + if (state.getCount() > 0) { + state.getVertexFormat().startDrawing(MemoryUtil.memAddress(pair.getSecond())); + GlStateManager.drawArrays(state.getMode(), 0, state.getCount()); + state.getVertexFormat().endDrawing(); } } - }