mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-14 07:23:50 +01:00
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:
parent
131c9a5479
commit
5b038d419c
7 changed files with 144 additions and 43 deletions
|
@ -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
|
||||
|
|
|
@ -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<SteamEngineTileEntity> STEAM_ENGINE = REGISTRATE
|
||||
.tileEntity("steam_engine", SteamEngineTileEntity::new)
|
||||
.instance(() -> SteamEngineInstance::new, false)
|
||||
.validBlocks(AllBlocks.STEAM_ENGINE)
|
||||
.renderer(() -> SteamEngineRenderer::new)
|
||||
.register();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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<SteamEngineTileE
|
|||
@Override
|
||||
protected void renderSafe(SteamEngineTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
|
||||
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();
|
||||
Direction facing = SteamEngineBlock.getFacing(blockState);
|
||||
|
@ -36,22 +42,20 @@ public class SteamEngineRenderer extends SafeTileEntityRenderer<SteamEngineTileE
|
|||
if (shaft != null)
|
||||
axis = KineticTileEntityRenderer.getRotationAxisOf(shaft);
|
||||
|
||||
Float angle = te.getTargetAngle();
|
||||
if (angle == null)
|
||||
return;
|
||||
|
||||
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;
|
||||
boolean roll90 = facingAxis.isHorizontal() && axis == Axis.Y || facingAxis.isVertical() && axis == Axis.Z;
|
||||
|
||||
transformed(AllBlockPartials.ENGINE_PISTON, blockState, facing).rotateY(roll90 ? -90 : 0)
|
||||
.unCentre()
|
||||
.light(light)
|
||||
VertexConsumer vb = buffer.getBuffer(RenderType.solid());
|
||||
|
||||
transformed(AllBlockPartials.ENGINE_PISTON, blockState, facing, roll90)
|
||||
.translate(0, piston, 0)
|
||||
.light(light)
|
||||
.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)
|
||||
.unCentre()
|
||||
.translate(0, piston, 0)
|
||||
|
@ -61,21 +65,22 @@ public class SteamEngineRenderer extends SafeTileEntityRenderer<SteamEngineTileE
|
|||
.light(light)
|
||||
.renderInto(ms, vb);
|
||||
|
||||
transformed(AllBlockPartials.ENGINE_CONNECTOR, blockState, facing).rotateY(roll90 ? -90 : 0)
|
||||
.unCentre()
|
||||
.light(light)
|
||||
transformed(AllBlockPartials.ENGINE_CONNECTOR, blockState, facing, roll90)
|
||||
.translate(0, 2, 0)
|
||||
.centre()
|
||||
.rotateXRadians(-angle + Mth.HALF_PI)
|
||||
.unCentre()
|
||||
.light(light)
|
||||
.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)
|
||||
.centre()
|
||||
.rotateY(AngleHelper.horizontalAngle(facing))
|
||||
.rotateX(AngleHelper.verticalAngle(facing) + 90);
|
||||
.rotateX(AngleHelper.verticalAngle(facing) + 90)
|
||||
.rotateY(roll90 ? -90 : 0)
|
||||
.unCentre();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -120,8 +120,9 @@ public class FlwContraption extends ContraptionRenderInfo {
|
|||
}
|
||||
|
||||
public void invalidate() {
|
||||
for (ArrayModelRenderer buffer : renderLayers.values()) {
|
||||
buffer.delete();
|
||||
for (ArrayModelRenderer renderer : renderLayers.values()) {
|
||||
renderer.delete();
|
||||
renderer.getModel().delete();
|
||||
}
|
||||
renderLayers.clear();
|
||||
|
||||
|
|
|
@ -243,30 +243,21 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour {
|
|||
}
|
||||
|
||||
public enum BottomlessFluidMode implements Predicate<Fluid> {
|
||||
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<Fluid> predicate;
|
||||
|
||||
BottomlessFluidMode(Predicate<Fluid> predicate) {
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Fluid fluid) {
|
||||
return predicate.test(fluid);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
"ContraptionDriverInteractMixin",
|
||||
"CustomItemUseEffectsMixin",
|
||||
"MapItemSavedDataMixin",
|
||||
"ContraptionDriverInteractMixin",
|
||||
"accessor.AbstractProjectileDispenseBehaviorAccessor",
|
||||
"accessor.DispenserBlockAccessor",
|
||||
"accessor.FallingBlockEntityAccessor",
|
||||
|
|
Loading…
Reference in a new issue