diff --git a/gradle.properties b/gradle.properties index d1a5ff50c..04131e4ce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ parchment_version = 2022.11.06 # dependency versions registrate_version = MC1.18.2-1.1.3 flywheel_minecraft_version = 1.18.2 -flywheel_version = 0.6.8-95 +flywheel_version = 0.6.8-96 jei_minecraft_version = 1.18.2 jei_version = 9.7.0.209 curios_minecraft_version = 1.18.2 diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index d2b1402ff..6f74119bb 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -53,6 +53,7 @@ import com.simibubi.create.content.contraptions.components.saw.SawInstance; import com.simibubi.create.content.contraptions.components.saw.SawRenderer; import com.simibubi.create.content.contraptions.components.saw.SawTileEntity; import com.simibubi.create.content.contraptions.components.steam.PoweredShaftTileEntity; +import com.simibubi.create.content.contraptions.components.steam.SteamEngineInstance; import com.simibubi.create.content.contraptions.components.steam.SteamEngineRenderer; import com.simibubi.create.content.contraptions.components.steam.SteamEngineTileEntity; import com.simibubi.create.content.contraptions.components.steam.whistle.WhistleRenderer; @@ -528,6 +529,7 @@ public class AllTileEntities { public static final BlockEntityEntry STEAM_ENGINE = REGISTRATE .tileEntity("steam_engine", SteamEngineTileEntity::new) + .instance(() -> SteamEngineInstance::new, false) .validBlocks(AllBlocks.STEAM_ENGINE) .renderer(() -> SteamEngineRenderer::new) .register(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineInstance.java new file mode 100644 index 000000000..2313e9039 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineInstance.java @@ -0,0 +1,103 @@ +package com.simibubi.create.content.contraptions.components.steam; + +import com.jozufozu.flywheel.api.MaterialManager; +import com.jozufozu.flywheel.api.instance.DynamicInstance; +import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance; +import com.jozufozu.flywheel.core.Materials; +import com.jozufozu.flywheel.core.materials.model.ModelData; +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.utility.AngleHelper; + +import net.minecraft.core.Direction; +import net.minecraft.core.Direction.Axis; +import net.minecraft.util.Mth; + +public class SteamEngineInstance extends BlockEntityInstance implements DynamicInstance { + + protected final ModelData piston; + protected final ModelData linkage; + protected final ModelData connector; + + public SteamEngineInstance(MaterialManager materialManager, SteamEngineTileEntity blockEntity) { + super(materialManager, blockEntity); + + piston = materialManager.defaultSolid() + .material(Materials.TRANSFORMED) + .getModel(AllBlockPartials.ENGINE_PISTON, blockState) + .createInstance(); + linkage = materialManager.defaultSolid() + .material(Materials.TRANSFORMED) + .getModel(AllBlockPartials.ENGINE_LINKAGE, blockState) + .createInstance(); + connector = materialManager.defaultSolid() + .material(Materials.TRANSFORMED) + .getModel(AllBlockPartials.ENGINE_CONNECTOR, blockState) + .createInstance(); + } + + @Override + public void beginFrame() { + Float angle = blockEntity.getTargetAngle(); + if (angle == null) { + piston.setEmptyTransform(); + linkage.setEmptyTransform(); + connector.setEmptyTransform(); + return; + } + + Direction facing = SteamEngineBlock.getFacing(blockState); + Axis facingAxis = facing.getAxis(); + Axis axis = Axis.Y; + + PoweredShaftTileEntity shaft = blockEntity.getShaft(); + if (shaft != null) + axis = KineticTileEntityRenderer.getRotationAxisOf(shaft); + + boolean roll90 = facingAxis.isHorizontal() && axis == Axis.Y || facingAxis.isVertical() && axis == Axis.Z; + float sine = Mth.sin(angle); + float sine2 = Mth.sin(angle - Mth.HALF_PI); + float piston = ((1 - sine) / 4) * 24 / 16f; + + transformed(this.piston, facing, roll90) + .translate(0, piston, 0); + + transformed(linkage, facing, roll90) + .centre() + .translate(0, 1, 0) + .unCentre() + .translate(0, piston, 0) + .translate(0, 4 / 16f, 8 / 16f) + .rotateX(sine2 * 23f) + .translate(0, -4 / 16f, -8 / 16f); + + transformed(connector, facing, roll90) + .translate(0, 2, 0) + .centre() + .rotateXRadians(-angle + Mth.HALF_PI) + .unCentre(); + } + + protected ModelData transformed(ModelData modelData, Direction facing, boolean roll90) { + return modelData.loadIdentity() + .translate(getInstancePosition()) + .centre() + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(AngleHelper.verticalAngle(facing) + 90) + .rotateY(roll90 ? -90 : 0) + .unCentre(); + } + + @Override + public void updateLight() { + relight(pos, piston, linkage, connector); + } + + @Override + protected void remove() { + piston.delete(); + linkage.delete(); + connector.delete(); + } + +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineRenderer.java index a9def6a7f..936700aa5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/steam/SteamEngineRenderer.java @@ -1,5 +1,6 @@ package com.simibubi.create.content.contraptions.components.steam; +import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.core.PartialModel; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -25,7 +26,12 @@ public class SteamEngineRenderer extends SafeTileEntityRenderer { - ALLOW_ALL { - @Override - public boolean test(Fluid fluid) { - return true; - } - }, - DENY_ALL { - @Override - public boolean test(Fluid fluid) { - return false; - } - }, - ALLOW_BY_TAG { - @Override - public boolean test(Fluid fluid) { - return AllFluidTags.BOTTOMLESS_ALLOW.matches(fluid); - } - }, - DENY_BY_TAG { - @Override - public boolean test(Fluid fluid) { - return !AllFluidTags.BOTTOMLESS_DENY.matches(fluid); - } - }; + ALLOW_ALL(fluid -> true), + DENY_ALL(fluid -> false), + ALLOW_BY_TAG(fluid -> AllFluidTags.BOTTOMLESS_ALLOW.matches(fluid)), + DENY_BY_TAG(fluid -> !AllFluidTags.BOTTOMLESS_DENY.matches(fluid)); + + private final Predicate predicate; + + BottomlessFluidMode(Predicate predicate) { + this.predicate = predicate; + } + + @Override + public boolean test(Fluid fluid) { + return predicate.test(fluid); + } } } diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 14c2d3a77..eca8d3b1a 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -9,7 +9,6 @@ "ContraptionDriverInteractMixin", "CustomItemUseEffectsMixin", "MapItemSavedDataMixin", - "ContraptionDriverInteractMixin", "accessor.AbstractProjectileDispenseBehaviorAccessor", "accessor.DispenserBlockAccessor", "accessor.FallingBlockEntityAccessor",