diff --git a/gradle.properties b/gradle.properties index 5c5f59c11..05d998f8b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ parchment_version = 2022.03.13 # dependency versions registrate_version = MC1.18.2-1.0.24 -flywheel_version = 1.18-0.6.2.64 +flywheel_version = 1.18-0.6.2.65 jei_minecraft_version = 1.18.2 jei_version = 9.5.3.143 diff --git a/src/main/java/com/simibubi/create/AllEntityTypes.java b/src/main/java/com/simibubi/create/AllEntityTypes.java index 05c266307..195d6e554 100644 --- a/src/main/java/com/simibubi/create/AllEntityTypes.java +++ b/src/main/java/com/simibubi/create/AllEntityTypes.java @@ -16,8 +16,10 @@ import com.simibubi.create.content.curiosities.weapons.PotatoProjectileEntity; import com.simibubi.create.content.curiosities.weapons.PotatoProjectileRenderer; import com.simibubi.create.content.logistics.trains.entity.CarriageContraptionEntity; import com.simibubi.create.content.logistics.trains.entity.CarriageContraptionEntityRenderer; +import com.simibubi.create.content.logistics.trains.entity.CarriageContraptionInstance; import com.simibubi.create.foundation.data.CreateEntityBuilder; import com.simibubi.create.foundation.utility.Lang; +import com.tterrag.registrate.builders.EntityBuilder; import com.tterrag.registrate.util.entry.EntityEntry; import com.tterrag.registrate.util.nullness.NonNullConsumer; import com.tterrag.registrate.util.nullness.NonNullFunction; @@ -33,15 +35,20 @@ import net.minecraft.world.entity.MobCategory; public class AllEntityTypes { public static final EntityEntry ORIENTED_CONTRAPTION = contraption("contraption", - OrientedContraptionEntity::new, () -> OrientedContraptionEntityRenderer::new, 5, 3, true); + OrientedContraptionEntity::new, () -> OrientedContraptionEntityRenderer::new, 5, 3, true) + .register(); public static final EntityEntry CONTROLLED_CONTRAPTION = contraption("stationary_contraption", ControlledContraptionEntity::new, () -> ContraptionEntityRenderer::new, - 20, 40, false); + 20, 40, false) + .register(); public static final EntityEntry GANTRY_CONTRAPTION = contraption("gantry_contraption", - GantryContraptionEntity::new, () -> ContraptionEntityRenderer::new, 10, 40, false); + GantryContraptionEntity::new, () -> ContraptionEntityRenderer::new, 10, 40, false) + .register(); public static final EntityEntry CARRIAGE_CONTRAPTION = contraption("carriage_contraption", CarriageContraptionEntity::new, - () -> CarriageContraptionEntityRenderer::new, 15, 3, true); + () -> CarriageContraptionEntityRenderer::new, 15, 3, true) + .instance(() -> CarriageContraptionInstance::new) + .register(); public static final EntityEntry SUPER_GLUE = register("super_glue", SuperGlueEntity::new, () -> SuperGlueRenderer::new, MobCategory.MISC, 10, @@ -61,11 +68,11 @@ public class AllEntityTypes { // - private static EntityEntry contraption(String name, EntityFactory factory, + private static CreateEntityBuilder contraption(String name, EntityFactory factory, NonNullSupplier>> renderer, int range, int updateFrequency, boolean sendVelocity) { return register(name, factory, renderer, MobCategory.MISC, range, updateFrequency, sendVelocity, true, - AbstractContraptionEntity::build).register(); + AbstractContraptionEntity::build); } private static CreateEntityBuilder register(String name, EntityFactory factory, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java index f55daf85c..6e86565a1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java @@ -24,7 +24,7 @@ public abstract class ContraptionLighter implements Light lightUpdater = LightUpdater.get(contraption.entity.level); bounds = getContraptionBounds(); - growBoundsForEdgeData(); + growBoundsForEdgeData(bounds); lightVolume = new GPULightVolume(bounds); @@ -51,7 +51,7 @@ public abstract class ContraptionLighter implements Light lightVolume.onLightPacket(world, chunkX, chunkZ); } - protected void growBoundsForEdgeData() { + protected static void growBoundsForEdgeData(GridAlignedBB bounds) { // so we have at least enough data on the edges to avoid artifacts and have smooth lighting bounds.grow(2); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java index 1249efaa8..af146da53 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/NonStationaryLighter.java @@ -18,11 +18,11 @@ public class NonStationaryLighter extends ContraptionLigh ImmutableBox contraptionBounds = getContraptionBounds(); - if (bounds.sameAs(contraptionBounds)) { + if (bounds.sameAs(contraptionBounds, 2)) { return false; } bounds.assign(contraptionBounds); - growBoundsForEdgeData(); + growBoundsForEdgeData(bounds); lightVolume.move(provider, bounds); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java index c52a7d882..a51193ecd 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionGroup.java @@ -16,7 +16,7 @@ public class ContraptionGroup

extends InstancedMat } @Override - public void setup(P program) { + protected void setup(P program) { contraption.setup(program); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraption.java index 01cbb7d95..969f2adef 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraption.java @@ -182,7 +182,7 @@ public class FlwContraption extends ContraptionRenderInfo { private final ContraptionInstanceManager tileInstanceManager; public ContraptionInstanceWorld(FlwContraption parent) { - switch (Backend.getEngine()) { + switch (Backend.getBackendType()) { case INSTANCING -> { InstancingEngine engine = InstancingEngine.builder(CreateContexts.CWORLD) .setGroupFactory(ContraptionGroup.forContraption(parent)) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java index 4b68fd1a8..2f0b5d64d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java @@ -7,7 +7,7 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.RenderLayer; import com.jozufozu.flywheel.backend.gl.GlStateTracker; import com.jozufozu.flywheel.backend.gl.GlTextureUnit; -import com.jozufozu.flywheel.config.FlwEngine; +import com.jozufozu.flywheel.config.BackendType; import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.compile.ProgramContext; @@ -43,7 +43,7 @@ public class FlwContraptionManager extends ContraptionRenderingWorld mat = materialManager.defaultSolid() + .material(Materials.TRANSFORMED); + + secondShaft = new ModelData[2]; + + mat.getModel(AllBlocks.SHAFT.getDefaultState() + .setValue(ShaftBlock.AXIS, Direction.Axis.X)) + .createInstances(secondShaft); + + drive = mat.getModel(AllBlockPartials.BOGEY_DRIVE) + .createInstance(); + piston = mat.getModel(AllBlockPartials.BOGEY_PISTON) + .createInstance(); + wheels = mat.getModel(AllBlockPartials.LARGE_BOGEY_WHEELS) + .createInstance(); + pin = mat.getModel(AllBlockPartials.BOGEY_PIN) + .createInstance(); + } + + @Override + public void beginFrame(float wheelAngle, PoseStack ms) { + super.beginFrame(wheelAngle, ms); + + for (int i : Iterate.zeroAndOne) + secondShaft[i].setTransform(ms) + .translate(-.5f, .25f, .5f + i * -2) + .centre() + .rotateX(wheelAngle) + .unCentre(); + + drive.setTransform(ms); + piston.setTransform(ms) + .translate(0, 0, 1 / 4f * Math.sin(AngleHelper.rad(wheelAngle))); + + wheels.setTransform(ms) + .translate(0, 1, 0) + .rotateX(wheelAngle); + pin.setTransform(ms) + .translate(0, 1, 0) + .rotateX(wheelAngle) + .translate(0, 1 / 4f, 0) + .rotateX(-wheelAngle); + } + + @Override + public void updateLight(int blockLight, int skyLight) { + super.updateLight(blockLight, skyLight); + for (ModelData shaft : secondShaft) + shaft.setBlockLight(blockLight).setSkyLight(skyLight); + drive.setBlockLight(blockLight).setSkyLight(skyLight); + piston.setBlockLight(blockLight).setSkyLight(skyLight); + wheels.setBlockLight(blockLight).setSkyLight(skyLight); + pin.setBlockLight(blockLight).setSkyLight(skyLight); + } + + @Override + public void remove() { + super.remove(); + for (ModelData shaft : secondShaft) + shaft.delete(); + drive.delete(); + piston.delete(); + wheels.delete(); + pin.delete(); + } + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java index 7249026b0..128041bb5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java @@ -63,6 +63,7 @@ public class Carriage { updateContraptionAnchors(); + bogey1.setLeading(); bogey1.carriage = this; if (bogey2 != null) bogey2.carriage = this; diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageBogey.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageBogey.java index 10b5ab3f1..dd1285718 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageBogey.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageBogey.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.logistics.trains.entity; import javax.annotation.Nullable; +import com.jozufozu.flywheel.api.MaterialManager; import com.simibubi.create.Create; import com.simibubi.create.content.logistics.trains.IBogeyBlock; import com.simibubi.create.content.logistics.trains.TrackGraph; @@ -24,6 +25,8 @@ public class CarriageBogey { public Carriage carriage; + boolean isLeading; + IBogeyBlock type; Couple points; @@ -133,4 +136,11 @@ public class CarriageBogey { return carriageBogey; } -} \ No newline at end of file + public BogeyInstance createInstance(MaterialManager materialManager) { + return type.createInstance(materialManager, this); + } + + void setLeading() { + isLeading = true; + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageContraptionEntityRenderer.java index 2c6d81801..28c625ab0 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageContraptionEntityRenderer.java @@ -1,12 +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 { @@ -39,37 +45,50 @@ public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer Vec3 position = entity.getPosition(partialTicks); - ms.pushPose(); - carriage.bogeys.forEachWithContext((bogey, first) -> { - if (!first && !carriage.isOnTwoBogeys()) + 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 (!Backend.isOn()) { + 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) - .translate(0, 0, first ? 0 : -bogeySpacing) + .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); + } - bogey.type.render(null, bogey.wheelAngle.getValue(partialTicks), ms, partialTicks, buffers, - getPackedLightCoords(entity, partialTicks), overlay); - bogey.updateCouplingAnchor(position, viewXRot, viewYRot, bogeySpacing, partialTicks, first); - if (!carriage.isOnTwoBogeys()) - bogey.updateCouplingAnchor(position, viewXRot, viewYRot, bogeySpacing, partialTicks, !first); + 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)); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageContraptionInstance.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageContraptionInstance.java new file mode 100644 index 000000000..eeb25566d --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageContraptionInstance.java @@ -0,0 +1,82 @@ +package com.simibubi.create.content.logistics.trains.entity; + +import com.jozufozu.flywheel.api.MaterialManager; +import com.jozufozu.flywheel.api.instance.DynamicInstance; +import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; +import com.jozufozu.flywheel.util.AnimationTickHolder; +import com.jozufozu.flywheel.util.transform.TransformStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.simibubi.create.foundation.utility.Couple; + +public class CarriageContraptionInstance extends EntityInstance implements DynamicInstance { + + private final PoseStack ms = new PoseStack(); + + private Carriage carriage; + private Couple bogeys; + + public CarriageContraptionInstance(MaterialManager materialManager, CarriageContraptionEntity entity) { + super(materialManager, entity); + } + + @Override + public void init() { + carriage = entity.getCarriage(); + + if (carriage == null) return; + + bogeys = carriage.bogeys.mapNotNullWithParam(CarriageBogey::createInstance, materialManager); + updateLight(); + } + + @Override + public void beginFrame() { + if (bogeys == null) { + init(); + return; + } + + float partialTicks = AnimationTickHolder.getPartialTicks(); + + float viewYRot = entity.getViewYRot(partialTicks); + float viewXRot = entity.getViewXRot(partialTicks); + int bogeySpacing = carriage.bogeySpacing; + + ms.pushPose(); + + TransformStack.cast(ms) + .translate(getInstancePosition(partialTicks)) + .translate(0, -1.5 - 1 / 128f, 0);; + + for (BogeyInstance instance : bogeys) { + if (instance != null) { + ms.pushPose(); + CarriageBogey bogey = instance.bogey; + + CarriageContraptionEntityRenderer.translateBogey(ms, bogey, bogeySpacing, viewYRot, viewXRot, partialTicks); + + instance.beginFrame(bogey.wheelAngle.getValue(partialTicks), ms); + ms.popPose(); + } + } + + ms.popPose(); + } + + @Override + public void updateLight() { + if (bogeys == null) return; + + bogeys.forEach(instance -> { + if (instance != null) + instance.updateLight(world, entity); + }); + } + + @Override + public void remove() { + bogeys.forEach(BogeyInstance::remove); + } + + +} diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/track/StandardBogeyBlock.java b/src/main/java/com/simibubi/create/content/logistics/trains/track/StandardBogeyBlock.java index 72064ea39..e579cbf35 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/track/StandardBogeyBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/track/StandardBogeyBlock.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.logistics.trains.track; import java.util.EnumSet; +import com.jozufozu.flywheel.api.MaterialManager; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Vector3f; @@ -10,6 +11,8 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock; import com.simibubi.create.content.logistics.trains.IBogeyBlock; +import com.simibubi.create.content.logistics.trains.entity.BogeyInstance; +import com.simibubi.create.content.logistics.trains.entity.CarriageBogey; import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.utility.AngleHelper; @@ -36,7 +39,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; public class StandardBogeyBlock extends Block implements IBogeyBlock, ITE { public static final EnumProperty AXIS = BlockStateProperties.HORIZONTAL_AXIS; - private boolean large; + private final boolean large; public StandardBogeyBlock(Properties p_i48440_1_, boolean large) { super(p_i48440_1_); @@ -114,23 +117,30 @@ public class StandardBogeyBlock extends Block implements IBogeyBlock, ITE pState.cycle(AXIS); + default -> pState; + }; } @Override diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 6bd26fcc7..275797b7a 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -212,7 +212,6 @@ public class ClientEvents { CreateClient.GHOST_BLOCKS.renderAll(ms, buffer); CreateClient.OUTLINER.renderOutlines(ms, buffer, pt); - // LightVolumeDebugger.render(ms, buffer); buffer.draw(); RenderSystem.enableCull(); diff --git a/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java b/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java index f40420188..ee411cfdc 100644 --- a/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java +++ b/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java @@ -42,7 +42,7 @@ public class CreateEntityBuilder extends EntityBuilder instance(NonNullSupplier>> instanceFactory, boolean renderNormally) { - return instance(instanceFactory, be -> true); + return instance(instanceFactory, be -> renderNormally); } public CreateEntityBuilder instance(NonNullSupplier>> instanceFactory, NonNullPredicate renderNormally) { diff --git a/src/main/java/com/simibubi/create/foundation/utility/Couple.java b/src/main/java/com/simibubi/create/foundation/utility/Couple.java index 36b257a23..608ab696c 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/Couple.java +++ b/src/main/java/com/simibubi/create/foundation/utility/Couple.java @@ -63,10 +63,15 @@ public class Couple extends Pair implements Iterable { return Couple.create(function.apply(first, values.first), function.apply(second, values.second)); } + public Couple mapNotNullWithParam(BiFunction function, R value) { + return Couple.create(first != null ? function.apply(first, value) : null, + second != null ? function.apply(second, value) : null); + } + public boolean both(Predicate test) { return test.test(getFirst()) && test.test(getSecond()); } - + public boolean either(Predicate test) { return test.test(getFirst()) || test.test(getSecond()); } @@ -125,7 +130,7 @@ public class Couple extends Pair implements Iterable { private static class Couplerator implements Iterator { int state; - private Couple couple; + private final Couple couple; public Couplerator(Couple couple) { this.couple = couple;