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;
import org.jetbrains.annotations.Nullable;
import com.jozufozu.flywheel.api.Material;
import com.jozufozu.flywheel.api.MaterialManager;
import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.AllBlockPartials;
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.Iterate;
import net.minecraft.core.BlockPos;
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 {
@ -47,6 +54,20 @@ public sealed class BogeyInstance {
.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) {
for (ModelData shaft : shafts) {
shaft.setBlockLight(blockLight).setSkyLight(skyLight);

View file

@ -1,13 +1,18 @@
package com.simibubi.create.content.logistics.trains.entity;
import java.util.Objects;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
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.culling.Frustum;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.phys.Vec3;
public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer<CarriageContraptionEntity> {
@ -34,24 +39,41 @@ public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer
MultiBufferSource buffers, int overlay) {
super.render(entity, yaw, partialTicks, ms, buffers, overlay);
if (Backend.isOn()) return;
Carriage carriage = entity.getCarriage();
if (carriage == null)
return;
boolean usingFlywheel = Backend.isOn();
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 -> {
if (bogey == null)
return;
ms.pushPose();
float viewYRot = entity.getViewYRot(partialTicks);
float viewXRot = entity.getViewXRot(partialTicks);
int bogeySpacing = carriage.bogeySpacing;
TransformStack.cast(ms)
if (!usingFlywheel) {
ms.pushPose();
translateBogey(ms, bogey, bogeySpacing, viewYRot, viewXRot, partialTicks);
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)
.rotateX(-viewXRot)
.rotateY(180)
@ -62,17 +84,13 @@ public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer
.rotateY(bogey.yaw.getValue(partialTicks))
.rotateX(bogey.pitch.getValue(partialTicks))
.translate(0, .5f, 0);
}
bogey.type.render(null, bogey.wheelAngle.getValue(partialTicks), ms, partialTicks, buffers,
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);
public static int getBogeyLightCoords(CarriageContraptionEntity entity, CarriageBogey bogey, float partialTicks) {
ms.popPose();
});
ms.popPose();
var lightPos = new BlockPos(Objects.requireNonNullElseGet(bogey.getAnchorPosition(), () -> entity.getLightProbePosition(partialTicks)));
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();
CarriageBogey bogey = instance.bogey;
TransformStack.cast(ms)
.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);
CarriageContraptionEntityRenderer.translateBogey(ms, bogey, bogeySpacing, viewYRot, viewXRot, partialTicks);
instance.beginFrame(bogey.wheelAngle.getValue(partialTicks), ms);
ms.popPose();
@ -82,13 +72,9 @@ public class CarriageContraptionInstance extends EntityInstance<CarriageContrapt
public void updateLight() {
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 -> {
if (instance != null)
instance.updateLight(block, sky);
instance.updateLight(world, entity);
});
}