Instanced steam engines

- Add SteamEngineInstance
- Delete contraption models on contraption invalidate
- Do not use enum subclasses in BottomlessFluidMode
- Fix ContraptionDriverInteractMixin being added twice
- Update Flywheel
This commit is contained in:
PepperCode1 2022-11-22 14:35:37 -08:00
parent 131c9a5479
commit 5b038d419c
7 changed files with 144 additions and 43 deletions

View file

@ -21,7 +21,7 @@ parchment_version = 2022.11.06
# dependency versions # dependency versions
registrate_version = MC1.18.2-1.1.3 registrate_version = MC1.18.2-1.1.3
flywheel_minecraft_version = 1.18.2 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_minecraft_version = 1.18.2
jei_version = 9.7.0.209 jei_version = 9.7.0.209
curios_minecraft_version = 1.18.2 curios_minecraft_version = 1.18.2

View file

@ -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.SawRenderer;
import com.simibubi.create.content.contraptions.components.saw.SawTileEntity; 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.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.SteamEngineRenderer;
import com.simibubi.create.content.contraptions.components.steam.SteamEngineTileEntity; import com.simibubi.create.content.contraptions.components.steam.SteamEngineTileEntity;
import com.simibubi.create.content.contraptions.components.steam.whistle.WhistleRenderer; import com.simibubi.create.content.contraptions.components.steam.whistle.WhistleRenderer;
@ -528,6 +529,7 @@ public class AllTileEntities {
public static final BlockEntityEntry<SteamEngineTileEntity> STEAM_ENGINE = REGISTRATE public static final BlockEntityEntry<SteamEngineTileEntity> STEAM_ENGINE = REGISTRATE
.tileEntity("steam_engine", SteamEngineTileEntity::new) .tileEntity("steam_engine", SteamEngineTileEntity::new)
.instance(() -> SteamEngineInstance::new, false)
.validBlocks(AllBlocks.STEAM_ENGINE) .validBlocks(AllBlocks.STEAM_ENGINE)
.renderer(() -> SteamEngineRenderer::new) .renderer(() -> SteamEngineRenderer::new)
.register(); .register();

View file

@ -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<SteamEngineTileEntity> 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();
}
}

View file

@ -1,5 +1,6 @@
package com.simibubi.create.content.contraptions.components.steam; package com.simibubi.create.content.contraptions.components.steam;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.PartialModel;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -25,7 +26,12 @@ public class SteamEngineRenderer extends SafeTileEntityRenderer<SteamEngineTileE
@Override @Override
protected void renderSafe(SteamEngineTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, protected void renderSafe(SteamEngineTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) { int light, int overlay) {
VertexConsumer vb = buffer.getBuffer(RenderType.solid()); if (Backend.canUseInstancing(te.getLevel()))
return;
Float angle = te.getTargetAngle();
if (angle == null)
return;
BlockState blockState = te.getBlockState(); BlockState blockState = te.getBlockState();
Direction facing = SteamEngineBlock.getFacing(blockState); Direction facing = SteamEngineBlock.getFacing(blockState);
@ -36,22 +42,20 @@ public class SteamEngineRenderer extends SafeTileEntityRenderer<SteamEngineTileE
if (shaft != null) if (shaft != null)
axis = KineticTileEntityRenderer.getRotationAxisOf(shaft); axis = KineticTileEntityRenderer.getRotationAxisOf(shaft);
Float angle = te.getTargetAngle(); boolean roll90 = facingAxis.isHorizontal() && axis == Axis.Y || facingAxis.isVertical() && axis == Axis.Z;
if (angle == null)
return;
float sine = Mth.sin(angle); float sine = Mth.sin(angle);
float sine2 = Mth.sin(angle - Mth.HALF_PI); float sine2 = Mth.sin(angle - Mth.HALF_PI);
float piston = ((1 - sine) / 4) * 24 / 16f; float piston = ((1 - sine) / 4) * 24 / 16f;
boolean roll90 = facingAxis.isHorizontal() && axis == Axis.Y || facingAxis.isVertical() && axis == Axis.Z;
transformed(AllBlockPartials.ENGINE_PISTON, blockState, facing).rotateY(roll90 ? -90 : 0) VertexConsumer vb = buffer.getBuffer(RenderType.solid());
.unCentre()
.light(light) transformed(AllBlockPartials.ENGINE_PISTON, blockState, facing, roll90)
.translate(0, piston, 0) .translate(0, piston, 0)
.light(light)
.renderInto(ms, vb); .renderInto(ms, vb);
transformed(AllBlockPartials.ENGINE_LINKAGE, blockState, facing).rotateY(roll90 ? -90 : 0) transformed(AllBlockPartials.ENGINE_LINKAGE, blockState, facing, roll90)
.centre()
.translate(0, 1, 0) .translate(0, 1, 0)
.unCentre() .unCentre()
.translate(0, piston, 0) .translate(0, piston, 0)
@ -61,21 +65,22 @@ public class SteamEngineRenderer extends SafeTileEntityRenderer<SteamEngineTileE
.light(light) .light(light)
.renderInto(ms, vb); .renderInto(ms, vb);
transformed(AllBlockPartials.ENGINE_CONNECTOR, blockState, facing).rotateY(roll90 ? -90 : 0) transformed(AllBlockPartials.ENGINE_CONNECTOR, blockState, facing, roll90)
.unCentre()
.light(light)
.translate(0, 2, 0) .translate(0, 2, 0)
.centre() .centre()
.rotateXRadians(-angle + Mth.HALF_PI) .rotateXRadians(-angle + Mth.HALF_PI)
.unCentre() .unCentre()
.light(light)
.renderInto(ms, vb); .renderInto(ms, vb);
} }
private SuperByteBuffer transformed(PartialModel model, BlockState blockState, Direction facing) { private SuperByteBuffer transformed(PartialModel model, BlockState blockState, Direction facing, boolean roll90) {
return CachedBufferer.partial(model, blockState) return CachedBufferer.partial(model, blockState)
.centre() .centre()
.rotateY(AngleHelper.horizontalAngle(facing)) .rotateY(AngleHelper.horizontalAngle(facing))
.rotateX(AngleHelper.verticalAngle(facing) + 90); .rotateX(AngleHelper.verticalAngle(facing) + 90)
.rotateY(roll90 ? -90 : 0)
.unCentre();
} }
@Override @Override

View file

@ -120,8 +120,9 @@ public class FlwContraption extends ContraptionRenderInfo {
} }
public void invalidate() { public void invalidate() {
for (ArrayModelRenderer buffer : renderLayers.values()) { for (ArrayModelRenderer renderer : renderLayers.values()) {
buffer.delete(); renderer.delete();
renderer.getModel().delete();
} }
renderLayers.clear(); renderLayers.clear();

View file

@ -243,30 +243,21 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour {
} }
public enum BottomlessFluidMode implements Predicate<Fluid> { public enum BottomlessFluidMode implements Predicate<Fluid> {
ALLOW_ALL { 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<Fluid> predicate;
BottomlessFluidMode(Predicate<Fluid> predicate) {
this.predicate = predicate;
}
@Override @Override
public boolean test(Fluid fluid) { public boolean test(Fluid fluid) {
return true; return predicate.test(fluid);
} }
},
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);
}
};
} }
} }

View file

@ -9,7 +9,6 @@
"ContraptionDriverInteractMixin", "ContraptionDriverInteractMixin",
"CustomItemUseEffectsMixin", "CustomItemUseEffectsMixin",
"MapItemSavedDataMixin", "MapItemSavedDataMixin",
"ContraptionDriverInteractMixin",
"accessor.AbstractProjectileDispenseBehaviorAccessor", "accessor.AbstractProjectileDispenseBehaviorAccessor",
"accessor.DispenserBlockAccessor", "accessor.DispenserBlockAccessor",
"accessor.FallingBlockEntityAccessor", "accessor.FallingBlockEntityAccessor",