diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedBlazeBurner.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedBlazeBurner.java index a864c800b..c71ed7271 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedBlazeBurner.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedBlazeBurner.java @@ -1,8 +1,6 @@ package com.simibubi.create.compat.jei.category.animations; -import dev.engine_room.flywheel.lib.model.baked.PartialModel; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Axis; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllPartialModels; @@ -12,10 +10,10 @@ import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import dev.engine_room.flywheel.lib.model.baked.PartialModel; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.util.Mth; import net.minecraft.world.level.block.Blocks; @@ -84,14 +82,10 @@ public class AnimatedBlazeBurner extends AnimatedKinetics { uScroll = uScroll - Math.floor(uScroll); uScroll = uScroll * spriteWidth / 2; - Minecraft mc = Minecraft.getInstance(); - MultiBufferSource.BufferSource buffer = mc.renderBuffers() - .bufferSource(); - VertexConsumer vb = buffer.getBuffer(RenderType.cutoutMipped()); CachedBufferer.partial(AllPartialModels.BLAZE_BURNER_FLAME, Blocks.AIR.defaultBlockState()) - .shiftUVScrolling(spriteShift, (float) uScroll, (float) vScroll) - .light(LightTexture.FULL_BRIGHT) - .renderInto(matrixStack, vb); + .shiftUVScrolling(spriteShift, (float) uScroll, (float) vScroll) + .light(LightTexture.FULL_BRIGHT) + .renderInto(matrixStack, graphics.bufferSource().getBuffer(RenderType.cutoutMipped())); matrixStack.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterRenderer.java index 6cfb8125b..0aa9b7102 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterRenderer.java @@ -53,8 +53,8 @@ public class HarvesterRenderer extends SafeBlockEntityRenderer sbb - .light(matrices.getWorld(), LevelRenderer.getLightColor(renderWorld, context.localPos)) + sbb -> sbb.light(LevelRenderer.getLightColor(renderWorld, context.localPos)) + .useLevelLight(context.world, matrices.getWorld()) .renderInto(matrices.getViewProjection(), vb)); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/actors/roller/RollerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/actors/roller/RollerRenderer.java index c8b27df34..06064e32b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/actors/roller/RollerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/actors/roller/RollerRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.actors.roller; import static net.minecraft.world.level.block.state.properties.BlockStateProperties.HORIZONTAL_FACING; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import com.simibubi.create.AllPartialModels; import com.simibubi.create.content.contraptions.actors.harvester.HarvesterRenderer; import com.simibubi.create.content.contraptions.behaviour.MovementContext; @@ -34,6 +35,7 @@ public class RollerRenderer extends SmartBlockEntityRenderer super.renderSafe(be, partialTicks, ms, buffer, light, overlay); BlockState blockState = be.getBlockState(); + VertexConsumer vc = buffer.getBuffer(RenderType.cutoutMipped()); ms.pushPose(); ms.translate(0, -0.25, 0); @@ -45,19 +47,20 @@ public class RollerRenderer extends SmartBlockEntityRenderer superBuffer.translate(0, -.5, .5) .rotateYDegrees(90) .light(light) - .renderInto(ms, buffer.getBuffer(RenderType.cutoutMipped())); + .renderInto(ms, vc); ms.popPose(); CachedBufferer.partial(AllPartialModels.ROLLER_FRAME, blockState) .rotateCentered(AngleHelper.rad(AngleHelper.horizontalAngle(facing) + 180), Direction.UP) .light(light) - .renderInto(ms, buffer.getBuffer(RenderType.cutoutMipped())); + .renderInto(ms, vc); } public static void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld, ContraptionMatrices matrices, MultiBufferSource buffers) { BlockState blockState = context.state; Direction facing = blockState.getValue(HORIZONTAL_FACING); + VertexConsumer vc = buffers.getBuffer(RenderType.cutoutMipped()); SuperByteBuffer superBuffer = CachedBufferer.partial(AllPartialModels.ROLLER_WHEEL, blockState); float speed = (float) (!VecHelper.isVecPointingTowards(context.relativeMotion, facing.getOpposite()) ? context.getAnimationSpeed() @@ -76,15 +79,17 @@ public class RollerRenderer extends SmartBlockEntityRenderer int contraptionWorldLight = LevelRenderer.getLightColor(renderWorld, context.localPos); superBuffer.translate(0, -.5, .5) .rotateYDegrees(90) - .light(matrices.getWorld(), contraptionWorldLight) - .renderInto(viewProjection, buffers.getBuffer(RenderType.cutoutMipped())); + .light(contraptionWorldLight) + .useLevelLight(context.world, matrices.getWorld()) + .renderInto(viewProjection, vc); viewProjection.popPose(); CachedBufferer.partial(AllPartialModels.ROLLER_FRAME, blockState) .transform(matrices.getModel()) .rotateCentered(AngleHelper.rad(AngleHelper.horizontalAngle(facing) + 180), Direction.UP) - .light(matrices.getWorld(), contraptionWorldLight) - .renderInto(viewProjection, buffers.getBuffer(RenderType.cutoutMipped())); + .light(contraptionWorldLight) + .useLevelLight(context.world, matrices.getWorld()) + .renderInto(viewProjection, vc); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/actors/roller/TrackPaverV2.java b/src/main/java/com/simibubi/create/content/contraptions/actors/roller/TrackPaverV2.java index b716d8f25..e7b4fc628 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/actors/roller/TrackPaverV2.java +++ b/src/main/java/com/simibubi/create/content/contraptions/actors/roller/TrackPaverV2.java @@ -101,7 +101,7 @@ public class TrackPaverV2 { Map, Double> yLevels = new HashMap<>(); Map, Double> tLevels = new HashMap<>(); - BlockPos tePosition = bc.tePositions.getFirst(); + BlockPos bePosition = bc.bePositions.getFirst(); double radius = -task.getHorizontalInterval() .getFirst(); double r1 = radius - .575; @@ -109,10 +109,10 @@ public class TrackPaverV2 { double handleLength = bc.getHandleLength(); Vec3 start = bc.starts.getFirst() - .subtract(Vec3.atLowerCornerOf(tePosition)) + .subtract(Vec3.atLowerCornerOf(bePosition)) .add(0, 3 / 16f, 0); Vec3 end = bc.starts.getSecond() - .subtract(Vec3.atLowerCornerOf(tePosition)) + .subtract(Vec3.atLowerCornerOf(bePosition)) .add(0, 3 / 16f, 0); Vec3 startHandle = bc.axes.getFirst() .scale(handleLength) @@ -190,7 +190,7 @@ public class TrackPaverV2 { BlockPos targetPos = new BlockPos(entry.getKey() .getFirst(), floor, entry.getKey() - .getSecond()).offset(tePosition); + .getSecond()).offset(bePosition); task.put(targetPos.getX(), targetPos.getZ(), targetPos.getY() + (yValue - floor >= .5 ? .5f : 0)); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/actors/trainControls/ControlsRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/actors/trainControls/ControlsRenderer.java index 2f1cd9599..265542dbb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/actors/trainControls/ControlsRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/actors/trainControls/ControlsRenderer.java @@ -1,6 +1,5 @@ package com.simibubi.create.content.contraptions.actors.trainControls; -import dev.engine_room.flywheel.lib.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllPartialModels; import com.simibubi.create.content.contraptions.behaviour.MovementContext; @@ -11,6 +10,7 @@ import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.virtualWorld.VirtualRenderWorld; +import dev.engine_room.flywheel.lib.transform.TransformStack; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; @@ -32,7 +32,8 @@ public class ControlsRenderer { .center() .rotateYDegrees(hAngle) .uncenter() - .light(matrices.getWorld(), LevelRenderer.getLightColor(renderWorld, context.localPos)) + .light(LevelRenderer.getLightColor(renderWorld, context.localPos)) + .useLevelLight(context.world, matrices.getWorld()) .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.cutoutMipped())); double yOffset = Mth.lerp(equipAnimation * equipAnimation, -0.15f, 0.05f); @@ -52,7 +53,8 @@ public class ControlsRenderer { .translate(0, -2 / 16f, -3 / 16f) .translate(first ? 0 : 6 / 16f, 0, 0); lever.transform(ms) - .light(matrices.getWorld(), LevelRenderer.getLightColor(renderWorld, context.localPos)) + .light(LevelRenderer.getLightColor(renderWorld, context.localPos)) + .useLevelLight(context.world, matrices.getWorld()) .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.solid())); ms.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/bearing/StabilizedBearingMovementBehaviour.java index 5779bd0ee..310add593 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/bearing/StabilizedBearingMovementBehaviour.java @@ -4,9 +4,6 @@ import javax.annotation.Nullable; import org.joml.Quaternionf; -import dev.engine_room.flywheel.api.visualization.VisualizationContext; -import dev.engine_room.flywheel.api.visualization.VisualizationManager; -import dev.engine_room.flywheel.lib.model.baked.PartialModel; import com.mojang.math.Axis; import com.simibubi.create.AllPartialModels; import com.simibubi.create.content.contraptions.AbstractContraptionEntity; @@ -21,6 +18,9 @@ import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.virtualWorld.VirtualRenderWorld; +import dev.engine_room.flywheel.api.visualization.VisualizationContext; +import dev.engine_room.flywheel.api.visualization.VisualizationManager; +import dev.engine_room.flywheel.lib.model.baked.PartialModel; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; @@ -72,8 +72,8 @@ public class StabilizedBearingMovementBehaviour implements MovementBehaviour { superBuffer.rotateCentered(orientation); // render - superBuffer - .light(matrices.getWorld(), LevelRenderer.getLightColor(renderWorld, context.localPos)) + superBuffer.light(LevelRenderer.getLightColor(renderWorld, context.localPos)) + .useLevelLight(context.world, matrices.getWorld()) .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.solid())); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorPulleyRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorPulleyRenderer.java index 63d99454d..d9a89b15b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorPulleyRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorPulleyRenderer.java @@ -33,11 +33,10 @@ public class ElevatorPulleyRenderer extends KineticBlockEntityRenderer exten Axis rotationAxis = ((IRotate) be.getBlockState() .getBlock()).getRotationAxis(be.getBlockState()); + VertexConsumer vb = buffer.getBuffer(RenderType.solid()); kineticRotationTransform(getRotatedCoil(be), be, rotationAxis, AngleHelper.rad(offset * 180), light) - .renderInto(ms, buffer.getBuffer(RenderType.solid())); + .renderInto(ms, vb); Level world = be.getLevel(); BlockState blockState = be.getBlockState(); @@ -65,7 +66,6 @@ public abstract class AbstractPulleyRenderer exten SuperByteBuffer magnet = renderMagnet(be); SuperByteBuffer rope = renderRope(be); - VertexConsumer vb = buffer.getBuffer(RenderType.solid()); if (running || offset == 0) renderAt(world, offset > .25f ? magnet : halfMagnet, offset, pos, ms, vb); @@ -85,7 +85,7 @@ public abstract class AbstractPulleyRenderer exten BlockPos actualPos = pulleyPos.below((int) offset); int light = LevelRenderer.getLightColor(world, world.getBlockState(actualPos), actualPos); partial.translate(0, -offset, 0) - .light(light) + .light(light) .renderInto(ms, buffer); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/render/ContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/render/ContraptionEntityRenderer.java index 18a4aa9dd..30daf394d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/render/ContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/render/ContraptionEntityRenderer.java @@ -69,8 +69,7 @@ public class ContraptionEntityRenderer exte if (!sbb.isEmpty()) { VertexConsumer vc = buffers.getBuffer(renderType); sbb.transform(matrices.getModel()) - .light(matrices.getWorld()) - .hybridLight() + .useLevelLight(level, matrices.getWorld()) .renderInto(poseStack, vc); } } diff --git a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankArmorLayer.java b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankArmorLayer.java index 1f492bd50..2d3441ae4 100644 --- a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankArmorLayer.java +++ b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankArmorLayer.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.equipment.armor; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.AngleHelper; @@ -9,7 +10,6 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.model.EntityModel; import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.Sheets; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.client.renderer.entity.EntityRenderer; @@ -43,7 +43,7 @@ public class BacktankArmorLayer return; HumanoidModel model = (HumanoidModel) entityModel; - RenderType renderType = Sheets.cutoutBlockSheet(); + VertexConsumer vc = buffer.getBuffer(Sheets.cutoutBlockSheet()); BlockState renderedState = item.getBlock().defaultBlockState() .setValue(BacktankBlock.HORIZONTAL_FACING, Direction.SOUTH); SuperByteBuffer backtank = CachedBufferer.block(renderedState); @@ -57,7 +57,7 @@ public class BacktankArmorLayer backtank.disableDiffuse() .light(light) - .renderInto(ms, buffer.getBuffer(renderType)); + .renderInto(ms, vc); cogs.center() .rotateYDegrees(180) @@ -68,7 +68,7 @@ public class BacktankArmorLayer cogs.disableDiffuse() .light(light) - .renderInto(ms, buffer.getBuffer(renderType)); + .renderInto(ms, vc); ms.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntityRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntityRenderer.java index be8e9ae55..312087cc6 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntityRenderer.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.kinetics.base; import org.apache.commons.lang3.ArrayUtils; -import dev.engine_room.flywheel.api.visualization.VisualizationManager; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.simibubi.create.AllBlocks; @@ -15,6 +14,7 @@ import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Color; +import dev.engine_room.flywheel.api.visualization.VisualizationManager; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; @@ -50,8 +50,7 @@ public class KineticBlockEntityRenderer extends Sa BlockState state = getRenderedBlockState(be); RenderType type = getRenderType(be, state); - if (type != null) - renderRotatingBuffer(be, getRotatedModel(be, state), ms, buffer.getBuffer(type), light); + renderRotatingBuffer(be, getRotatedModel(be, state), ms, buffer.getBuffer(type), light); } protected BlockState getRenderedBlockState(T be) { @@ -66,7 +65,7 @@ public class KineticBlockEntityRenderer extends Sa for (RenderType type : REVERSED_CHUNK_BUFFER_LAYERS) if (typeSet.contains(type)) return type; - return null; + return RenderType.cutoutMipped(); } protected SuperByteBuffer getRotatedModel(T be, BlockState state) { @@ -84,7 +83,7 @@ public class KineticBlockEntityRenderer extends Sa standardKineticRotationTransform(superBuffer, be, light).renderInto(ms, buffer); } - public static float getAngleForTe(KineticBlockEntity be, final BlockPos pos, Axis axis) { + public static float getAngleForBe(KineticBlockEntity be, final BlockPos pos, Axis axis) { float time = AnimationTickHolder.getRenderTime(be.getLevel()); float offset = getRotationOffsetForPosition(be, pos, axis); float angle = ((time * be.getSpeed() * 3f / 10 + offset) % 360) / 180 * (float) Math.PI; @@ -96,7 +95,7 @@ public class KineticBlockEntityRenderer extends Sa final BlockPos pos = be.getBlockPos(); Axis axis = ((IRotate) be.getBlockState() .getBlock()).getRotationAxis(be.getBlockState()); - return kineticRotationTransform(buffer, be, axis, getAngleForTe(be, pos, axis), light); + return kineticRotationTransform(buffer, be, axis, getAngleForBe(be, pos, axis), light); } public static SuperByteBuffer kineticRotationTransform(SuperByteBuffer buffer, KineticBlockEntity be, Axis axis, diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java index 330896fc0..8139c65dc 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java @@ -118,7 +118,7 @@ public class BeltRenderer extends SafeBlockEntityRenderer { } beltBuffer - .transform(localTransforms) + .transform(localTransforms) .renderInto(ms, vb); // Diagonal belt do not have a separate bottom model diff --git a/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlockEntity.java index c06953d13..ff8d02946 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlockEntity.java @@ -91,7 +91,7 @@ public class ValveHandleBlockEntity extends HandCrankBlockEntity { @Override public float getIndependentAngle(float partialTicks) { if (inUse == 0 && source != null && getSpeed() != 0) - return KineticBlockEntityRenderer.getAngleForTe(this, worldPosition, + return KineticBlockEntityRenderer.getAngleForBe(this, worldPosition, KineticBlockEntityRenderer.getRotationAxisOf(this)); int step = getBlockState().getOptionalValue(ValveHandleBlock.FACING) diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java index aab7e367b..e382d5485 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java @@ -3,9 +3,6 @@ package com.simibubi.create.content.kinetics.deployer; import static com.simibubi.create.content.kinetics.base.DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE; import static com.simibubi.create.content.kinetics.base.DirectionalKineticBlock.FACING; -import dev.engine_room.flywheel.api.visualization.VisualizationManager; -import dev.engine_room.flywheel.lib.model.baked.PartialModel; -import dev.engine_room.flywheel.lib.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Axis; @@ -27,6 +24,9 @@ import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.virtualWorld.VirtualRenderWorld; +import dev.engine_room.flywheel.api.visualization.VisualizationManager; +import dev.engine_room.flywheel.lib.model.baked.PartialModel; +import dev.engine_room.flywheel.lib.transform.TransformStack; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.MultiBufferSource; @@ -213,11 +213,14 @@ public class DeployerRenderer extends SafeBlockEntityRenderer .rotateXDegrees(AngleHelper.verticalAngle(facing)) .rotateZDegrees(angle) .uncenter() - .light(matrices.getWorld(), - LevelRenderer.getLightColor(renderWorld, context.localPos)) + .light(LevelRenderer.getLightColor(renderWorld, context.localPos)) + .useLevelLight(context.world, matrices.getWorld()) .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.solid())); } diff --git a/src/main/java/com/simibubi/create/content/kinetics/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/fan/EncasedFanRenderer.java index 988292a1d..58286df27 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/fan/EncasedFanRenderer.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.kinetics.fan; import static net.minecraft.world.level.block.state.properties.BlockStateProperties.FACING; -import dev.engine_room.flywheel.api.visualization.VisualizationManager; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.simibubi.create.AllPartialModels; @@ -11,6 +10,7 @@ import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import dev.engine_room.flywheel.api.visualization.VisualizationManager; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java index 2266388e1..d0903a124 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java @@ -2,8 +2,6 @@ package com.simibubi.create.content.kinetics.saw; import static net.minecraft.world.level.block.state.properties.BlockStateProperties.FACING; -import dev.engine_room.flywheel.api.visualization.VisualizationManager; -import dev.engine_room.flywheel.lib.model.baked.PartialModel; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; import com.simibubi.create.AllPartialModels; @@ -19,6 +17,8 @@ import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.virtualWorld.VirtualRenderWorld; +import dev.engine_room.flywheel.api.visualization.VisualizationManager; +import dev.engine_room.flywheel.lib.model.baked.PartialModel; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.MultiBufferSource; @@ -198,7 +198,8 @@ public class SawRenderer extends SafeBlockEntityRenderer { } superBuffer.uncenter() - .light(matrices.getWorld(), LevelRenderer.getLightColor(renderWorld, context.localPos)) + .light(LevelRenderer.getLightColor(renderWorld, context.localPos)) + .useLevelLight(context.world, matrices.getWorld()) .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.cutoutMipped())); } diff --git a/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/BracketedKineticBlockEntityRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/BracketedKineticBlockEntityRenderer.java index ec046a8e8..3232a05f2 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/BracketedKineticBlockEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/BracketedKineticBlockEntityRenderer.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.kinetics.simpleRelays; -import dev.engine_room.flywheel.api.visualization.VisualizationManager; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllPartialModels; import com.simibubi.create.content.kinetics.base.KineticBlockEntityRenderer; @@ -9,6 +9,7 @@ import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import dev.engine_room.flywheel.api.visualization.VisualizationManager; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider.Context; @@ -38,17 +39,18 @@ public class BracketedKineticBlockEntityRenderer extends KineticBlockEntityRende // Large cogs sometimes have to offset their teeth by 11.25 degrees in order to // mesh properly + VertexConsumer vc = buffer.getBuffer(RenderType.solid()); Axis axis = getRotationAxisOf(be); Direction facing = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE); renderRotatingBuffer(be, CachedBufferer.partialFacingVertical(AllPartialModels.SHAFTLESS_LARGE_COGWHEEL, be.getBlockState(), facing), - ms, buffer.getBuffer(RenderType.solid()), light); + ms, vc, light); float angle = getAngleForLargeCogShaft(be, axis); SuperByteBuffer shaft = CachedBufferer.partialFacingVertical(AllPartialModels.COGWHEEL_SHAFT, be.getBlockState(), facing); kineticRotationTransform(shaft, be, axis, angle, light); - shaft.renderInto(ms, buffer.getBuffer(RenderType.solid())); + shaft.renderInto(ms, vc); } diff --git a/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/encased/EncasedCogRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/encased/EncasedCogRenderer.java index a7d2cf094..a2d40e792 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/encased/EncasedCogRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/encased/EncasedCogRenderer.java @@ -1,6 +1,5 @@ package com.simibubi.create.content.kinetics.simpleRelays.encased; -import dev.engine_room.flywheel.api.visualization.VisualizationManager; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllPartialModels; import com.simibubi.create.content.kinetics.base.IRotate; @@ -11,6 +10,7 @@ import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.Iterate; +import dev.engine_room.flywheel.api.visualization.VisualizationManager; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; @@ -54,7 +54,7 @@ public class EncasedCogRenderer extends KineticBlockEntityRenderer { int light, int overlay) { super.renderSafe(be, partialTicks, ms, buffer, light, overlay); - VertexConsumer vertexBuilder = buffer.getBuffer(RenderType.solid()); float lidProgress = be.getLidProgress(partialTicks); float angle = lidProgress * 70; @@ -49,7 +47,7 @@ public class EjectorRenderer extends ShaftRenderer { SuperByteBuffer model = CachedBufferer.partial(AllPartialModels.EJECTOR_TOP, be.getBlockState()); applyLidAngle(be, angle, model); model.light(light) - .renderInto(ms, vertexBuilder); + .renderInto(ms, buffer.getBuffer(RenderType.solid())); } var msr = TransformStack.of(ms); diff --git a/src/main/java/com/simibubi/create/content/redstone/displayLink/DisplayLinkRenderer.java b/src/main/java/com/simibubi/create/content/redstone/displayLink/DisplayLinkRenderer.java index 8ccfddcf9..9ca03ea53 100644 --- a/src/main/java/com/simibubi/create/content/redstone/displayLink/DisplayLinkRenderer.java +++ b/src/main/java/com/simibubi/create/content/redstone/displayLink/DisplayLinkRenderer.java @@ -1,6 +1,5 @@ package com.simibubi.create.content.redstone.displayLink; -import dev.engine_room.flywheel.lib.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllPartialModels; import com.simibubi.create.foundation.blockEntity.renderer.SafeBlockEntityRenderer; @@ -8,6 +7,7 @@ import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.render.RenderTypes; import com.simibubi.create.foundation.utility.AngleHelper; +import dev.engine_room.flywheel.lib.transform.TransformStack; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; @@ -57,7 +57,7 @@ public class DisplayLinkRenderer extends SafeBlockEntityRenderer return; M entityModel = getParentModel(); - RenderType renderType = Sheets.cutoutBlockSheet(); ms.pushPose(); boolean valid = false; @@ -127,7 +125,7 @@ public class TrainHatArmorLayer CachedBufferer.partial(AllPartialModels.TRAIN_HAT, air) .disableDiffuse() .light(light) - .renderInto(ms, buffer.getBuffer(renderType)); + .renderInto(ms, buffer.getBuffer(Sheets.cutoutBlockSheet())); } ms.popPose(); diff --git a/src/main/java/com/simibubi/create/content/trains/track/BezierConnection.java b/src/main/java/com/simibubi/create/content/trains/track/BezierConnection.java index d09090d71..393abe414 100644 --- a/src/main/java/com/simibubi/create/content/trains/track/BezierConnection.java +++ b/src/main/java/com/simibubi/create/content/trains/track/BezierConnection.java @@ -34,7 +34,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; public class BezierConnection implements Iterable { - public Couple tePositions; + public Couple bePositions; public Couple starts; public Couple axes; public Couple normals; @@ -59,7 +59,7 @@ public class BezierConnection implements Iterable { public BezierConnection(Couple positions, Couple starts, Couple axes, Couple normals, boolean primary, boolean girder, TrackMaterial material) { - tePositions = positions; + bePositions = positions; this.starts = starts; this.axes = axes; this.normals = normals; @@ -70,7 +70,7 @@ public class BezierConnection implements Iterable { } public BezierConnection secondary() { - BezierConnection bezierConnection = new BezierConnection(tePositions.swap(), starts.swap(), axes.swap(), + BezierConnection bezierConnection = new BezierConnection(bePositions.swap(), starts.swap(), axes.swap(), normals.swap(), !primary, hasGirder, trackMaterial); if (smoothing != null) bezierConnection.smoothing = smoothing.swap(); @@ -96,7 +96,7 @@ public class BezierConnection implements Iterable { } private boolean equalsSansMaterialInner(BezierConnection other) { - return this == other || (other != null && coupleEquals(this.tePositions, other.tePositions) + return this == other || (other != null && coupleEquals(this.bePositions, other.bePositions) && coupleEquals(this.starts, other.starts) && coupleEquals(this.axes, other.axes) && coupleEquals(this.normals, other.normals) && this.hasGirder == other.hasGirder); } @@ -116,7 +116,7 @@ public class BezierConnection implements Iterable { } public CompoundTag write(BlockPos localTo) { - Couple tePositions = this.tePositions.map(b -> b.subtract(localTo)); + Couple tePositions = this.bePositions.map(b -> b.subtract(localTo)); Couple starts = this.starts.map(v -> v.subtract(Vec3.atLowerCornerOf(localTo))); CompoundTag compound = new CompoundTag(); @@ -143,7 +143,7 @@ public class BezierConnection implements Iterable { } public void write(FriendlyByteBuf buffer) { - tePositions.forEach(buffer::writeBlockPos); + bePositions.forEach(buffer::writeBlockPos); starts.forEach(v -> VecHelper.write(v, buffer)); axes.forEach(v -> VecHelper.write(v, buffer)); normals.forEach(v -> VecHelper.write(v, buffer)); @@ -156,7 +156,7 @@ public class BezierConnection implements Iterable { } public BlockPos getKey() { - return tePositions.getSecond(); + return bePositions.getSecond(); } public boolean isPrimary() { @@ -346,7 +346,7 @@ public class BezierConnection implements Iterable { @Override public Iterator iterator() { resolve(); - var offset = Vec3.atLowerCornerOf(tePositions.getFirst()) + var offset = Vec3.atLowerCornerOf(bePositions.getFirst()) .scale(-1) .add(0, 3 / 16f, 0); return new Bezierator(this, offset); @@ -378,7 +378,7 @@ public class BezierConnection implements Iterable { if (!level.getGameRules() .getBoolean(GameRules.RULE_DOBLOCKDROPS)) return; - Vec3 origin = Vec3.atLowerCornerOf(tePositions.getFirst()); + Vec3 origin = Vec3.atLowerCornerOf(bePositions.getFirst()); for (Segment segment : this) { if (segment.index % 2 != 0 || segment.index == getSegmentCount()) continue; @@ -403,7 +403,7 @@ public class BezierConnection implements Iterable { new BlockParticleOption(ParticleTypes.BLOCK, AllBlocks.METAL_GIRDER.getDefaultState()); if (!(level instanceof ServerLevel slevel)) return; - Vec3 origin = Vec3.atLowerCornerOf(tePositions.getFirst()); + Vec3 origin = Vec3.atLowerCornerOf(bePositions.getFirst()); for (Segment segment : this) { for (int offset : Iterate.positiveAndNegative) { Vec3 v = segment.position.add(segment.normal.scale(14 / 16f * offset)) diff --git a/src/main/java/com/simibubi/create/content/trains/track/TrackBlock.java b/src/main/java/com/simibubi/create/content/trains/track/TrackBlock.java index 815e3858e..9e081cf7e 100644 --- a/src/main/java/com/simibubi/create/content/trains/track/TrackBlock.java +++ b/src/main/java/com/simibubi/create/content/trains/track/TrackBlock.java @@ -369,7 +369,7 @@ public class TrackBlock extends Block Map connections = trackBE.getConnections(); connections.forEach((connectedPos, bc) -> ITrackBlock.addToListIfConnected(connectedTo, list, - (d, b) -> d == 1 ? Vec3.atLowerCornerOf(bc.tePositions.get(b)) : bc.starts.get(b), bc.normals::get, + (d, b) -> d == 1 ? Vec3.atLowerCornerOf(bc.bePositions.get(b)) : bc.starts.get(b), bc.normals::get, b -> world instanceof Level l ? l.dimension() : Level.OVERWORLD, bc::yOffsetAt, null, bc, (b, v) -> ITrackBlock.getMaterialSimple(world, v, bc.getMaterial()))); diff --git a/src/main/java/com/simibubi/create/content/trains/track/TrackBlockEntity.java b/src/main/java/com/simibubi/create/content/trains/track/TrackBlockEntity.java index 10c6f0b09..cdf2bd862 100644 --- a/src/main/java/com/simibubi/create/content/trains/track/TrackBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/trains/track/TrackBlockEntity.java @@ -93,7 +93,7 @@ public class TrackBlockEntity extends SmartBlockEntity implements ITransformable BlockPos key = entry.getKey(); BezierConnection bc = entry.getValue(); - if (!key.equals(bc.getKey()) || !worldPosition.equals(bc.tePositions.getFirst())) { + if (!key.equals(bc.getKey()) || !worldPosition.equals(bc.bePositions.getFirst())) { invalid.add(key); continue; } @@ -159,7 +159,7 @@ public class TrackBlockEntity extends SmartBlockEntity implements ITransformable for (BezierConnection bezierConnection : connections.values()) { if (!(level.getBlockEntity(bezierConnection.getKey())instanceof TrackBlockEntity tbe)) return; - tbe.removeConnection(bezierConnection.tePositions.getFirst()); + tbe.removeConnection(bezierConnection.bePositions.getFirst()); if (!dropAndDiscard) continue; if (!cancelDrops) @@ -282,10 +282,10 @@ public class TrackBlockEntity extends SmartBlockEntity implements ITransformable newConnection.normals.replace(transform::applyWithoutOffsetUncentered); newConnection.axes.replace(transform::applyWithoutOffsetUncentered); - BlockPos diff = newConnection.tePositions.getSecond() - .subtract(newConnection.tePositions.getFirst()); - newConnection.tePositions - .setSecond(BlockPos.containing(Vec3.atCenterOf(newConnection.tePositions.getFirst()) + BlockPos diff = newConnection.bePositions.getSecond() + .subtract(newConnection.bePositions.getFirst()); + newConnection.bePositions + .setSecond(BlockPos.containing(Vec3.atCenterOf(newConnection.bePositions.getFirst()) .add(transform.applyWithoutOffsetUncentered(Vec3.atLowerCornerOf(diff))))); Vec3 beVec = Vec3.atLowerCornerOf(worldPosition); @@ -364,7 +364,7 @@ public class TrackBlockEntity extends SmartBlockEntity implements ITransformable public void manageFakeTracksAlong(BezierConnection bc, boolean remove) { Map, Double> yLevels = new HashMap<>(); - BlockPos tePosition = bc.tePositions.getFirst(); + BlockPos tePosition = bc.bePositions.getFirst(); Vec3 end1 = bc.starts.getFirst() .subtract(Vec3.atLowerCornerOf(tePosition)) .add(0, 3 / 16f, 0); diff --git a/src/main/java/com/simibubi/create/content/trains/track/TrackMaterial.java b/src/main/java/com/simibubi/create/content/trains/track/TrackMaterial.java index 16be7f504..0a72008ac 100644 --- a/src/main/java/com/simibubi/create/content/trains/track/TrackMaterial.java +++ b/src/main/java/com/simibubi/create/content/trains/track/TrackMaterial.java @@ -163,7 +163,7 @@ public class TrackMaterial { } @OnlyIn(Dist.CLIENT) - public record TrackModelHolder(PartialModel tie, PartialModel segment_left, PartialModel segment_right) { + public record TrackModelHolder(PartialModel tie, PartialModel leftSegment, PartialModel rightSegment) { static final TrackModelHolder DEFAULT = new TrackModelHolder(AllPartialModels.TRACK_TIE, AllPartialModels.TRACK_SEGMENT_LEFT, AllPartialModels.TRACK_SEGMENT_RIGHT); } diff --git a/src/main/java/com/simibubi/create/content/trains/track/TrackPaver.java b/src/main/java/com/simibubi/create/content/trains/track/TrackPaver.java index 3a2058e6e..bb7ced143 100644 --- a/src/main/java/com/simibubi/create/content/trains/track/TrackPaver.java +++ b/src/main/java/com/simibubi/create/content/trains/track/TrackPaver.java @@ -99,7 +99,7 @@ public class TrackPaver { } Map, Double> yLevels = new HashMap<>(); - BlockPos tePosition = bc.tePositions.getFirst(); + BlockPos tePosition = bc.bePositions.getFirst(); Vec3 end1 = bc.starts.getFirst() .subtract(Vec3.atLowerCornerOf(tePosition)) .add(0, 3 / 16f, 0); diff --git a/src/main/java/com/simibubi/create/content/trains/track/TrackRenderer.java b/src/main/java/com/simibubi/create/content/trains/track/TrackRenderer.java index 30cf36622..85706c2cd 100644 --- a/src/main/java/com/simibubi/create/content/trains/track/TrackRenderer.java +++ b/src/main/java/com/simibubi/create/content/trains/track/TrackRenderer.java @@ -48,15 +48,15 @@ public class TrackRenderer extends SafeBlockEntityRenderer { return; ms.pushPose(); - BlockPos tePosition = bc.tePositions.getFirst(); + BlockPos bePosition = bc.bePositions.getFirst(); BlockState air = Blocks.AIR.defaultBlockState(); SegmentAngles[] segments = bc.getBakedSegments(); - renderGirder(level, bc, ms, vb, tePosition); + renderGirder(level, bc, ms, vb, bePosition); for (int i = 1; i < segments.length; i++) { SegmentAngles segment = segments[i]; - int light = LevelRenderer.getLightColor(level, segment.lightPosition.offset(tePosition)); + int light = LevelRenderer.getLightColor(level, segment.lightPosition.offset(bePosition)); TrackMaterial.TrackModelHolder modelHolder = bc.getMaterial().getModelHolder(); @@ -68,7 +68,7 @@ public class TrackRenderer extends SafeBlockEntityRenderer { for (boolean first : Iterate.trueAndFalse) { Pose transform = segment.railTransforms.get(first); - CachedBufferer.partial(first ? modelHolder.segment_left() : modelHolder.segment_right(), air) + CachedBufferer.partial(first ? modelHolder.leftSegment() : modelHolder.rightSegment(), air) .mulPose(transform.pose()) .mulNormal(transform.normal()) .light(light) diff --git a/src/main/java/com/simibubi/create/content/trains/track/TrackVisual.java b/src/main/java/com/simibubi/create/content/trains/track/TrackVisual.java index a478c1769..c9bc26f04 100644 --- a/src/main/java/com/simibubi/create/content/trains/track/TrackVisual.java +++ b/src/main/java/com/simibubi/create/content/trains/track/TrackVisual.java @@ -123,7 +123,7 @@ public class TrackVisual extends AbstractBlockEntityVisual { private @Nullable GirderVisual girder; private BezierTrackVisual(BezierConnection bc) { - BlockPos tePosition = bc.tePositions.getFirst(); + BlockPos tePosition = bc.bePositions.getFirst(); girder = bc.hasGirder ? new GirderVisual(bc) : null; PoseStack pose = new PoseStack(); @@ -142,9 +142,9 @@ public class TrackVisual extends AbstractBlockEntityVisual { instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.partial(modelHolder.tie())) .createInstances(ties); - instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.partial(modelHolder.segment_left())) + instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.partial(modelHolder.leftSegment())) .createInstances(left); - instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.partial(modelHolder.segment_right())) + instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.partial(modelHolder.rightSegment())) .createInstances(right); SegmentAngles[] segments = bc.getBakedSegments(); @@ -209,11 +209,11 @@ public class TrackVisual extends AbstractBlockEntityVisual { private final BlockPos[] lightPos; private GirderVisual(BezierConnection bc) { - BlockPos tePosition = bc.tePositions.getFirst(); + BlockPos tePosition = bc.bePositions.getFirst(); PoseStack pose = new PoseStack(); TransformStack.of(pose) .translate(getVisualPosition()) - .nudge((int) bc.tePositions.getFirst() + .nudge((int) bc.bePositions.getFirst() .asLong()); int segCount = bc.getSegmentCount(); diff --git a/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java b/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java index 1e1707e97..3e338b91e 100644 --- a/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/fluid/FluidRenderer.java @@ -33,7 +33,7 @@ import net.minecraftforge.fluids.FluidType; public class FluidRenderer { public static VertexConsumer getFluidBuilder(MultiBufferSource buffer) { - return buffer.getBuffer(RenderTypes.getFluid()); + return buffer.getBuffer(RenderTypes.fluid()); } public static void renderFluidStream(FluidStack fluidStack, Direction direction, float radius, float progress, diff --git a/src/main/java/com/simibubi/create/foundation/gui/CustomLightingSettings.java b/src/main/java/com/simibubi/create/foundation/gui/CustomLightingSettings.java index 2618fd9bf..86f8bbb28 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/CustomLightingSettings.java +++ b/src/main/java/com/simibubi/create/foundation/gui/CustomLightingSettings.java @@ -1,6 +1,5 @@ package com.simibubi.create.foundation.gui; -import org.joml.Matrix4f; import org.joml.Vector3f; import com.mojang.blaze3d.systems.RenderSystem; @@ -10,7 +9,6 @@ public class CustomLightingSettings implements ILightingSettings { private Vector3f light1; private Vector3f light2; - private Matrix4f lightMatrix; protected CustomLightingSettings(float yRot, float xRot) { init(yRot, xRot, 0, 0, false); @@ -32,14 +30,11 @@ public class CustomLightingSettings implements ILightingSettings { } else { light2 = new Vector3f(); } - - lightMatrix = new Matrix4f(); - lightMatrix.identity(); } @Override public void applyLighting() { - RenderSystem.setupLevelDiffuseLighting(light1, light2, lightMatrix); + RenderSystem.setShaderLights(light1, light2); } public static Builder builder() { diff --git a/src/main/java/com/simibubi/create/foundation/gui/element/GuiGameElement.java b/src/main/java/com/simibubi/create/foundation/gui/element/GuiGameElement.java index 4cc63f916..c26ce914c 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/element/GuiGameElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/element/GuiGameElement.java @@ -171,8 +171,7 @@ public class GuiGameElement { Minecraft mc = Minecraft.getInstance(); BlockRenderDispatcher blockRenderer = mc.getBlockRenderer(); - MultiBufferSource.BufferSource buffer = mc.renderBuffers() - .bufferSource(); + MultiBufferSource.BufferSource buffer = graphics.bufferSource(); transformMatrix(matrixStack); @@ -264,11 +263,11 @@ public class GuiGameElement { PoseStack matrixStack = graphics.pose(); prepareMatrix(matrixStack); transformMatrix(matrixStack); - renderItemIntoGUI(matrixStack, stack, customLighting == null); + renderItemIntoGUI(graphics, matrixStack, stack, customLighting == null); cleanUpMatrix(matrixStack); } - public static void renderItemIntoGUI(PoseStack matrixStack, ItemStack stack, boolean useDefaultLighting) { + public static void renderItemIntoGUI(GuiGraphics graphics, PoseStack matrixStack, ItemStack stack, boolean useDefaultLighting) { ItemRenderer renderer = Minecraft.getInstance().getItemRenderer(); BakedModel bakedModel = renderer.getModel(stack, null, null, 0); @@ -282,7 +281,7 @@ public class GuiGameElement { matrixStack.translate(0, 0, 100.0F); matrixStack.translate(8.0F, -8.0F, 0.0F); matrixStack.scale(16.0F, 16.0F, 16.0F); - MultiBufferSource.BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource(); + MultiBufferSource.BufferSource buffer = graphics.bufferSource(); boolean flatLighting = !bakedModel.usesBlockLight(); if (useDefaultLighting && flatLighting) { Lighting.setupForFlatItems(); diff --git a/src/main/java/com/simibubi/create/foundation/item/render/PartialItemModelRenderer.java b/src/main/java/com/simibubi/create/foundation/item/render/PartialItemModelRenderer.java index 9a07c3b00..b03db2b94 100644 --- a/src/main/java/com/simibubi/create/foundation/item/render/PartialItemModelRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/item/render/PartialItemModelRenderer.java @@ -8,6 +8,7 @@ import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.Sheets; import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; @@ -41,19 +42,19 @@ public class PartialItemModelRenderer { } public void render(BakedModel model, int light) { - render(model, RenderTypes.getItemPartialTranslucent(), light); + render(model, Sheets.translucentCullBlockSheet(), light); } public void renderSolid(BakedModel model, int light) { - render(model, RenderTypes.getItemPartialSolid(), light); - } - - public void renderSolidGlowing(BakedModel model, int light) { - render(model, RenderTypes.getGlowingSolid(), light); + render(model, Sheets.solidBlockSheet(), light); } public void renderGlowing(BakedModel model, int light) { - render(model, RenderTypes.getGlowingTranslucent(), light); + render(model, RenderTypes.itemGlowingTranslucent(), light); + } + + public void renderSolidGlowing(BakedModel model, int light) { + render(model, RenderTypes.itemGlowingSolid(), light); } public void render(BakedModel model, RenderType type, int light) { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/accessor/RenderSystemAccessor.java b/src/main/java/com/simibubi/create/foundation/mixin/accessor/RenderSystemAccessor.java new file mode 100644 index 000000000..96b9ec1d1 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/accessor/RenderSystemAccessor.java @@ -0,0 +1,15 @@ +package com.simibubi.create.foundation.mixin.accessor; + +import org.joml.Vector3f; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import com.mojang.blaze3d.systems.RenderSystem; + +@Mixin(RenderSystem.class) +public interface RenderSystemAccessor { + @Accessor("shaderLightDirections") + static Vector3f[] create$getShaderLightDirections() { + throw new AssertionError(); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/outliner/AABBOutline.java b/src/main/java/com/simibubi/create/foundation/outliner/AABBOutline.java index ed94ace11..555a6704c 100644 --- a/src/main/java/com/simibubi/create/foundation/outliner/AABBOutline.java +++ b/src/main/java/com/simibubi/create/foundation/outliner/AABBOutline.java @@ -70,7 +70,7 @@ public class AABBOutline extends Outline { if (lineWidth == 0) return; - VertexConsumer consumer = buffer.getBuffer(RenderTypes.getOutlineSolid()); + VertexConsumer consumer = buffer.getBuffer(RenderTypes.outlineSolid()); renderBoxEdges(ms, consumer, minPos, maxPos, lineWidth, color, lightmap, disableLineNormals); } @@ -94,7 +94,7 @@ public class AABBOutline extends Outline { return; AllSpecialTextures faceTexture = optionalFaceTexture.get(); - RenderType renderType = RenderTypes.getOutlineTranslucent(faceTexture.getLocation(), cull); + RenderType renderType = RenderTypes.outlineTranslucent(faceTexture.getLocation(), cull); VertexConsumer consumer = buffer.getLateBuffer(renderType); float alphaMult = highlighted ? 1 : 0.5f; diff --git a/src/main/java/com/simibubi/create/foundation/outliner/BlockClusterOutline.java b/src/main/java/com/simibubi/create/foundation/outliner/BlockClusterOutline.java index 59b8a4d00..fc8b46316 100644 --- a/src/main/java/com/simibubi/create/foundation/outliner/BlockClusterOutline.java +++ b/src/main/java/com/simibubi/create/foundation/outliner/BlockClusterOutline.java @@ -63,7 +63,7 @@ public class BlockClusterOutline extends Outline { AllSpecialTextures faceTexture = optionalFaceTexture.get(); PoseStack.Pose pose = ms.last(); - RenderType renderType = RenderTypes.getOutlineTranslucent(faceTexture.getLocation(), true); + RenderType renderType = RenderTypes.outlineTranslucent(faceTexture.getLocation(), true); VertexConsumer consumer = buffer.getLateBuffer(renderType); cluster.visibleFaces.forEach((face, axisDirection) -> { @@ -89,7 +89,7 @@ public class BlockClusterOutline extends Outline { cluster.anchor.getZ() - camera.z); PoseStack.Pose pose = ms.last(); - VertexConsumer consumer = buffer.getBuffer(RenderTypes.getOutlineSolid()); + VertexConsumer consumer = buffer.getBuffer(RenderTypes.outlineSolid()); cluster.visibleEdges.forEach(edge -> { BlockPos pos = edge.pos; diff --git a/src/main/java/com/simibubi/create/foundation/outliner/LineOutline.java b/src/main/java/com/simibubi/create/foundation/outliner/LineOutline.java index 09cd2a6a0..aad99f336 100644 --- a/src/main/java/com/simibubi/create/foundation/outliner/LineOutline.java +++ b/src/main/java/com/simibubi/create/foundation/outliner/LineOutline.java @@ -34,7 +34,7 @@ public class LineOutline extends Outline { if (width == 0) return; - VertexConsumer consumer = buffer.getBuffer(RenderTypes.getOutlineSolid()); + VertexConsumer consumer = buffer.getBuffer(RenderTypes.outlineSolid()); params.loadColor(colorTemp); Vector4f color = colorTemp; int lightmap = params.lightmap; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java index 703323873..d35b79671 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java @@ -20,7 +20,6 @@ import org.apache.commons.lang3.mutable.MutableObject; import org.joml.Matrix4f; import org.joml.Vector4f; -import dev.engine_room.flywheel.lib.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.gui.UIRenderHelper; import com.simibubi.create.foundation.outliner.Outliner; @@ -31,8 +30,6 @@ import com.simibubi.create.foundation.ponder.element.WorldSectionElement; import com.simibubi.create.foundation.ponder.instruction.HideAllInstruction; import com.simibubi.create.foundation.ponder.instruction.PonderInstruction; import com.simibubi.create.foundation.ponder.ui.PonderUI; -import com.simibubi.create.foundation.render.DiffuseLightCalculator; -import com.simibubi.create.foundation.render.ForcedDiffuseState; import com.simibubi.create.foundation.render.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Pair; @@ -40,6 +37,7 @@ import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.infrastructure.ponder.PonderIndex; +import dev.engine_room.flywheel.lib.transform.TransformStack; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import net.minecraft.client.Camera; @@ -236,7 +234,6 @@ public class PonderScene { } public void renderScene(SuperRenderTypeBuffer buffer, PoseStack ms, float pt) { - ForcedDiffuseState.pushCalculator(DiffuseLightCalculator.DEFAULT); ms.pushPose(); Minecraft mc = Minecraft.getInstance(); @@ -256,7 +253,6 @@ public class PonderScene { outliner.renderOutlines(ms, buffer, Vec3.ZERO, pt); ms.popPose(); - ForcedDiffuseState.popCalculator(); } public void renderOverlay(PonderUI screen, GuiGraphics graphics, float partialTicks) { diff --git a/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java b/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java index 36f8cc83b..dc3f932a1 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java @@ -305,7 +305,7 @@ public class WorldSectionElement extends AnimatedSceneElement { public void renderFirst(PonderWorld world, MultiBufferSource buffer, PoseStack ms, float fade, float pt) { int light = -1; if (fade != 1) - light = (int) (Mth.lerp(fade, 5, 14)); + light = (int) (Mth.lerp(fade, 5, 15)); if (redraw) { renderedBlockEntities = null; tickableBlockEntities = null; @@ -359,14 +359,14 @@ public class WorldSectionElement extends AnimatedSceneElement { if (redraw) bufferCache.invalidate(DOC_WORLD_SECTION, key); - SuperByteBuffer contraptionBuffer = + SuperByteBuffer structureBuffer = bufferCache.get(DOC_WORLD_SECTION, key, () -> buildStructureBuffer(world, type)); - if (contraptionBuffer.isEmpty()) + if (structureBuffer.isEmpty()) return; - transformMS(contraptionBuffer.getTransforms(), pt); + transformMS(structureBuffer.getTransforms(), pt); int light = lightCoordsFromFade(fade); - contraptionBuffer + structureBuffer .light(light) .renderInto(ms, buffer.getBuffer(type)); } @@ -415,6 +415,7 @@ public class WorldSectionElement extends AnimatedSceneElement { sbbBuilder.begin(); world.setMask(this.section); + world.pushFakeLight(0); ModelBlockRenderer.enableCaching(); section.forEach(pos -> { BlockState state = world.getBlockState(pos); @@ -444,6 +445,7 @@ public class WorldSectionElement extends AnimatedSceneElement { } }); ModelBlockRenderer.clearCache(); + world.popLight(); world.clearMask(); return sbbBuilder.end(); diff --git a/src/main/java/com/simibubi/create/foundation/render/DiffuseLightCalculator.java b/src/main/java/com/simibubi/create/foundation/render/DiffuseLightCalculator.java deleted file mode 100644 index 755e42687..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/DiffuseLightCalculator.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.simibubi.create.foundation.render; - -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraftforge.client.model.lighting.QuadLighter; - -public interface DiffuseLightCalculator { - DiffuseLightCalculator DEFAULT = DiffuseLightCalculator::diffuseLight; - DiffuseLightCalculator NETHER = DiffuseLightCalculator::diffuseLightNether; - - static DiffuseLightCalculator forLevel(ClientLevel level) { - return level.effects().constantAmbientLight() ? NETHER : DEFAULT; - } - - float getDiffuse(float normalX, float normalY, float normalZ, boolean shaded); - - static float diffuseLight(float x, float y, float z, boolean shaded) { - if (!shaded) { - return 1f; - } - return QuadLighter.calculateShade(x, y, z, false); - } - - static float diffuseLightNether(float x, float y, float z, boolean shaded) { - if (!shaded) { - return 0.9f; - } - return QuadLighter.calculateShade(x, y, z, true); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/ForcedDiffuseState.java b/src/main/java/com/simibubi/create/foundation/render/ForcedDiffuseState.java deleted file mode 100644 index 3c94a6281..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/ForcedDiffuseState.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.simibubi.create.foundation.render; - -import javax.annotation.Nullable; - -import it.unimi.dsi.fastutil.objects.ObjectArrayList; - -public final class ForcedDiffuseState { - private static final ThreadLocal> FORCED_DIFFUSE = ThreadLocal.withInitial(ObjectArrayList::new); - - private ForcedDiffuseState() { - } - - public static void pushCalculator(DiffuseLightCalculator calculator) { - FORCED_DIFFUSE.get().push(calculator); - } - - public static void popCalculator() { - FORCED_DIFFUSE.get().pop(); - } - - @Nullable - public static DiffuseLightCalculator getForcedCalculator() { - ObjectArrayList stack = FORCED_DIFFUSE.get(); - if (stack.isEmpty()) { - return null; - } - return stack.top(); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/RenderTypes.java b/src/main/java/com/simibubi/create/foundation/render/RenderTypes.java index 5a18d8298..d0acb2cc3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/RenderTypes.java +++ b/src/main/java/com/simibubi/create/foundation/render/RenderTypes.java @@ -1,43 +1,104 @@ package com.simibubi.create.foundation.render; import java.io.IOException; +import java.util.function.BiFunction; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.VertexFormat; import com.simibubi.create.AllSpecialTextures; import com.simibubi.create.Create; +import net.minecraft.Util; import net.minecraft.client.renderer.RenderStateShard; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.ShaderInstance; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceProvider; -import net.minecraft.world.inventory.InventoryMenu; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RegisterShadersEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -// TODO 1.17: use custom shaders instead of vanilla ones public class RenderTypes extends RenderStateShard { - public static final RenderStateShard.ShaderStateShard GLOWING_SHADER = new RenderStateShard.ShaderStateShard(() -> Shaders.glowingShader); + private static final RenderType ENTITY_SOLID_BLOCK_MIPPED = RenderType.create(createLayerName("entity_solid_block_mipped"), + DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, false, + RenderType.CompositeState.builder() + .setShaderState(RENDERTYPE_ENTITY_SOLID_SHADER) + .setTextureState(BLOCK_SHEET_MIPPED) + .setTransparencyState(NO_TRANSPARENCY) + .setLightmapState(LIGHTMAP) + .setOverlayState(OVERLAY) + .createCompositeState(true)); + + private static final RenderType ENTITY_CUTOUT_BLOCK_MIPPED = RenderType.create(createLayerName("entity_cutout_block_mipped"), + DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, false, + RenderType.CompositeState.builder() + .setShaderState(RENDERTYPE_ENTITY_CUTOUT_SHADER) + .setTextureState(BLOCK_SHEET_MIPPED) + .setTransparencyState(NO_TRANSPARENCY) + .setLightmapState(LIGHTMAP) + .setOverlayState(OVERLAY) + .createCompositeState(true)); + + private static final RenderType ENTITY_TRANSLUCENT_BLOCK_MIPPED = RenderType.create(createLayerName("entity_translucent_block_mipped"), + DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, + RenderType.CompositeState.builder() + .setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER) + .setTextureState(BLOCK_SHEET_MIPPED) + .setTransparencyState(TRANSLUCENT_TRANSPARENCY) + .setLightmapState(LIGHTMAP) + .setOverlayState(OVERLAY) + .createCompositeState(true)); + + private static final RenderType ADDITIVE = RenderType.create(createLayerName("additive"), DefaultVertexFormat.BLOCK, + VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() + .setShaderState(RENDERTYPE_SOLID_SHADER) + .setTextureState(BLOCK_SHEET) + .setTransparencyState(ADDITIVE_TRANSPARENCY) + .setCullState(NO_CULL) + .setLightmapState(LIGHTMAP) + .setOverlayState(OVERLAY) + .createCompositeState(true)); + + private static final RenderType FLUID = RenderType.create(createLayerName("fluid"), + DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, false, true, RenderType.CompositeState.builder() + .setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER) + .setTextureState(BLOCK_SHEET_MIPPED) + .setCullState(NO_CULL) + .setTransparencyState(TRANSLUCENT_TRANSPARENCY) + .setLightmapState(LIGHTMAP) + .setOverlayState(OVERLAY) + .createCompositeState(true)); + + private static final RenderType ITEM_GLOWING_SOLID = RenderType.create(createLayerName("item_glowing_solid"), + DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, false, RenderType.CompositeState.builder() + .setShaderState(GLOWING_SHADER) + .setTextureState(BLOCK_SHEET) + .setLightmapState(LIGHTMAP) + .setOverlayState(OVERLAY) + .createCompositeState(true)); + + private static final RenderType ITEM_GLOWING_TRANSLUCENT = RenderType.create(createLayerName("item_glowing_translucent"), + DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() + .setShaderState(GLOWING_SHADER) + .setTextureState(BLOCK_SHEET) + .setTransparencyState(TRANSLUCENT_TRANSPARENCY) + .setLightmapState(LIGHTMAP) + .setOverlayState(OVERLAY) + .createCompositeState(true)); + private static final RenderType OUTLINE_SOLID = RenderType.create(createLayerName("outline_solid"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, false, false, RenderType.CompositeState.builder() .setShaderState(RENDERTYPE_ENTITY_SOLID_SHADER) .setTextureState(new RenderStateShard.TextureStateShard(AllSpecialTextures.BLANK.getLocation(), false, false)) - .setCullState(CULL) .setLightmapState(LIGHTMAP) .setOverlayState(OVERLAY) .createCompositeState(false)); - public static RenderType getOutlineSolid() { - return OUTLINE_SOLID; - } - - public static RenderType getOutlineTranslucent(ResourceLocation texture, boolean cull) { + private static final BiFunction OUTLINE_TRANSLUCENT = Util.memoize((texture, cull) -> { return RenderType.create(createLayerName("outline_translucent" + (cull ? "_cull" : "")), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, false, true, RenderType.CompositeState.builder() .setShaderState(cull ? RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER : RENDERTYPE_ENTITY_TRANSLUCENT_SHADER) @@ -48,96 +109,44 @@ public class RenderTypes extends RenderStateShard { .setOverlayState(OVERLAY) .setWriteMaskState(COLOR_WRITE) .createCompositeState(false)); + }); + + public static RenderType entitySolidBlockMipped() { + return ENTITY_SOLID_BLOCK_MIPPED; } - public static RenderType getGlowingSolid(ResourceLocation texture) { - return RenderType.create(createLayerName("glowing_solid"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, - true, false, RenderType.CompositeState.builder() - .setShaderState(GLOWING_SHADER) - .setTextureState(new RenderStateShard.TextureStateShard(texture, false, false)) - .setCullState(CULL) - .setLightmapState(LIGHTMAP) - .setOverlayState(OVERLAY) - .createCompositeState(true)); + public static RenderType entityCutoutBlockMipped() { + return ENTITY_CUTOUT_BLOCK_MIPPED; } - private static final RenderType GLOWING_SOLID_DEFAULT = getGlowingSolid(InventoryMenu.BLOCK_ATLAS); - - public static RenderType getGlowingSolid() { - return GLOWING_SOLID_DEFAULT; + public static RenderType entityTranslucentBlockMipped() { + return ENTITY_TRANSLUCENT_BLOCK_MIPPED; } - public static RenderType getGlowingTranslucent(ResourceLocation texture) { - return RenderType.create(createLayerName("glowing_translucent"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, - 256, true, true, RenderType.CompositeState.builder() - .setShaderState(GLOWING_SHADER) - .setTextureState(new RenderStateShard.TextureStateShard(texture, false, false)) - .setTransparencyState(TRANSLUCENT_TRANSPARENCY) - .setLightmapState(LIGHTMAP) - .setOverlayState(OVERLAY) - .createCompositeState(true)); - } - - private static final RenderType ADDITIVE = RenderType.create(createLayerName("additive"), DefaultVertexFormat.BLOCK, - VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() - .setShaderState(RENDERTYPE_SOLID_SHADER) - .setTextureState(new RenderStateShard.TextureStateShard(InventoryMenu.BLOCK_ATLAS, false, false)) - .setTransparencyState(ADDITIVE_TRANSPARENCY) - .setCullState(NO_CULL) - .setLightmapState(LIGHTMAP) - .setOverlayState(OVERLAY) - .createCompositeState(true)); - - public static RenderType getAdditive() { + public static RenderType additive() { return ADDITIVE; } - private static final RenderType GLOWING_TRANSLUCENT_DEFAULT = getGlowingTranslucent(InventoryMenu.BLOCK_ATLAS); - - public static RenderType getGlowingTranslucent() { - return GLOWING_TRANSLUCENT_DEFAULT; - } - - private static final RenderType ITEM_PARTIAL_SOLID = - RenderType.create(createLayerName("item_partial_solid"), DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, - false, RenderType.CompositeState.builder() - .setShaderState(RENDERTYPE_ENTITY_SOLID_SHADER) - .setTextureState(BLOCK_SHEET) - .setCullState(CULL) - .setLightmapState(LIGHTMAP) - .setOverlayState(OVERLAY) - .createCompositeState(true)); - - public static RenderType getItemPartialSolid() { - return ITEM_PARTIAL_SOLID; - } - - private static final RenderType ITEM_PARTIAL_TRANSLUCENT = RenderType.create(createLayerName("item_partial_translucent"), - DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, RenderType.CompositeState.builder() - .setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER) - .setTextureState(BLOCK_SHEET) - .setTransparencyState(TRANSLUCENT_TRANSPARENCY) - .setLightmapState(LIGHTMAP) - .setOverlayState(OVERLAY) - .createCompositeState(true)); - - public static RenderType getItemPartialTranslucent() { - return ITEM_PARTIAL_TRANSLUCENT; - } - - private static final RenderType FLUID = RenderType.create(createLayerName("fluid"), - DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, false, true, RenderType.CompositeState.builder() - .setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER) - .setTextureState(BLOCK_SHEET_MIPPED) - .setTransparencyState(TRANSLUCENT_TRANSPARENCY) - .setLightmapState(LIGHTMAP) - .setOverlayState(OVERLAY) - .createCompositeState(true)); - - public static RenderType getFluid() { + public static RenderType fluid() { return FLUID; } + public static RenderType itemGlowingSolid() { + return ITEM_GLOWING_SOLID; + } + + public static RenderType itemGlowingTranslucent() { + return ITEM_GLOWING_TRANSLUCENT; + } + + public static RenderType outlineSolid() { + return OUTLINE_SOLID; + } + + public static RenderType outlineTranslucent(ResourceLocation texture, boolean cull) { + return OUTLINE_TRANSLUCENT.apply(texture, cull); + } + private static String createLayerName(String name) { return Create.ID + ":" + name; } @@ -157,5 +166,4 @@ public class RenderTypes extends RenderStateShard { event.registerShader(new ShaderInstance(resourceProvider, Create.asResource("glowing_shader"), DefaultVertexFormat.NEW_ENTITY), shader -> glowingShader = shader); } } - } 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 c33d4a49b..6c61512ff 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBuffer.java @@ -1,29 +1,32 @@ package com.simibubi.create.foundation.render; +import org.jetbrains.annotations.Nullable; import org.joml.Matrix3f; import org.joml.Matrix4f; import org.joml.Quaternionf; import org.joml.Vector3f; +import org.joml.Vector3fc; import org.joml.Vector4f; -import dev.engine_room.flywheel.lib.transform.TransformStack; -import dev.engine_room.flywheel.lib.util.ShadersModHandler; -import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; +import com.simibubi.create.foundation.mixin.accessor.RenderSystemAccessor; import com.simibubi.create.foundation.utility.Color; +import dev.engine_room.flywheel.lib.transform.TransformStack; +import dev.engine_room.flywheel.lib.util.ShadersModHandler; import it.unimi.dsi.fastutil.longs.Long2IntMap; import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; +import net.minecraft.world.level.BlockAndTintGetter; public class SuperByteBuffer implements TransformStack { + private static final Long2IntMap WORLD_LIGHT_CACHE = new Long2IntOpenHashMap(); + private final TemplateMesh template; private final int[] shadeSwapVertices; @@ -31,32 +34,40 @@ public class SuperByteBuffer implements TransformStack { private final PoseStack transforms = new PoseStack(); // Vertex Coloring - private boolean shouldColor; private float r, g, b, a; - private boolean disableDiffuseMult; - private DiffuseLightCalculator diffuseCalculator; + private boolean disableDiffuse; // Vertex Texture Coords + @Nullable private SpriteShiftFunc spriteShiftFunc; - // Vertex Overlay Color - private int overlay = OverlayTexture.NO_OVERLAY; + // Vertex Overlay + private boolean hasCustomOverlay; + private int overlay; - // Vertex Lighting - private boolean useWorldLight; - private Matrix4f lightTransform; + // Vertex Light private boolean hasCustomLight; - private int packedLightCoords; - private boolean hybridLight; + private int packedLight; + private boolean useLevelLight; + @Nullable + private BlockAndTintGetter levelWithLight; + @Nullable + private Matrix4f lightTransform; - // Temporary - private static final Long2IntMap WORLD_LIGHT_CACHE = new Long2IntOpenHashMap(); + // Reused objects + private final Matrix4f modelMat = new Matrix4f(); + private final Matrix3f normalMat = new Matrix3f(); + private final Vector4f pos = new Vector4f(); + private final Vector3f normal = new Vector3f(); + private final Vector3f lightDir0 = new Vector3f(); + private final Vector3f lightDir1 = new Vector3f(); + private final ShiftOutput shiftOutput = new ShiftOutput(); + private final Vector4f lightPos = new Vector4f(); public SuperByteBuffer(TemplateMesh template, int[] shadeSwapVertices) { this.template = template; this.shadeSwapVertices = shadeSwapVertices; - - transforms.pushPose(); + reset(); } public SuperByteBuffer(TemplateMesh template) { @@ -64,56 +75,49 @@ public class SuperByteBuffer implements TransformStack { } public void renderInto(PoseStack input, VertexConsumer builder) { - if (isEmpty()) + if (isEmpty()) { return; + } - Matrix4f modelMat = new Matrix4f(input.last() + if (useLevelLight) { + WORLD_LIGHT_CACHE.clear(); + } + + Matrix4f modelMat = this.modelMat.set(input.last() .pose()); Matrix4f localTransforms = transforms.last() .pose(); modelMat.mul(localTransforms); - Matrix3f normalMat = new Matrix3f(input.last() + Matrix3f normalMat = this.normalMat.set(input.last() .normal()); Matrix3f localNormalTransforms = transforms.last() .normal(); normalMat.mul(localNormalTransforms); - if (useWorldLight) { - WORLD_LIGHT_CACHE.clear(); - } - - class ShiftOutput implements SpriteShiftFunc.Output { - public float u; - public float v; - - @Override - public void accept(float u, float v) { - this.u = u; - this.v = v; - } - }; - - final Vector4f pos = new Vector4f(); - final Vector3f normal = new Vector3f(); - final ShiftOutput shiftOutput = new ShiftOutput(); - final Vector4f lightPos = new Vector4f(); - - DiffuseLightCalculator diffuseCalculator = ForcedDiffuseState.getForcedCalculator(); - final boolean disableDiffuseMult = - this.disableDiffuseMult || (ShadersModHandler.isShaderPackInUse() && diffuseCalculator == null); - if (diffuseCalculator == null) { - diffuseCalculator = this.diffuseCalculator; - if (diffuseCalculator == null) { - diffuseCalculator = DiffuseLightCalculator.forLevel(Minecraft.getInstance().level); - } - } + Vector4f pos = this.pos; + Vector3f normal = this.normal; + ShiftOutput shiftOutput = this.shiftOutput; + Vector3f lightDir0 = this.lightDir0; + Vector3f lightDir1 = this.lightDir1; + Vector4f lightPos = this.lightPos; + boolean applyDiffuse = !disableDiffuse && !ShadersModHandler.isShaderPackInUse(); boolean shaded = true; int shadeSwapIndex = 0; int nextShadeSwapVertex = shadeSwapIndex < shadeSwapVertices.length ? shadeSwapVertices[shadeSwapIndex] : -1; + float unshadedDiffuse = 1; + if (applyDiffuse) { + lightDir0.set(RenderSystemAccessor.create$getShaderLightDirections()[0]).normalize(); + lightDir1.set(RenderSystemAccessor.create$getShaderLightDirections()[1]).normalize(); + if (shadeSwapVertices.length > 0) { + normal.set(0, 1, 0); + normal.mul(normalMat); + unshadedDiffuse = calculateDiffuse(normal, lightDir0, lightDir1); + } + } - final int vertexCount = template.vertexCount(); + int vertexCount = template.vertexCount(); for (int i = 0; i < vertexCount; i++) { if (i == nextShadeSwapVertex) { shaded = !shaded; @@ -133,27 +137,14 @@ public class SuperByteBuffer implements TransformStack { float normalZ = ((byte) ((packedNormal >>> 16) & 0xFF)) / 127.0f; normal.set(normalX, normalY, normalZ); normal.mul(normalMat); - normalX = normal.x(); - normalY = normal.y(); - normalZ = normal.z(); - float r, g, b, a; - if (shouldColor) { - r = this.r; - g = this.g; - b = this.b; - a = this.a; - } else { - int color = template.color(i); - r = (color & 0xFF) / 255.0f; - g = ((color >>> 8) & 0xFF) / 255.0f; - b = ((color >>> 16) & 0xFF) / 255.0f; - a = ((color >>> 24) & 0xFF) / 255.0f; - } - if (!disableDiffuseMult) { - // Transformed normal is in camera space, but it is needed in world space to calculate diffuse. - normal.mul(RenderSystem.getInverseViewRotationMatrix()); - float diffuse = diffuseCalculator.getDiffuse(normal.x(), normal.y(), normal.z(), shaded); + int color = template.color(i); + float r = (color & 0xFF) / 255.0f * this.r; + float g = ((color >>> 8) & 0xFF) / 255.0f * this.g; + float b = ((color >>> 16) & 0xFF) / 255.0f * this.b; + float a = ((color >>> 24) & 0xFF) / 255.0f * this.a; + if (applyDiffuse) { + float diffuse = shaded ? calculateDiffuse(normal, lightDir0, lightDir1) : unshadedDiffuse; r *= diffuse; g *= diffuse; b *= diffuse; @@ -167,28 +158,27 @@ public class SuperByteBuffer implements TransformStack { v = shiftOutput.v; } - int light; - if (useWorldLight) { + int overlay; + if (hasCustomOverlay) { + overlay = this.overlay; + } else { + overlay = template.overlay(i); + } + + int light = template.light(i); + if (hasCustomLight) { + light = maxLight(light, packedLight); + } + if (useLevelLight) { lightPos.set(((x - .5f) * 15 / 16f) + .5f, (y - .5f) * 15 / 16f + .5f, (z - .5f) * 15 / 16f + .5f, 1f); lightPos.mul(localTransforms); if (lightTransform != null) { lightPos.mul(lightTransform); } - - light = getLight(Minecraft.getInstance().level, lightPos); - if (hasCustomLight) { - light = maxLight(light, packedLightCoords); - } - } else if (hasCustomLight) { - light = packedLightCoords; - } else { - light = template.light(i); - } - if (hybridLight) { - light = maxLight(light, template.light(i)); + light = maxLight(light, getLight(levelWithLight, lightPos)); } - builder.vertex(pos.x(), pos.y(), pos.z(), r, g, b, a, u, v, overlay, light, normalX, normalY, normalZ); + builder.vertex(pos.x(), pos.y(), pos.z(), r, g, b, a, u, v, overlay, light, normal.x(), normal.y(), normal.z()); } reset(); @@ -199,20 +189,19 @@ public class SuperByteBuffer implements TransformStack { transforms.popPose(); transforms.pushPose(); - shouldColor = false; - r = 0; - g = 0; - b = 0; - a = 0; - disableDiffuseMult = false; - diffuseCalculator = null; + r = 1; + g = 1; + b = 1; + a = 1; + disableDiffuse = false; spriteShiftFunc = null; + hasCustomOverlay = false; overlay = OverlayTexture.NO_OVERLAY; - useWorldLight = false; - lightTransform = null; hasCustomLight = false; - packedLightCoords = 0; - hybridLight = false; + packedLight = 0; + useLevelLight = false; + levelWithLight = null; + lightTransform = null; return this; } @@ -271,7 +260,6 @@ public class SuperByteBuffer implements TransformStack { } public SuperByteBuffer color(float r, float g, float b, float a) { - shouldColor = true; this.r = r; this.g = g; this.b = b; @@ -293,18 +281,8 @@ public class SuperByteBuffer implements TransformStack { return color(c.getRGB()); } - /** - * Prevents vertex colors from being multiplied by the diffuse value calculated - * from the final transformed normal vector. Useful for entity rendering, when - * diffuse is applied automatically later. - */ public SuperByteBuffer disableDiffuse() { - disableDiffuseMult = true; - return this; - } - - public SuperByteBuffer diffuseCalculator(DiffuseLightCalculator diffuseCalculator) { - this.diffuseCalculator = diffuseCalculator; + disableDiffuse = true; return this; } @@ -346,40 +324,27 @@ public class SuperByteBuffer implements TransformStack { } public SuperByteBuffer overlay(int overlay) { + hasCustomOverlay = true; this.overlay = overlay; return this; } - public SuperByteBuffer light() { - useWorldLight = true; - return this; - } - - public SuperByteBuffer light(Matrix4f lightTransform) { - useWorldLight = true; - this.lightTransform = lightTransform; - return this; - } - - public SuperByteBuffer light(int packedLightCoords) { + public SuperByteBuffer light(int packedLight) { hasCustomLight = true; - this.packedLightCoords = packedLightCoords; + this.packedLight = packedLight; return this; } - public SuperByteBuffer light(Matrix4f lightTransform, int packedLightCoords) { - light(lightTransform); - light(packedLightCoords); + public SuperByteBuffer useLevelLight(BlockAndTintGetter level) { + useLevelLight = true; + levelWithLight = level; return this; } - /** - * Uses max light from calculated light (world light or custom light) and vertex - * light for the final light value. Ineffective if any other light method was - * not called. - */ - public SuperByteBuffer hybridLight() { - hybridLight = true; + public SuperByteBuffer useLevelLight(BlockAndTintGetter level, Matrix4f lightTransform) { + useLevelLight = true; + levelWithLight = level; + this.lightTransform = lightTransform; return this; } @@ -391,7 +356,14 @@ public class SuperByteBuffer implements TransformStack { return LightTexture.pack(Math.max(blockLight1, blockLight2), Math.max(skyLight1, skyLight2)); } - private static int getLight(Level world, Vector4f lightPos) { + // Adapted from minecraft:shaders/include/light.glsl + private static float calculateDiffuse(Vector3fc normal, Vector3fc lightDir0, Vector3fc lightDir1) { + float light0 = Math.max(0.0f, lightDir0.dot(normal)); + float light1 = Math.max(0.0f, lightDir1.dot(normal)); + return Math.min(1.0f, (light0 + light1) * 0.6f + 0.4f); + } + + private static int getLight(BlockAndTintGetter world, Vector4f lightPos) { BlockPos pos = BlockPos.containing(lightPos.x(), lightPos.y(), lightPos.z()); return WORLD_LIGHT_CACHE.computeIfAbsent(pos.asLong(), $ -> LevelRenderer.getLightColor(world, pos)); } @@ -405,8 +377,14 @@ public class SuperByteBuffer implements TransformStack { } } - @FunctionalInterface - public interface VertexLighter { - int getPackedLight(float x, float y, float z); - } + private class ShiftOutput implements SpriteShiftFunc.Output { + public float u; + public float v; + + @Override + public void accept(float u, float v) { + this.u = u; + this.v = v; + } + }; } diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperRenderTypeBuffer.java b/src/main/java/com/simibubi/create/foundation/render/SuperRenderTypeBuffer.java index 57716c382..0933e1c4e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperRenderTypeBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperRenderTypeBuffer.java @@ -79,10 +79,12 @@ public class SuperRenderTypeBuffer implements MultiBufferSource { put(map, RenderType.entityGlint()); put(map, RenderType.entityGlintDirect()); put(map, RenderType.waterMask()); - put(map, RenderTypes.getOutlineSolid()); ModelBakery.DESTROY_TYPES.forEach((p_173062_) -> { put(map, p_173062_); }); + + // extras + put(map, RenderTypes.outlineSolid()); }); private final MultiBufferSource.BufferSource bufferSource = MultiBufferSource.immediateWithBuffers(fixedBuffers, new BufferBuilder(256)); diff --git a/src/main/java/com/simibubi/create/foundation/render/VirtualRenderHelper.java b/src/main/java/com/simibubi/create/foundation/render/VirtualRenderHelper.java index 8bbf0dbc0..7b2cb55a7 100644 --- a/src/main/java/com/simibubi/create/foundation/render/VirtualRenderHelper.java +++ b/src/main/java/com/simibubi/create/foundation/render/VirtualRenderHelper.java @@ -62,9 +62,9 @@ public class VirtualRenderHelper { ShadedBlockSbbBuilder sbbBuilder = objects.sbbBuilder; sbbBuilder.begin(); - ModelData modelData = model.getModelData(VirtualEmptyBlockGetter.INSTANCE, BlockPos.ZERO, state, VIRTUAL_DATA); + ModelData modelData = model.getModelData(VirtualEmptyBlockGetter.FULL_DARK, BlockPos.ZERO, state, VIRTUAL_DATA); poseStack.pushPose(); - renderer.tesselateBlock(VirtualEmptyBlockGetter.INSTANCE, model, state, BlockPos.ZERO, poseStack, sbbBuilder, false, random, 42L, OverlayTexture.NO_OVERLAY, modelData, null); + renderer.tesselateBlock(VirtualEmptyBlockGetter.FULL_DARK, model, state, BlockPos.ZERO, poseStack, sbbBuilder, false, random, 42L, OverlayTexture.NO_OVERLAY, modelData, null); poseStack.popPose(); return sbbBuilder.end(); diff --git a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java index adc9a825c..0e8cd5dda 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java +++ b/src/main/java/com/simibubi/create/foundation/utility/outliner/Outline.java @@ -60,7 +60,7 @@ public abstract class Outline { if (lineWidth == 0) return; - VertexConsumer builder = buffer.getBuffer(RenderTypes.getOutlineSolid()); + VertexConsumer builder = buffer.getBuffer(RenderTypes.outlineSolid()); Vec3 diff = end.subtract(start); if (diff.x + diff.y + diff.z < 0) { diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 8bfa48c30..dbea82de4 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -31,6 +31,7 @@ "accessor.GameRendererAccessor", "accessor.HumanoidArmorLayerAccessor", "accessor.ParticleEngineAccessor", + "accessor.RenderSystemAccessor", "client.BlockDestructionProgressMixin", "client.CameraMixin", "client.EntityContraptionInteractionMixin",