From b6d1f02d6a656a79b5b002e1ab351cbf342cbc9a Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Tue, 23 Jan 2024 13:56:36 -0800 Subject: [PATCH] Chugging along - Fix compile errors with new flywheel light update system. - Fix compile errors in instance shaders. - Call Instance#setChanged where needed. --- gradle.properties | 2 +- .../com/simibubi/create/CreateClient.java | 4 ++- .../harvester/HarvesterActorVisual.java | 4 ++- .../contraptions/actors/psi/PSIVisual.java | 1 + .../actors/roller/RollerActorVisual.java | 6 ++-- .../contraptions/bearing/BearingVisual.java | 7 ++-- .../elevator/ElevatorPulleyVisual.java | 8 +---- .../gantry/GantryCarriageVisual.java | 3 +- .../pulley/AbstractPulleyVisual.java | 29 +++++----------- .../render/ContraptionLighter.java | 12 +------ .../render/NonStationaryLighter.java | 4 +-- .../equipment/toolbox/ToolBoxVisual.java | 1 + .../fluids/pipes/valve/FluidValveVisual.java | 3 +- .../base/KineticBlockEntityVisual.java | 6 ++-- .../kinetics/base/SingleRotatingVisual.java | 1 + .../kinetics/belt/BeltBlockEntity.java | 23 ++----------- .../content/kinetics/belt/BeltVisual.java | 12 ++++--- .../kinetics/crank/HandCrankVisual.java | 4 ++- .../kinetics/deployer/DeployerVisual.java | 10 +++--- .../kinetics/flywheel/FlywheelVisual.java | 3 +- .../content/kinetics/gauge/GaugeVisual.java | 4 +-- .../kinetics/gearbox/GearboxVisual.java | 3 +- .../kinetics/mechanicalArm/ArmVisual.java | 15 ++++++--- .../content/kinetics/mixer/MixerVisual.java | 6 ++-- .../content/kinetics/press/PressVisual.java | 3 +- .../BracketedKineticBlockEntityVisual.java | 33 ++++++++++--------- .../encased/EncasedCogVisual.java | 2 ++ .../logistics/depot/EjectorVisual.java | 1 + .../entity/CarriageContraptionVisual.java | 14 ++++---- .../content/trains/track/TrackVisual.java | 4 --- .../assets/create/flywheel/instance/belt.vert | 13 +++----- .../flywheel/instance/contraption_actor.vert | 14 ++++---- .../create/flywheel/instance/cull/belt.glsl | 7 +--- .../instance/cull/contraption_actor.glsl | 11 +++---- .../create/flywheel/instance/cull/flap.glsl | 15 +++------ .../flywheel/instance/cull/rotating.glsl | 17 ++++------ .../assets/create/flywheel/instance/flap.vert | 20 ++++------- .../create/flywheel/instance/rotating.vert | 20 +++++------ 38 files changed, 146 insertions(+), 199 deletions(-) diff --git a/gradle.properties b/gradle.properties index eb3694c76..f0359e1cb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ use_parchment = true # dependency versions registrate_version = MC1.20-1.3.3 flywheel_minecraft_version = 1.20.1 -flywheel_version = 1.0.0-alpha-18 +flywheel_version = 1.0.0-alpha-27 jei_minecraft_version = 1.20.1 jei_version = 15.2.0.22 curios_minecraft_version = 1.20.1 diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index ea5cb4b0a..be27cae85 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -20,7 +20,7 @@ import com.simibubi.create.foundation.outliner.Outliner; import com.simibubi.create.foundation.ponder.element.WorldSectionElement; import com.simibubi.create.foundation.render.AllInstanceTypes; import com.simibubi.create.foundation.render.CachedBufferer; -import com.simibubi.create.foundation.render.CreateContexts; +import com.simibubi.create.foundation.render.StitchedSprite; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.ModelSwapper; @@ -64,6 +64,8 @@ public class CreateClient { modEventBus.addListener(CreateClient::clientInit); modEventBus.addListener(AllParticleTypes::registerFactories); + modEventBus.addListener(StitchedSprite::onTextureStitchPost); + AllInstanceTypes.init(); MODEL_SWAPPER.registerListeners(modEventBus); diff --git a/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterActorVisual.java b/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterActorVisual.java index 5d1f447c3..5c69dfac0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterActorVisual.java +++ b/src/main/java/com/simibubi/create/content/contraptions/actors/harvester/HarvesterActorVisual.java @@ -44,6 +44,7 @@ public class HarvesterActorVisual extends ActorVisual { horizontalAngle = facing.toYRot() + ((facing.getAxis() == Direction.Axis.X) ? 180 : 0); harvester.setBlockLight(localBlockLight()); + harvester.setChanged(); } protected PartialModel getRollingPartial() { @@ -90,7 +91,8 @@ public class HarvesterActorVisual extends ActorVisual { .uncenter() .translate(getRotationOffset()) .rotateXDegrees((float) getRotation()) - .translateBack(getRotationOffset()); + .translateBack(getRotationOffset()) + .setChanged(); } protected double getRotation() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/actors/psi/PSIVisual.java b/src/main/java/com/simibubi/create/content/contraptions/actors/psi/PSIVisual.java index 0d23f1f3e..851ee24d7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/actors/psi/PSIVisual.java +++ b/src/main/java/com/simibubi/create/content/contraptions/actors/psi/PSIVisual.java @@ -24,6 +24,7 @@ public class PSIVisual extends AbstractBlockEntityVisual e topInstance = instancerProvider.instancer(InstanceTypes.ORIENTED, Models.partial(top), RenderStage.AFTER_BLOCK_ENTITIES) .createInstance(); - topInstance.setPosition(getVisualPosition()).setRotation(blockOrientation); + topInstance.setPosition(getVisualPosition()) + .setRotation(blockOrientation) + .setChanged(); } @Override @@ -53,7 +55,8 @@ public class BearingVisual e rot.mul(blockOrientation); - topInstance.setRotation(rot); + topInstance.setRotation(rot) + .setChanged(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorPulleyVisual.java b/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorPulleyVisual.java index 8198e4953..7199c7e06 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorPulleyVisual.java +++ b/src/main/java/com/simibubi/create/content/contraptions/elevator/ElevatorPulleyVisual.java @@ -3,21 +3,15 @@ package com.simibubi.create.content.contraptions.elevator; import com.jozufozu.flywheel.api.visual.DynamicVisual; import com.jozufozu.flywheel.api.visual.VisualFrameContext; import com.jozufozu.flywheel.api.visualization.VisualizationContext; -import com.jozufozu.flywheel.lib.light.TickingLightListener; import com.simibubi.create.content.kinetics.base.ShaftVisual; // TODO -public class ElevatorPulleyVisual extends ShaftVisual implements DynamicVisual, TickingLightListener { +public class ElevatorPulleyVisual extends ShaftVisual implements DynamicVisual { public ElevatorPulleyVisual(VisualizationContext context, ElevatorPulleyBlockEntity blockEntity) { super(context, blockEntity); } - @Override - public boolean tickLightListener() { - return false; - } - @Override public void beginFrame(VisualFrameContext ctx) { } diff --git a/src/main/java/com/simibubi/create/content/contraptions/gantry/GantryCarriageVisual.java b/src/main/java/com/simibubi/create/content/contraptions/gantry/GantryCarriageVisual.java index 6703e14d6..9e5a40040 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/gantry/GantryCarriageVisual.java +++ b/src/main/java/com/simibubi/create/content/contraptions/gantry/GantryCarriageVisual.java @@ -74,7 +74,8 @@ public class GantryCarriageVisual extends ShaftVisual .translate(0, -9 / 16f, 0) .rotateX(-cogAngle) .translate(0, 9 / 16f, 0) - .uncenter(); + .uncenter() + .setChanged(); } static float getRotationMultiplier(Direction.Axis gantryAxis, Direction facing) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/pulley/AbstractPulleyVisual.java b/src/main/java/com/simibubi/create/content/contraptions/pulley/AbstractPulleyVisual.java index 4ba00ebf7..ebf48d643 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/pulley/AbstractPulleyVisual.java +++ b/src/main/java/com/simibubi/create/content/contraptions/pulley/AbstractPulleyVisual.java @@ -7,12 +7,10 @@ import com.jozufozu.flywheel.api.instance.Instancer; import com.jozufozu.flywheel.api.visual.DynamicVisual; import com.jozufozu.flywheel.api.visual.VisualFrameContext; import com.jozufozu.flywheel.api.visualization.VisualizationContext; -import com.jozufozu.flywheel.lib.box.Box; import com.jozufozu.flywheel.lib.box.MutableBox; import com.jozufozu.flywheel.lib.instance.OrientedInstance; import com.jozufozu.flywheel.lib.light.LightPacking; import com.jozufozu.flywheel.lib.light.LightVolume; -import com.jozufozu.flywheel.lib.light.TickingLightListener; import com.mojang.math.Axis; import com.simibubi.create.content.kinetics.base.KineticBlockEntity; import com.simibubi.create.content.kinetics.base.ShaftVisual; @@ -21,11 +19,9 @@ import com.simibubi.create.foundation.render.GroupInstance; import com.simibubi.create.foundation.render.SelectInstance; import net.minecraft.core.Direction; -import net.minecraft.core.SectionPos; import net.minecraft.util.Mth; -import net.minecraft.world.level.LightLayer; -public abstract class AbstractPulleyVisual extends ShaftVisual implements DynamicVisual, TickingLightListener { +public abstract class AbstractPulleyVisual extends ShaftVisual implements DynamicVisual { final OrientedInstance coil; final SelectInstance magnet; @@ -47,6 +43,7 @@ public abstract class AbstractPulleyVisual extends coil = getCoilModel().createInstance() .setPosition(getVisualPosition()); + coil.setChanged(); magnet = new SelectInstance<>(this::getMagnetModelIndex); magnet.addModel(getMagnetModel()) @@ -78,7 +75,8 @@ public abstract class AbstractPulleyVisual extends data.setPosition(getVisualPosition()) .nudgePosition(0, -offset, 0) .setBlockLight(LightPacking.getBlock(packed)) - .setSkyLight(LightPacking.getSky(packed)); + .setSkyLight(LightPacking.getSky(packed)) + .setChanged(); }); halfRope.update() @@ -91,7 +89,8 @@ public abstract class AbstractPulleyVisual extends rope1.setPosition(getVisualPosition()) .nudgePosition(0, -halfRopeNudge, 0) .setBlockLight(LightPacking.getBlock(packed)) - .setSkyLight(LightPacking.getSky(packed)); + .setSkyLight(LightPacking.getSky(packed)) + .setChanged(); }); if (isRunning()) { @@ -104,7 +103,8 @@ public abstract class AbstractPulleyVisual extends .setPosition(getVisualPosition()) .nudgePosition(0, -offset + i + 1, 0) .setBlockLight(LightPacking.getBlock(packed)) - .setSkyLight(LightPacking.getSky(packed)); + .setSkyLight(LightPacking.getSky(packed)) + .setChanged(); } } else { rope.clear(); @@ -114,6 +114,7 @@ public abstract class AbstractPulleyVisual extends @Override public void updateLight() { super.updateLight(); + light.copyLight(volume); relight(pos, coil); } @@ -141,7 +142,6 @@ public abstract class AbstractPulleyVisual extends protected abstract boolean isRunning(); - @Override public boolean tickLightListener() { if (updateVolume()) { light.move(volume); @@ -182,17 +182,6 @@ public abstract class AbstractPulleyVisual extends } } - @Override - public Box getVolume() { - return volume; - } - - @Override - public void onLightUpdate(LightLayer type, SectionPos pos) { - super.onLightUpdate(type, pos); - light.onLightUpdate(type, pos); - } - @Override public void collectCrumblingInstances(Consumer consumer) { super.collectCrumblingInstances(consumer); diff --git a/src/main/java/com/simibubi/create/content/contraptions/render/ContraptionLighter.java b/src/main/java/com/simibubi/create/content/contraptions/render/ContraptionLighter.java index 8f319d4a6..e3033709f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/render/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/render/ContraptionLighter.java @@ -3,17 +3,14 @@ package com.simibubi.create.content.contraptions.render; import com.jozufozu.flywheel.lib.box.Box; import com.jozufozu.flywheel.lib.box.MutableBox; import com.jozufozu.flywheel.lib.light.GPULightVolume; -import com.jozufozu.flywheel.lib.light.LightListener; -import com.jozufozu.flywheel.lib.light.LightUpdater; import com.simibubi.create.content.contraptions.Contraption; import net.minecraft.core.SectionPos; import net.minecraft.world.level.LightLayer; -public abstract class ContraptionLighter implements LightListener { +public abstract class ContraptionLighter { protected final C contraption; public final GPULightVolume lightVolume; - protected final LightUpdater lightUpdater; protected final MutableBox bounds; @@ -21,7 +18,6 @@ public abstract class ContraptionLighter implements Light protected ContraptionLighter(C contraption) { this.contraption = contraption; - lightUpdater = LightUpdater.get(contraption.entity.level()); bounds = getContraptionBounds(); growBoundsForEdgeData(bounds); @@ -30,18 +26,14 @@ public abstract class ContraptionLighter implements Light lightVolume.initialize(); scheduleRebuild = true; - - lightUpdater.addListener(this); } public abstract MutableBox getContraptionBounds(); - @Override public boolean isInvalid() { return lightVolume.isInvalid(); } - @Override public void onLightUpdate(LightLayer type, SectionPos pos) { lightVolume.onLightUpdate(type, pos); } @@ -51,13 +43,11 @@ public abstract class ContraptionLighter implements Light bounds.grow(2); } - @Override public Box getVolume() { return bounds; } public void delete() { - lightUpdater.removeListener(this); lightVolume.delete(); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/render/NonStationaryLighter.java b/src/main/java/com/simibubi/create/content/contraptions/render/NonStationaryLighter.java index d80a5a0f3..d3a229444 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/render/NonStationaryLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/render/NonStationaryLighter.java @@ -2,16 +2,14 @@ package com.simibubi.create.content.contraptions.render; import com.jozufozu.flywheel.lib.box.Box; import com.jozufozu.flywheel.lib.box.MutableBox; -import com.jozufozu.flywheel.lib.light.TickingLightListener; import com.simibubi.create.content.contraptions.Contraption; import com.simibubi.create.infrastructure.config.AllConfigs; -public class NonStationaryLighter extends ContraptionLighter implements TickingLightListener { +public class NonStationaryLighter extends ContraptionLighter { public NonStationaryLighter(C contraption) { super(contraption); } - @Override public boolean tickLightListener() { if (getVolume().volume() > AllConfigs.client().maxContraptionLightVolume.get()) return false; diff --git a/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolBoxVisual.java b/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolBoxVisual.java index 3c7e81530..8cb2fd562 100644 --- a/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolBoxVisual.java +++ b/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolBoxVisual.java @@ -38,6 +38,7 @@ public class ToolBoxVisual extends AbstractBlockEntityVisual lid = instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.partial(AllPartialModels.TOOLBOX_LIDS.get(blockEntity.getColor())), RenderStage.AFTER_BLOCK_ENTITIES) .createInstance(); + super.init(pt); } @Override diff --git a/src/main/java/com/simibubi/create/content/fluids/pipes/valve/FluidValveVisual.java b/src/main/java/com/simibubi/create/content/fluids/pipes/valve/FluidValveVisual.java index d7ed82dba..0df1320e3 100644 --- a/src/main/java/com/simibubi/create/content/fluids/pipes/valve/FluidValveVisual.java +++ b/src/main/java/com/simibubi/create/content/fluids/pipes/valve/FluidValveVisual.java @@ -67,7 +67,8 @@ public class FluidValveVisual extends ShaftVisual impleme .rotateY((float) yRot) .rotateX((float) xRot) .rotateY(pointerRotationOffset + pointerRotation) - .uncenter(); + .uncenter() + .setChanged(); } @Override diff --git a/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntityVisual.java b/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntityVisual.java index ecda32b4e..9676e217d 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntityVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntityVisual.java @@ -35,7 +35,8 @@ public abstract class KineticBlockEntityVisual ext instance.setRotationAxis(axis) .setRotationOffset(getRotationOffset(axis)) .setRotationalSpeed(speed) - .setColor(blockEntity); + .setColor(blockEntity) + .setChanged(); } protected final RotatingInstance setup(RotatingInstance key) { @@ -55,7 +56,8 @@ public abstract class KineticBlockEntityVisual ext .setRotationalSpeed(speed) .setRotationOffset(getRotationOffset(axis)) .setColor(blockEntity) - .setPosition(getVisualPosition()); + .setPosition(getVisualPosition()) + .setChanged(); return key; } diff --git a/src/main/java/com/simibubi/create/content/kinetics/base/SingleRotatingVisual.java b/src/main/java/com/simibubi/create/content/kinetics/base/SingleRotatingVisual.java index 6f344a4f1..cb00ea20c 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/base/SingleRotatingVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/base/SingleRotatingVisual.java @@ -22,6 +22,7 @@ public class SingleRotatingVisual extends KineticB rotatingModel = instancerProvider.instancer(AllInstanceTypes.ROTATING, model(), RenderStage.AFTER_BLOCK_ENTITIES) .createInstance(); setup(rotatingModel); + super.init(pt); } @Override diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltBlockEntity.java index a6816196f..3d554ca6f 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltBlockEntity.java @@ -14,8 +14,6 @@ import java.util.function.Function; import com.jozufozu.flywheel.lib.box.Box; import com.jozufozu.flywheel.lib.box.MutableBox; -import com.jozufozu.flywheel.lib.light.LightListener; -import com.jozufozu.flywheel.lib.light.LightUpdater; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.kinetics.base.IRotate; import com.simibubi.create.content.kinetics.base.KineticBlockEntity; @@ -579,13 +577,11 @@ public class BeltBlockEntity extends KineticBlockEntity { * Hide this behavior in an inner class to avoid loading LightListener on servers. */ @OnlyIn(Dist.CLIENT) - class BeltLighter implements LightListener { + class BeltLighter { private byte[] light; public BeltLighter() { initializeLight(); - LightUpdater.get(level) - .addListener(this); } /** @@ -605,7 +601,6 @@ public class BeltBlockEntity extends KineticBlockEntity { return light == null ? 0 : LightTexture.pack(light[segment * 2], light[segment * 2 + 1]); } - @Override public Box getVolume() { BlockPos endPos = BeltHelper.getPositionForOffset(BeltBlockEntity.this, beltLength - 1); var bb = MutableBox.from(worldPosition, endPos); @@ -613,27 +608,13 @@ public class BeltBlockEntity extends KineticBlockEntity { return bb; } - @Override - public boolean isInvalid() { - return remove; - } - - @Override public void onLightUpdate(LightLayer type, SectionPos pos) { if (remove) return; if (level == null) return; - Box beltVolume = getVolume(); - - if (beltVolume.intersects(MutableBox.from(pos))) { - if (type == LightLayer.BLOCK) - updateBlockLight(); - - if (type == LightLayer.SKY) - updateSkyLight(); - } + initializeLight(); } private void initializeLight() { diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltVisual.java b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltVisual.java index b72629fdf..0189843a1 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltVisual.java @@ -88,8 +88,9 @@ public class BeltVisual extends KineticBlockEntityVisual { SpriteShiftEntry spriteShiftEntry = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom); key.setScrollTexture(spriteShiftEntry) - .setColor(blockEntity) - .setRotationalSpeed(getScrollSpeed()); + .setColor(blockEntity) + .setRotationalSpeed(getScrollSpeed()) + .setChanged(); bottom = false; } @@ -165,14 +166,17 @@ public class BeltVisual extends KineticBlockEntityVisual { .setColor(blockEntity) .setPosition(getVisualPosition()) .setBlockLight(level.getBrightness(LightLayer.BLOCK, pos)) - .setSkyLight(level.getBrightness(LightLayer.SKY, pos)); + .setSkyLight(level.getBrightness(LightLayer.SKY, pos)) + .setChanged(); return key; } @Override public void collectCrumblingInstances(Consumer consumer) { - consumer.accept(pulleyKey); + if (pulleyKey != null) { + consumer.accept(pulleyKey); + } keys.forEach(consumer); } } diff --git a/src/main/java/com/simibubi/create/content/kinetics/crank/HandCrankVisual.java b/src/main/java/com/simibubi/create/content/kinetics/crank/HandCrankVisual.java index b216fa0fe..854d8490b 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/crank/HandCrankVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/crank/HandCrankVisual.java @@ -46,11 +46,13 @@ public class HandCrankVisual extends SingleRotatingVisual .translate(getVisualPosition()) .center() .rotate(angle, Direction.get(Direction.AxisDirection.POSITIVE, axis)) - .uncenter(); + .uncenter() + .setChanged(); } @Override public void init(float pt) { + // FIXME: need to call super.super.init here if (blockEntity.shouldRenderShaft()) super.init(pt); } diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerVisual.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerVisual.java index 509f6f470..3b93b1dae 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerVisual.java @@ -124,8 +124,8 @@ public class DeployerVisual extends ShaftVisual implements float y = blockPos.getY() + ((float) facingVec.getY()) * distance; float z = blockPos.getZ() + ((float) facingVec.getZ()) * distance; - pole.setPosition(x, y, z); - hand.setPosition(x, y, z); + pole.setPosition(x, y, z).setChanged(); + hand.setPosition(x, y, z).setChanged(); } static void updateRotation(OrientedInstance pole, OrientedInstance hand, float yRot, float xRot, float zRot) { @@ -133,11 +133,13 @@ public class DeployerVisual extends ShaftVisual implements Quaternionf q = Axis.YP.rotationDegrees(yRot); q.mul(Axis.XP.rotationDegrees(xRot)); - hand.setRotation(q); + hand.setRotation(q) + .setChanged(); q.mul(Axis.ZP.rotationDegrees(zRot)); - pole.setRotation(q); + pole.setRotation(q) + .setChanged(); } @Override diff --git a/src/main/java/com/simibubi/create/content/kinetics/flywheel/FlywheelVisual.java b/src/main/java/com/simibubi/create/content/kinetics/flywheel/FlywheelVisual.java index a63cd5b8e..b5bb46d78 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/flywheel/FlywheelVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/flywheel/FlywheelVisual.java @@ -62,7 +62,8 @@ public class FlywheelVisual extends KineticBlockEntityVisual implemen msr.pushPose(); rotateToFace(msr); - getSecond().setTransform(ms); + getSecond().setTransform(ms).setChanged(); msr.translate(0, dialPivot, dialPivot) .rotate((float) (Math.PI / 2 * -progress), Direction.EAST) .translate(0, -dialPivot, -dialPivot); - getFirst().setTransform(ms); + getFirst().setTransform(ms).setChanged(); msr.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/kinetics/gearbox/GearboxVisual.java b/src/main/java/com/simibubi/create/content/kinetics/gearbox/GearboxVisual.java index 4d0bb2999..c4a2d9193 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/gearbox/GearboxVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/gearbox/GearboxVisual.java @@ -49,7 +49,8 @@ public class GearboxVisual extends KineticBlockEntityVisual .setRotationOffset(getRotationOffset(axis)).setColor(blockEntity) .setPosition(getVisualPosition()) .setBlockLight(blockLight) - .setSkyLight(skyLight); + .setSkyLight(skyLight) + .setChanged(); keys.put(direction, key); } diff --git a/src/main/java/com/simibubi/create/content/kinetics/mechanicalArm/ArmVisual.java b/src/main/java/com/simibubi/create/content/kinetics/mechanicalArm/ArmVisual.java index 908f3ddc2..617c6c20b 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/mechanicalArm/ArmVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/mechanicalArm/ArmVisual.java @@ -133,22 +133,26 @@ public class ArmVisual extends SingleRotatingVisual implements D msr.rotateX(180); ArmRenderer.transformBase(msr, baseAngle); - base.setTransform(msLocal); + base.setTransform(msLocal) + .setChanged(); ArmRenderer.transformLowerArm(msr, lowerArmAngle); lowerBody.setTransform(msLocal) - .setColor(color); + .setColor(color) + .setChanged(); ArmRenderer.transformUpperArm(msr, upperArmAngle); upperBody.setTransform(msLocal) - .setColor(color); + .setColor(color) + .setChanged(); ArmRenderer.transformHead(msr, headAngle); if (ceiling && blockEntity.goggles) msr.rotateZ(180); - claw.setTransform(msLocal); + claw.setTransform(msLocal) + .setChanged(); if (ceiling && blockEntity.goggles) msr.rotateZ(180); @@ -166,7 +170,8 @@ public class ArmVisual extends SingleRotatingVisual implements D int flip = index * 2 - 1; ArmRenderer.transformClawHalf(msr, hasItem, isBlockItem, flip); clawGrips.get(index) - .setTransform(msLocal); + .setTransform(msLocal) + .setChanged(); msLocal.popPose(); } } diff --git a/src/main/java/com/simibubi/create/content/kinetics/mixer/MixerVisual.java b/src/main/java/com/simibubi/create/content/kinetics/mixer/MixerVisual.java index 8264cefa6..b1941a55d 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/mixer/MixerVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/mixer/MixerVisual.java @@ -62,12 +62,14 @@ public class MixerVisual extends EncasedCogVisual implements DynamicVisual { mixerHead.setPosition(getVisualPosition()) .nudge(0, -renderedHeadOffset, 0) - .setRotationalSpeed(speed * 2); + .setRotationalSpeed(speed * 2) + .setChanged(); } private void transformPole(float renderedHeadOffset) { mixerPole.setPosition(getVisualPosition()) - .nudgePosition(0, -renderedHeadOffset, 0); + .nudgePosition(0, -renderedHeadOffset, 0) + .setChanged(); } private float getRenderedHeadOffset() { diff --git a/src/main/java/com/simibubi/create/content/kinetics/press/PressVisual.java b/src/main/java/com/simibubi/create/content/kinetics/press/PressVisual.java index 31f2437e8..c6e487552 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/press/PressVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/press/PressVisual.java @@ -45,7 +45,8 @@ public class PressVisual extends ShaftVisual impleme float renderedHeadOffset = getRenderedHeadOffset(blockEntity); pressHead.setPosition(getVisualPosition()) - .nudgePosition(0, -renderedHeadOffset, 0); + .nudgePosition(0, -renderedHeadOffset, 0) + .setChanged(); } private float getRenderedHeadOffset(MechanicalPressBlockEntity press) { diff --git a/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/BracketedKineticBlockEntityVisual.java b/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/BracketedKineticBlockEntityVisual.java index 37dca3c4f..38cecb5b6 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/BracketedKineticBlockEntityVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/simpleRelays/BracketedKineticBlockEntityVisual.java @@ -31,22 +31,22 @@ public class BracketedKineticBlockEntityVisual extends SingleRotatingVisual half = instancerProvider.instancer(AllInstanceTypes.ROTATING, model, RenderStage.AFTER_BLOCK_ENTITIES); + + additionalShaft = setup(half.createInstance(), speed); + additionalShaft.setRotationOffset(offset) + .setChanged(); + } super.init(pt); - if (!ICogWheel.isLargeCog(blockEntity.getBlockState())) - return; - - // Large cogs sometimes have to offset their teeth by 11.25 degrees in order to - // mesh properly - - float speed = blockEntity.getSpeed(); - Direction.Axis axis = KineticBlockEntityRenderer.getRotationAxisOf(blockEntity); - BlockPos pos = blockEntity.getBlockPos(); - float offset = BracketedKineticBlockEntityRenderer.getShaftAngleOffset(axis, pos); - var model = Models.partial(AllPartialModels.COGWHEEL_SHAFT, axis, BracketedKineticBlockEntityVisual::rotateToAxis); - Instancer half = instancerProvider.instancer(AllInstanceTypes.ROTATING, model, RenderStage.AFTER_BLOCK_ENTITIES); - - additionalShaft = setup(half.createInstance(), speed); - additionalShaft.setRotationOffset(offset); } @Override @@ -72,7 +72,8 @@ public class BracketedKineticBlockEntityVisual extends SingleRotatingVisual implements Dy float angle = lidProgress * 70; EjectorRenderer.applyLidAngle(blockEntity, angle, plate.loadIdentity().translate(getVisualPosition())); + plate.setChanged(); } @Override diff --git a/src/main/java/com/simibubi/create/content/trains/entity/CarriageContraptionVisual.java b/src/main/java/com/simibubi/create/content/trains/entity/CarriageContraptionVisual.java index 1309342f3..fc10aa376 100644 --- a/src/main/java/com/simibubi/create/content/trains/entity/CarriageContraptionVisual.java +++ b/src/main/java/com/simibubi/create/content/trains/entity/CarriageContraptionVisual.java @@ -32,13 +32,14 @@ public class CarriageContraptionVisual extends AbstractEntityVisual bogey.getStyle() + .createVisual(bogey, bogey.type.getSize(), manager), visualizationContext); + updateLight(); + } - bogeys = carriage.bogeys.mapNotNullWithParam((bogey, manager) -> - bogey.getStyle().createVisual(bogey, bogey.type.getSize(), manager), visualizationContext); - updateLight(); - } + super.init(pt); + } public void setBogeyVisibility(boolean first, boolean visible) { bogeyHidden.set(first, !visible); @@ -86,7 +87,6 @@ public class CarriageContraptionVisual extends AbstractEntityVisual { .map(this::createInstance) .filter(Objects::nonNull) .toList(); - LightUpdater.get(level) - .addListener(this); } - @Override public Box getVolume() { List out = new ArrayList<>(); out.addAll(blockEntity.connections.keySet()); diff --git a/src/main/resources/assets/create/flywheel/instance/belt.vert b/src/main/resources/assets/create/flywheel/instance/belt.vert index a42270e0f..b8b0fb93d 100644 --- a/src/main/resources/assets/create/flywheel/instance/belt.vert +++ b/src/main/resources/assets/create/flywheel/instance/belt.vert @@ -1,21 +1,16 @@ -#define PI 3.1415926538 - #include "flywheel:util/quaternion.glsl" #include "flywheel:util/matrix.glsl" -const float uTime = 0.; - - void flw_instanceVertex(in FlwInstance instance) { - flw_vertexPos = vec4(rotateVertexByQuat(flw_vertexPos.xyz - .5, instance.rotation) + instance.pos + .5, 1.); + flw_vertexPos = vec4(rotateByQuaternion(flw_vertexPos.xyz - .5, instance.rotation) + instance.pos + .5, 1.); - flw_vertexNormal = rotateVertexByQuat(flw_vertexNormal, instance.rotation); + flw_vertexNormal = rotateByQuaternion(flw_vertexNormal, instance.rotation); float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y; - float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult; + float scroll = fract(instance.speed * flw_renderTicks / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult; flw_vertexTexCoord = flw_vertexTexCoord - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll); - flw_vertexLight = instance.light; + flw_vertexLight = instance.light / 15.; #if defined(DEBUG_RAINBOW) flw_vertexColor = instance.color; diff --git a/src/main/resources/assets/create/flywheel/instance/contraption_actor.vert b/src/main/resources/assets/create/flywheel/instance/contraption_actor.vert index 676274e80..912baa876 100644 --- a/src/main/resources/assets/create/flywheel/instance/contraption_actor.vert +++ b/src/main/resources/assets/create/flywheel/instance/contraption_actor.vert @@ -1,15 +1,13 @@ #include "flywheel:util/matrix.glsl" #include "flywheel:util/quaternion.glsl" -const float uTime = 0.; - void flw_instanceVertex(in FlwInstance instance) { - float degrees = instance.offset + uTime * instance.speed / 20.; + float degrees = instance.offset + flw_renderSeconds * instance.speed; - vec4 kineticRot = quat(instance.axis, degrees); - vec3 rotated = rotateVertexByQuat(flw_vertexPos.xyz - instance.rotationCenter, kineticRot) + instance.rotationCenter; + vec4 kineticRot = quaternionDegrees(instance.axis, degrees); + vec3 rotated = rotateByQuaternion(flw_vertexPos.xyz - instance.rotationCenter, kineticRot) + instance.rotationCenter; - flw_vertexPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.); - flw_vertexNormal = rotateVertexByQuat(rotateVertexByQuat(flw_vertexNormal, kineticRot), instance.rotation); - flw_vertexLight = instance.light; + flw_vertexPos.xyz = rotateByQuaternion(rotated - .5, instance.rotation) + instance.pos + .5; + flw_vertexNormal = rotateByQuaternion(rotateByQuaternion(flw_vertexNormal, kineticRot), instance.rotation); + flw_vertexLight = instance.light / 15.; } diff --git a/src/main/resources/assets/create/flywheel/instance/cull/belt.glsl b/src/main/resources/assets/create/flywheel/instance/cull/belt.glsl index 0b638ab27..80778eef4 100644 --- a/src/main/resources/assets/create/flywheel/instance/cull/belt.glsl +++ b/src/main/resources/assets/create/flywheel/instance/cull/belt.glsl @@ -1,11 +1,6 @@ -#define PI 3.1415926538 - #include "flywheel:util/quaternion.glsl" -#include "flywheel:util/matrix.glsl" - -const float uTime = 0.; void flw_transformBoundingSphere(in FlwInstance instance, inout vec3 center, inout float radius) { // FIXME: this is incorrect, but it compiles - center = rotateVertexByQuat(center - .5, instance.rotation) + instance.pos + .5; + center = rotateByQuaternion(center - .5, instance.rotation) + instance.pos + .5; } diff --git a/src/main/resources/assets/create/flywheel/instance/cull/contraption_actor.glsl b/src/main/resources/assets/create/flywheel/instance/cull/contraption_actor.glsl index a1c1aaff4..c830f69ea 100644 --- a/src/main/resources/assets/create/flywheel/instance/cull/contraption_actor.glsl +++ b/src/main/resources/assets/create/flywheel/instance/cull/contraption_actor.glsl @@ -1,14 +1,11 @@ -#include "flywheel:util/matrix.glsl" #include "flywheel:util/quaternion.glsl" -const float uTime = 0.; - void flw_transformBoundingSphere(in FlwInstance instance, inout vec3 center, inout float radius) { // FIXME: this is incorrect, but it compiles - float degrees = instance.offset + uTime * instance.speed / 20.; + float degrees = instance.offset + flw_renderSeconds * instance.speed; - vec4 kineticRot = quat(instance.axis, degrees); - vec3 rotated = rotateVertexByQuat(center - instance.rotationCenter, kineticRot) + instance.rotationCenter; + vec4 kineticRot = quaternion(instance.axis, degrees); + vec3 rotated = rotateByQuaternion(center - instance.rotationCenter, kineticRot) + instance.rotationCenter; - center = rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5; + center = rotateByQuaternion(rotated - .5, instance.rotation) + instance.pos + .5; } diff --git a/src/main/resources/assets/create/flywheel/instance/cull/flap.glsl b/src/main/resources/assets/create/flywheel/instance/cull/flap.glsl index 8a8ebeaa3..1a4fed42b 100644 --- a/src/main/resources/assets/create/flywheel/instance/cull/flap.glsl +++ b/src/main/resources/assets/create/flywheel/instance/cull/flap.glsl @@ -1,14 +1,7 @@ #define PI 3.1415926538 -const float uTime = 0.; - -#include "flywheel:util/matrix.glsl" #include "flywheel:util/quaternion.glsl" -float toRad(float degrees) { - return fract(degrees / 360.) * PI * 2.; -} - float getFlapAngle(float flapness, float intensity, float scale) { float absFlap = abs(flapness); @@ -26,9 +19,9 @@ void flw_transformBoundingSphere(in FlwInstance flap, inout vec3 center, inout f // FIXME: this is incorrect, but it compiles float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale); - vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle); - vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle); + vec4 orientation = quaternion(vec3(0., 1., 0.), -flap.horizontalAngle); + vec4 flapRotation = quaternion(vec3(1., 0., 0.), flapAngle); - vec3 rotated = rotateVertexByQuat(center - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset; - center = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5; + vec3 rotated = rotateByQuaternion(center - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset; + center = rotateByQuaternion(rotated - .5, orientation) + flap.instancePos + .5; } diff --git a/src/main/resources/assets/create/flywheel/instance/cull/rotating.glsl b/src/main/resources/assets/create/flywheel/instance/cull/rotating.glsl index 809a5679a..2825ed2f9 100644 --- a/src/main/resources/assets/create/flywheel/instance/cull/rotating.glsl +++ b/src/main/resources/assets/create/flywheel/instance/cull/rotating.glsl @@ -1,20 +1,15 @@ -#define PI 3.1415926538 - #include "flywheel:util/matrix.glsl" -const float uTime = 0.; +mat3 kineticRotation(float offset, float speed, vec3 axis) { + float degrees = offset + flw_renderTicks * speed * 3./10.; -mat4 kineticRotation(float offset, float speed, vec3 axis) { - float degrees = offset + uTime * speed * 3./10.; - float angle = fract(degrees / 360.) * PI * 2.; - - return rotate(axis, angle); + return rotationDegrees(axis, degrees); } void flw_transformBoundingSphere(in FlwInstance instance, inout vec3 center, inout float radius) { // FIXME: this is incorrect, but it compiles - mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis); + mat3 spin = kineticRotation(instance.offset, instance.speed, instance.axis); - vec4 worldPos = spin * vec4(center - .5, 1.); - center = worldPos.xyz + instance.pos + .5; + vec3 worldPos = spin * (center - .5); + center = worldPos + instance.pos + .5; } diff --git a/src/main/resources/assets/create/flywheel/instance/flap.vert b/src/main/resources/assets/create/flywheel/instance/flap.vert index 75a82a908..ec8928a45 100644 --- a/src/main/resources/assets/create/flywheel/instance/flap.vert +++ b/src/main/resources/assets/create/flywheel/instance/flap.vert @@ -1,14 +1,7 @@ #define PI 3.1415926538 -const float uTime = 0.; - -#include "flywheel:util/matrix.glsl" #include "flywheel:util/quaternion.glsl" -float toRad(float degrees) { - return fract(degrees / 360.) * PI * 2.; -} - float getFlapAngle(float flapness, float intensity, float scale) { float absFlap = abs(flapness); @@ -25,13 +18,12 @@ float getFlapAngle(float flapness, float intensity, float scale) { void flw_instanceVertex(in FlwInstance flap) { float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale); - vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle); - vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle); + vec4 orientation = quaternion(vec3(0., 1., 0.), -flap.horizontalAngle); + vec4 flapRotation = quaternion(vec3(1., 0., 0.), flapAngle); - vec3 rotated = rotateVertexByQuat(flw_vertexPos.xyz - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset; - rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5; + vec3 rotated = rotateByQuaternion(flw_vertexPos.xyz - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset; - flw_vertexPos = vec4(rotated, 1.); - flw_vertexNormal = rotateVertexByQuat(rotateVertexByQuat(flw_vertexNormal, flapRotation), orientation); - flw_vertexLight = flap.light; + flw_vertexPos.xyz = rotateByQuaternion(rotated - .5, orientation) + flap.instancePos + .5; + flw_vertexNormal = rotateByQuaternion(rotateByQuaternion(flw_vertexNormal, flapRotation), orientation); + flw_vertexLight = flap.light / 15.; } diff --git a/src/main/resources/assets/create/flywheel/instance/rotating.vert b/src/main/resources/assets/create/flywheel/instance/rotating.vert index dd4d73ae1..3221cf0e7 100644 --- a/src/main/resources/assets/create/flywheel/instance/rotating.vert +++ b/src/main/resources/assets/create/flywheel/instance/rotating.vert @@ -1,24 +1,20 @@ -#define PI 3.1415926538 - #include "flywheel:util/matrix.glsl" const float uTime = 0.; -mat4 kineticRotation(float offset, float speed, vec3 axis) { - float degrees = offset + uTime * speed * 3./10.; - float angle = fract(degrees / 360.) * PI * 2.; - - return rotate(axis, angle); +mat3 kineticRotation(float offset, float speed, vec3 axis) { + float degrees = offset + flw_renderTicks * speed * 3./10.; + return rotationDegrees(axis, degrees); } void flw_instanceVertex(in FlwInstance instance) { - mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis); + mat3 spin = kineticRotation(instance.offset, instance.speed, instance.axis); - vec4 worldPos = spin * vec4(flw_vertexPos.xyz - .5, 1.); - flw_vertexPos = vec4(worldPos.xyz + instance.pos + .5, 1.); + vec3 worldPos = spin * (flw_vertexPos.xyz - .5); + flw_vertexPos.xyz = worldPos.xyz + instance.pos + .5; - flw_vertexNormal = modelToNormal(spin) * flw_vertexNormal; - flw_vertexLight = instance.light; + flw_vertexNormal = spin * flw_vertexNormal; + flw_vertexLight = instance.light / 15.; #if defined(DEBUG_RAINBOW) flw_vertexColor = instance.color;