Better bogey brightness

- Deduplicate bogey translation code
This commit is contained in:
Jozufozu 2022-04-03 15:08:14 -07:00
parent 9ca26d674c
commit 9c8439fe08
3 changed files with 57 additions and 32 deletions

View file

@ -1,9 +1,12 @@
package com.simibubi.create.content.logistics.trains.entity; package com.simibubi.create.content.logistics.trains.entity;
import org.jetbrains.annotations.Nullable;
import com.jozufozu.flywheel.api.Material; import com.jozufozu.flywheel.api.Material;
import com.jozufozu.flywheel.api.MaterialManager; import com.jozufozu.flywheel.api.MaterialManager;
import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
@ -12,7 +15,11 @@ import com.simibubi.create.foundation.render.CachedBufferer;
import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.phys.Vec3;
public sealed class BogeyInstance { public sealed class BogeyInstance {
@ -47,6 +54,20 @@ public sealed class BogeyInstance {
.unCentre(); .unCentre();
} }
public void updateLight(BlockAndTintGetter world, CarriageContraptionEntity entity) {
var lightPos = new BlockPos(getLightPos(entity));
updateLight(world.getBrightness(LightLayer.BLOCK, lightPos), world.getBrightness(LightLayer.SKY, lightPos));
}
private Vec3 getLightPos(CarriageContraptionEntity entity) {
if (bogey.getAnchorPosition() != null) {
return bogey.getAnchorPosition();
} else {
return entity.getLightProbePosition(AnimationTickHolder.getPartialTicks());
}
}
public void updateLight(int blockLight, int skyLight) { public void updateLight(int blockLight, int skyLight) {
for (ModelData shaft : shafts) { for (ModelData shaft : shafts) {
shaft.setBlockLight(blockLight).setSkyLight(skyLight); shaft.setBlockLight(blockLight).setSkyLight(skyLight);

View file

@ -1,13 +1,18 @@
package com.simibubi.create.content.logistics.trains.entity; package com.simibubi.create.content.logistics.trains.entity;
import java.util.Objects;
import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.util.transform.TransformStack; import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionEntityRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.culling.Frustum; import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer<CarriageContraptionEntity> { public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer<CarriageContraptionEntity> {
@ -34,24 +39,41 @@ public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer
MultiBufferSource buffers, int overlay) { MultiBufferSource buffers, int overlay) {
super.render(entity, yaw, partialTicks, ms, buffers, overlay); super.render(entity, yaw, partialTicks, ms, buffers, overlay);
if (Backend.isOn()) return;
Carriage carriage = entity.getCarriage(); Carriage carriage = entity.getCarriage();
if (carriage == null) if (carriage == null)
return; return;
boolean usingFlywheel = Backend.isOn();
Vec3 position = entity.getPosition(partialTicks); Vec3 position = entity.getPosition(partialTicks);
ms.pushPose(); float viewYRot = entity.getViewYRot(partialTicks);
float viewXRot = entity.getViewXRot(partialTicks);
int bogeySpacing = carriage.bogeySpacing;
carriage.bogeys.forEach(bogey -> { carriage.bogeys.forEach(bogey -> {
if (bogey == null) if (bogey == null)
return; return;
ms.pushPose(); if (!usingFlywheel) {
float viewYRot = entity.getViewYRot(partialTicks); ms.pushPose();
float viewXRot = entity.getViewXRot(partialTicks); translateBogey(ms, bogey, bogeySpacing, viewYRot, viewXRot, partialTicks);
int bogeySpacing = carriage.bogeySpacing;
TransformStack.cast(ms) int light = getBogeyLightCoords(entity, bogey, partialTicks);
bogey.type.render(null, bogey.wheelAngle.getValue(partialTicks), ms, partialTicks, buffers, light, overlay);
ms.popPose();
}
bogey.updateCouplingAnchor(position, viewXRot, viewYRot, bogeySpacing, partialTicks, bogey.isLeading);
if (!carriage.isOnTwoBogeys())
bogey.updateCouplingAnchor(position, viewXRot, viewYRot, bogeySpacing, partialTicks, !bogey.isLeading);
});
}
public static void translateBogey(PoseStack ms, CarriageBogey bogey, int bogeySpacing, float viewYRot, float viewXRot, float partialTicks) {
TransformStack.cast(ms)
.rotateY(viewYRot + 90) .rotateY(viewYRot + 90)
.rotateX(-viewXRot) .rotateX(-viewXRot)
.rotateY(180) .rotateY(180)
@ -62,17 +84,13 @@ public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer
.rotateY(bogey.yaw.getValue(partialTicks)) .rotateY(bogey.yaw.getValue(partialTicks))
.rotateX(bogey.pitch.getValue(partialTicks)) .rotateX(bogey.pitch.getValue(partialTicks))
.translate(0, .5f, 0); .translate(0, .5f, 0);
}
bogey.type.render(null, bogey.wheelAngle.getValue(partialTicks), ms, partialTicks, buffers, public static int getBogeyLightCoords(CarriageContraptionEntity entity, CarriageBogey bogey, float partialTicks) {
getPackedLightCoords(entity, partialTicks), overlay);
bogey.updateCouplingAnchor(position, viewXRot, viewYRot, bogeySpacing, partialTicks, bogey.isLeading);
if (!carriage.isOnTwoBogeys())
bogey.updateCouplingAnchor(position, viewXRot, viewYRot, bogeySpacing, partialTicks, !bogey.isLeading);
ms.popPose(); var lightPos = new BlockPos(Objects.requireNonNullElseGet(bogey.getAnchorPosition(), () -> entity.getLightProbePosition(partialTicks)));
});
ms.popPose();
return LightTexture.pack(entity.level.getBrightness(LightLayer.BLOCK, lightPos), entity.level.getBrightness(LightLayer.SKY, lightPos));
} }
} }

View file

@ -58,17 +58,7 @@ public class CarriageContraptionInstance extends EntityInstance<CarriageContrapt
ms.pushPose(); ms.pushPose();
CarriageBogey bogey = instance.bogey; CarriageBogey bogey = instance.bogey;
TransformStack.cast(ms) CarriageContraptionEntityRenderer.translateBogey(ms, bogey, bogeySpacing, viewYRot, viewXRot, partialTicks);
.rotateY(viewYRot + 90)
.rotateX(-viewXRot)
.rotateY(180)
.translate(0, 0, bogey.isLeading ? 0 : -bogeySpacing)
.rotateY(-180)
.rotateX(viewXRot)
.rotateY(-viewYRot - 90)
.rotateY(bogey.yaw.getValue(partialTicks))
.rotateX(bogey.pitch.getValue(partialTicks))
.translate(0, .5f, 0);
instance.beginFrame(bogey.wheelAngle.getValue(partialTicks), ms); instance.beginFrame(bogey.wheelAngle.getValue(partialTicks), ms);
ms.popPose(); ms.popPose();
@ -82,13 +72,9 @@ public class CarriageContraptionInstance extends EntityInstance<CarriageContrapt
public void updateLight() { public void updateLight() {
if (bogeys == null) return; if (bogeys == null) return;
var pos = new BlockPos(entity.getLightProbePosition(AnimationTickHolder.getPartialTicks()));
int block = world.getBrightness(LightLayer.BLOCK, pos);
int sky = world.getBrightness(LightLayer.SKY, pos);
bogeys.forEach(instance -> { bogeys.forEach(instance -> {
if (instance != null) if (instance != null)
instance.updateLight(block, sky); instance.updateLight(world, entity);
}); });
} }