Updates to the Bogey API (#4875)

- Provided bogey data during model initialisation and patched other oversights in BogeyRenderer
- Refactored method names in BogeyRenderer
- Implemented interface for interactions with custom bogey blocks
- Implemented wrapper record for bogey model data
This commit is contained in:
Rabbitminers 2023-07-03 17:08:54 +01:00 committed by GitHub
parent d16b3ebe34
commit 4d7b64db49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 202 additions and 103 deletions

View File

@ -187,7 +187,7 @@ public abstract class AbstractBogeyBlock<T extends AbstractBogeyBlockEntity> ext
} }
@Override @Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, public final InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand,
BlockHitResult hit) { BlockHitResult hit) {
if (level.isClientSide) if (level.isClientSide)
return InteractionResult.PASS; return InteractionResult.PASS;
@ -239,6 +239,12 @@ public abstract class AbstractBogeyBlock<T extends AbstractBogeyBlockEntity> ext
return InteractionResult.CONSUME; return InteractionResult.CONSUME;
} }
return onInteractWithBogey(state, level, pos, player, hand, hit);
}
// Allows for custom interactions with bogey block to be added simply
protected InteractionResult onInteractWithBogey(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand,
BlockHitResult hit) {
return InteractionResult.PASS; return InteractionResult.PASS;
} }
@ -249,7 +255,6 @@ public abstract class AbstractBogeyBlock<T extends AbstractBogeyBlockEntity> ext
return BOGEYS; return BOGEYS;
} }
@Override @Override
public BlockState getRotatedBlockState(BlockState state, Direction targetedFace) { public BlockState getRotatedBlockState(BlockState state, Direction targetedFace) {
Block block = state.getBlock(); Block block = state.getBlock();

View File

@ -4,6 +4,8 @@ import com.jozufozu.flywheel.api.MaterialManager;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.simibubi.create.content.trains.entity.CarriageBogey;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
public class BackupBogeyRenderer extends BogeyRenderer.CommonRenderer { public class BackupBogeyRenderer extends BogeyRenderer.CommonRenderer {
@ -15,7 +17,7 @@ public class BackupBogeyRenderer extends BogeyRenderer.CommonRenderer {
} }
@Override @Override
public void initialiseContraptionModelData(MaterialManager materialManager) { public void initialiseContraptionModelData(MaterialManager materialManager, CarriageBogey carriageBogey) {
} }
} }

View File

@ -30,8 +30,8 @@ public final class BogeyInstance {
this.renderer = this.style.createRendererInstance(this.size); this.renderer = this.style.createRendererInstance(this.size);
this.commonRenderer = this.style.getNewCommonRenderInstance(); this.commonRenderer = this.style.getNewCommonRenderInstance();
commonRenderer.ifPresent(bogeyRenderer -> bogeyRenderer.initialiseContraptionModelData(materialManager)); commonRenderer.ifPresent(bogeyRenderer -> bogeyRenderer.initialiseContraptionModelData(materialManager, bogey));
renderer.initialiseContraptionModelData(materialManager); renderer.initialiseContraptionModelData(materialManager, bogey);
} }
public void beginFrame(float wheelAngle, PoseStack ms) { public void beginFrame(float wheelAngle, PoseStack ms) {

View File

@ -4,6 +4,12 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.stream.IntStream;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
import com.mojang.math.Quaternion;
import com.simibubi.create.content.trains.entity.CarriageBogey;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -23,8 +29,15 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
/**
* This is a port of the bogey api from Extended Bogeys, If you are looking to implement your own bogeys you can find some helpful resources below:
* <p>
* - <a href="https://github.com/Rabbitminers/Extended-Bogeys/tree/1.18/multiloader/dev/common/src/main/java/com/rabbitminers/extendedbogeys/bogeys/styles">Extended Bogeys (Examples)</a>
* - <a href="https://github.com/Rabbitminers/Extended-Bogeys/blob/1.18/multiloader/dev/API_DOCS.md">Extended Bogeys (API documentation)</a>
* - <a href="https://github.com/Layers-of-Railways/Railway/tree/93e318d1e922b1e992b89b0aceef85a2d545f370/common/src/main/java/com/railwayteam/railways/content/custom_bogeys">Steam n' Rails (Examples)</a>
*/
public abstract class BogeyRenderer { public abstract class BogeyRenderer {
Map<String, ModelData[]> contraptionModelData = new HashMap<>(); Map<String, BogeyModelData[]> contraptionModelData = new HashMap<>();
/** /**
* A common interface for getting transform data for both in-world and in-contraption model data safely from a * A common interface for getting transform data for both in-world and in-contraption model data safely from a
@ -36,7 +49,7 @@ public abstract class BogeyRenderer {
* @param size The amount of models needed * @param size The amount of models needed
* @return A generic transform which can be used for both in-world and in-contraption models * @return A generic transform which can be used for both in-world and in-contraption models
*/ */
public Transform<?>[] getTransformsFromPartial(PartialModel model, PoseStack ms, boolean inInstancedContraption, int size) { public BogeyModelData[] getTransform(PartialModel model, PoseStack ms, boolean inInstancedContraption, int size) {
return (inInstancedContraption) ? transformContraptionModelData(keyFromModel(model), ms) : createModelData(model, size); return (inInstancedContraption) ? transformContraptionModelData(keyFromModel(model), ms) : createModelData(model, size);
} }
@ -50,10 +63,37 @@ public abstract class BogeyRenderer {
* @param size The amount of models needed * @param size The amount of models needed
* @return A generic transform which can be used for both in-world and in-contraption models * @return A generic transform which can be used for both in-world and in-contraption models
*/ */
public Transform<?>[] getTransformsFromBlockState(BlockState state, PoseStack ms, boolean inContraption, int size) { public BogeyModelData[] getTransform(BlockState state, PoseStack ms, boolean inContraption, int size) {
return inContraption ? transformContraptionModelData(keyFromModel(state), ms) : createModelData(state, size); return inContraption ? transformContraptionModelData(keyFromModel(state), ms) : createModelData(state, size);
} }
/**
* Helper function to collect or create a single model from a partial model used for both in-world and
* in-contraption rendering
*
* @param model The key of the model to be collected or instantiated
* @param ms Posestack to bind the model to if it is within a contraption
* @param inInstancedContraption Type of rendering required
* @return A generic transform which can be used for both in-world and in-contraption models
*/
public BogeyModelData getTransform(PartialModel model, PoseStack ms, boolean inInstancedContraption) {
return inInstancedContraption ? contraptionModelData.get(keyFromModel(model))[0].setTransform(ms)
: BogeyModelData.from(model);
}
/**
* A common interface for getting transform data for blockstates, for a single model
*
* @param state The state of the model to be collected or instantiated
* @param ms Posestack to bind the model to if it is within a contraption
* @param inContraption Type of model required
* @return A generic transform which can be used for both in-world and in-contraption models
*/
public BogeyModelData getTransform(BlockState state, PoseStack ms, boolean inContraption) {
return (inContraption) ? contraptionModelData.get(keyFromModel(state))[0].setTransform(ms)
: BogeyModelData.from(state);
}
/** /**
* Used for calling both in-world and in-contraption rendering * Used for calling both in-world and in-contraption rendering
* *
@ -64,7 +104,8 @@ public abstract class BogeyRenderer {
* @param vb (Optional) Vertex Consumer used for in-world rendering * @param vb (Optional) Vertex Consumer used for in-world rendering
*/ */
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public abstract void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption); public abstract void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light,
VertexConsumer vb, boolean inContraption);
/** /**
* Used for calling in-contraption rendering ensuring that falsey data is handled correctly * Used for calling in-contraption rendering ensuring that falsey data is handled correctly
@ -88,8 +129,8 @@ public abstract class BogeyRenderer {
* @param ms Posestack of the contraption to bind the model data to * @param ms Posestack of the contraption to bind the model data to
* @return A generic transform which can be used for both in-world and in-contraption models * @return A generic transform which can be used for both in-world and in-contraption models
*/ */
private Transform<?>[] transformContraptionModelData(String key, PoseStack ms) { private BogeyModelData[] transformContraptionModelData(String key, PoseStack ms) {
ModelData[] modelData = contraptionModelData.get(key); BogeyModelData[] modelData = contraptionModelData.get(key);
Arrays.stream(modelData).forEach(modelDataElement -> modelDataElement.setTransform(ms)); Arrays.stream(modelData).forEach(modelDataElement -> modelDataElement.setTransform(ms));
return modelData; return modelData;
} }
@ -103,9 +144,8 @@ public abstract class BogeyRenderer {
* @param size The Amount of models needed * @param size The Amount of models needed
* @return A generic transform which can be used for both in-world and in-contraption models * @return A generic transform which can be used for both in-world and in-contraption models
*/ */
private Transform<?>[] createModelData(PartialModel model, int size) { private BogeyModelData[] createModelData(PartialModel model, int size) {
BlockState air = Blocks.AIR.defaultBlockState(); BogeyModelData[] data = { BogeyModelData.from(model) };
SuperByteBuffer[] data = { CachedBufferer.partial(model, air) };
return expandArrayToLength(data, size); return expandArrayToLength(data, size);
} }
@ -117,8 +157,8 @@ public abstract class BogeyRenderer {
* @param size Amount of models needed * @param size Amount of models needed
* @return A generic transform which can be used for both in-world and in-contraption models * @return A generic transform which can be used for both in-world and in-contraption models
*/ */
private Transform<?>[] createModelData(BlockState state, int size) { private BogeyModelData[] createModelData(BlockState state, int size) {
SuperByteBuffer[] data = { CachedBufferer.block(state) }; BogeyModelData[] data = { BogeyModelData.from(state) };
return expandArrayToLength(data, size); return expandArrayToLength(data, size);
} }
@ -130,47 +170,20 @@ public abstract class BogeyRenderer {
* @param size Amount of models needed * @param size Amount of models needed
* @return A generic transform which can be used for both in-world and in-contraption models * @return A generic transform which can be used for both in-world and in-contraption models
*/ */
private Transform<?>[] expandArrayToLength(SuperByteBuffer[] data, int size) { private BogeyModelData[] expandArrayToLength(BogeyModelData[] data, int size) {
return Arrays.stream(Collections.nCopies(size, data).toArray()) return Arrays.stream(Collections.nCopies(size, data).toArray())
.flatMap(inner -> Arrays.stream((SuperByteBuffer[]) inner)) .flatMap(inner -> Arrays.stream((BogeyModelData[]) inner))
.toArray(SuperByteBuffer[]::new); .toArray(BogeyModelData[]::new);
}
/**
* Helper function to collect or create a single model from a partial model used for both in-world and
* in-contraption rendering
*
* @param model The key of the model to be collected or instantiated
* @param ms Posestack to bind the model to if it is within a contraption
* @param inInstancedContraption Type of rendering required
* @return A generic transform which can be used for both in-world and in-contraption models
*/
public Transform<?> getTransformFromPartial(PartialModel model, PoseStack ms, boolean inInstancedContraption) {
BlockState air = Blocks.AIR.defaultBlockState();
return inInstancedContraption ? contraptionModelData.get(keyFromModel(model))[0].setTransform(ms)
: CachedBufferer.partial(model, air);
}
/**
* A common interface for getting transform data for blockstates, for a single model
*
* @param state The state of the model to be collected or instantiated
* @param ms Posestack to bind the model to if it is within a contraption
* @param inContraption Type of model required
* @return A generic transform which can be used for both in-world and in-contraption models
*/
public Transform<?> getTransformFromBlockState(BlockState state, PoseStack ms, boolean inContraption) {
return (inContraption) ? contraptionModelData.get(keyFromModel(state))[0].setTransform(ms)
: CachedBufferer.block(state);
} }
/** /**
* Provides render implementations a point in setup to instantiate all model data to be needed * Provides render implementations a point in setup to instantiate all model data to be needed
* *
* @param materialManager The material manager * @param materialManager The material manager
* @param carriageBogey The bogey to create data for
*/ */
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public abstract void initialiseContraptionModelData(MaterialManager materialManager); public abstract void initialiseContraptionModelData(MaterialManager materialManager, CarriageBogey carriageBogey);
/** /**
* Creates instances of models for in-world rendering to a set length from a provided partial model * Creates instances of models for in-world rendering to a set length from a provided partial model
@ -179,10 +192,13 @@ public abstract class BogeyRenderer {
* @param model Partial model to be instanced * @param model Partial model to be instanced
* @param count Amount of models neeeded * @param count Amount of models neeeded
*/ */
public void createModelInstances(MaterialManager materialManager, PartialModel model, int count) { public void createModelInstance(MaterialManager materialManager, PartialModel model, int count) {
ModelData[] modelData = new ModelData[count]; BogeyModelData[] modelData = IntStream.range(0, count)
materialManager.defaultSolid().material(Materials.TRANSFORMED) .mapToObj(i -> materialManager.defaultSolid()
.getModel(model).createInstances(modelData); .material(Materials.TRANSFORMED)
.getModel(model).createInstance())
.map(BogeyModelData::new)
.toArray(BogeyModelData[]::new);
contraptionModelData.put(keyFromModel(model), modelData); contraptionModelData.put(keyFromModel(model), modelData);
} }
@ -193,10 +209,13 @@ public abstract class BogeyRenderer {
* @param state Blockstate of the model to be created * @param state Blockstate of the model to be created
* @param count Amount of models needed * @param count Amount of models needed
*/ */
public void createModelInstances(MaterialManager materialManager, BlockState state, int count) { public void createModelInstance(MaterialManager materialManager, BlockState state, int count) {
ModelData[] modelData = new ModelData[count]; BogeyModelData[] modelData = IntStream.range(0, count)
materialManager.defaultSolid().material(Materials.TRANSFORMED) .mapToObj(i -> materialManager.defaultSolid()
.getModel(state).createInstances(modelData); .material(Materials.TRANSFORMED)
.getModel(state).createInstance())
.map(BogeyModelData::new)
.toArray(BogeyModelData[]::new);
contraptionModelData.put(keyFromModel(state), modelData); contraptionModelData.put(keyFromModel(state), modelData);
} }
@ -204,10 +223,11 @@ public abstract class BogeyRenderer {
* Creates a single instance of models for in-contraption rendering from a provided blockstate * Creates a single instance of models for in-contraption rendering from a provided blockstate
* *
* @param materialManager The material manager * @param materialManager The material manager
* @param state Blockstate of the model to be created * @param states Blockstates of the models to be created
*/ */
public void createModelInstance(MaterialManager materialManager, BlockState state) { public void createModelInstance(MaterialManager materialManager, BlockState... states) {
this.createModelInstances(materialManager, state, 1); for (BlockState state : states)
this.createModelInstance(materialManager, state, 1);
} }
/** /**
@ -216,13 +236,14 @@ public abstract class BogeyRenderer {
* @param materialManager The material manager * @param materialManager The material manager
* @param models The type of model to create instances of * @param models The type of model to create instances of
*/ */
public void createModelInstances(MaterialManager materialManager, PartialModel... models) { public void createModelInstance(MaterialManager materialManager, PartialModel... models) {
for (PartialModel model : models) for (PartialModel model : models)
createModelInstances(materialManager, model, 1); createModelInstance(materialManager, model, 1);
} }
/** /**
* Handles scale for all model data and renders non contraption model data * This method is deprecated, use BogeyModelData#render instead, left in
* to avoid existing usages from crashing
* *
* @param b The model data itself * @param b The model data itself
* @param ms Pose stack to render to * @param ms Pose stack to render to
@ -231,6 +252,7 @@ public abstract class BogeyRenderer {
* @param <B> Generic alias for both contraption and in-world model data * @param <B> Generic alias for both contraption and in-world model data
*/ */
@Deprecated
public static <B extends Transform<?>> void finalize(B b, PoseStack ms, int light, @Nullable VertexConsumer vb) { public static <B extends Transform<?>> void finalize(B b, PoseStack ms, int light, @Nullable VertexConsumer vb) {
b.scale(1 - 1/512f); b.scale(1 - 1/512f);
if (b instanceof SuperByteBuffer byteBuf && vb != null) if (b instanceof SuperByteBuffer byteBuf && vb != null)
@ -243,8 +265,8 @@ public abstract class BogeyRenderer {
*/ */
public void emptyTransforms() { public void emptyTransforms() {
for (ModelData[] data : contraptionModelData.values()) for (BogeyModelData[] data : contraptionModelData.values())
for (ModelData model : data) for (BogeyModelData model : data)
model.setEmptyTransform(); model.setEmptyTransform();
} }
@ -256,9 +278,9 @@ public abstract class BogeyRenderer {
*/ */
public void updateLight(int blockLight, int skyLight) { public void updateLight(int blockLight, int skyLight) {
for (ModelData[] data : contraptionModelData.values()) for (BogeyModelData[] data : contraptionModelData.values())
for (ModelData model : data) for (BogeyModelData model : data)
model.setBlockLight(blockLight).setSkyLight(skyLight); model.updateLight(blockLight, skyLight);
} }
/** /**
@ -267,8 +289,8 @@ public abstract class BogeyRenderer {
*/ */
public void remove() { public void remove() {
for (ModelData[] data : contraptionModelData.values()) for (BogeyModelData[] data : contraptionModelData.values())
for (ModelData model : data) for (BogeyModelData model : data)
model.delete(); model.delete();
contraptionModelData.clear(); contraptionModelData.clear();
} }
@ -301,4 +323,73 @@ public abstract class BogeyRenderer {
return null; return null;
} }
} }
public record BogeyModelData(Transform<?> transform) implements Transform<BogeyModelData> {
public static BogeyModelData from(PartialModel model) {
BlockState air = Blocks.AIR.defaultBlockState();
return new BogeyModelData(CachedBufferer.partial(model, air));
}
public static BogeyModelData from(BlockState model) {
return new BogeyModelData(CachedBufferer.block(model));
}
public void render(PoseStack ms, int light, @Nullable VertexConsumer vb) {
transform.scale(1 - 1/512f);
if (transform instanceof SuperByteBuffer byteBuf && vb != null)
byteBuf.light(light).renderInto(ms, vb);
}
public BogeyModelData setTransform(PoseStack ms) {
if (this.transform instanceof ModelData model)
model.setTransform(ms);
return this;
}
public BogeyModelData setEmptyTransform() {
if (this.transform instanceof ModelData model)
model.setEmptyTransform();
return this;
}
public BogeyModelData delete() {
if (this.transform instanceof ModelData model)
model.delete();
return this;
}
public BogeyModelData updateLight(int blockLight, int skyLight) {
if (this.transform instanceof ModelData model)
model.setBlockLight(blockLight).setSkyLight(skyLight);
return this;
}
@Override
public BogeyModelData mulPose(Matrix4f pose) {
this.transform.mulPose(pose);
return this;
}
@Override
public BogeyModelData mulNormal(Matrix3f normal) {
this.transform.mulNormal(normal);
return this;
}
@Override
public BogeyModelData multiply(Quaternion quaternion) {
this.transform.multiply(quaternion);
return this;
}
@Override
public BogeyModelData scale(float factorX, float factorY, float factorZ) {
this.transform.scale(factorX, factorY, factorZ);
return this;
}
@Override
public BogeyModelData translate(double x, double y, double z) {
this.transform.translate(x, y, z);
return this;
}
}
} }

View File

@ -13,6 +13,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.kinetics.simpleRelays.ShaftBlock; import com.simibubi.create.content.kinetics.simpleRelays.ShaftBlock;
import com.simibubi.create.content.trains.entity.CarriageBogey;
import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Iterate;
@ -22,22 +23,22 @@ import net.minecraft.nbt.CompoundTag;
public class StandardBogeyRenderer { public class StandardBogeyRenderer {
public static class CommonStandardBogeyRenderer extends BogeyRenderer.CommonRenderer { public static class CommonStandardBogeyRenderer extends BogeyRenderer.CommonRenderer {
@Override @Override
public void initialiseContraptionModelData(MaterialManager materialManager) { public void initialiseContraptionModelData(MaterialManager materialManager, CarriageBogey carriageBogey) {
createModelInstances(materialManager, AllBlocks.SHAFT.getDefaultState() createModelInstance(materialManager, AllBlocks.SHAFT.getDefaultState()
.setValue(ShaftBlock.AXIS, Direction.Axis.Z), 2); .setValue(ShaftBlock.AXIS, Direction.Axis.Z), 2);
} }
@Override @Override
public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) { public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
boolean inInstancedContraption = vb == null; boolean inInstancedContraption = vb == null;
Transform<?>[] shafts = getTransformsFromBlockState(AllBlocks.SHAFT.getDefaultState() BogeyModelData[] shafts = getTransform(AllBlocks.SHAFT.getDefaultState()
.setValue(ShaftBlock.AXIS, Direction.Axis.Z), ms, inInstancedContraption, 2); .setValue(ShaftBlock.AXIS, Direction.Axis.Z), ms, inInstancedContraption, 2);
for (int i : Iterate.zeroAndOne) { for (int i : Iterate.zeroAndOne) {
shafts[i].translate(-.5f, .25f, i * -1) shafts[i].translate(-.5f, .25f, i * -1)
.centre() .centre()
.rotateZ(wheelAngle) .rotateZ(wheelAngle)
.unCentre(); .unCentre()
finalize(shafts[i], ms, light, vb); .render(ms, light, vb);
} }
} }
} }
@ -45,9 +46,9 @@ public class StandardBogeyRenderer {
public static class SmallStandardBogeyRenderer extends BogeyRenderer { public static class SmallStandardBogeyRenderer extends BogeyRenderer {
@Override @Override
public void initialiseContraptionModelData(MaterialManager materialManager) { public void initialiseContraptionModelData(MaterialManager materialManager, CarriageBogey carriageBogey) {
createModelInstances(materialManager, SMALL_BOGEY_WHEELS, 2); createModelInstance(materialManager, SMALL_BOGEY_WHEELS, 2);
createModelInstances(materialManager, BOGEY_FRAME); createModelInstance(materialManager, BOGEY_FRAME);
} }
@ -59,17 +60,17 @@ public class StandardBogeyRenderer {
@Override @Override
public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) { public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
boolean inInstancedContraption = vb == null; boolean inInstancedContraption = vb == null;
Transform<?> transform = getTransformFromPartial(BOGEY_FRAME, ms, inInstancedContraption); getTransform(BOGEY_FRAME, ms, inInstancedContraption)
finalize(transform, ms, light, vb); .render(ms, light, vb);
Transform<?>[] wheels = getTransformsFromPartial(SMALL_BOGEY_WHEELS, ms, inInstancedContraption, 2); BogeyModelData[] wheels = getTransform(SMALL_BOGEY_WHEELS, ms, inInstancedContraption, 2);
for (int side : Iterate.positiveAndNegative) { for (int side : Iterate.positiveAndNegative) {
if (!inInstancedContraption) if (!inInstancedContraption)
ms.pushPose(); ms.pushPose();
Transform<?> wheel = wheels[(side + 1)/2]; wheels[(side + 1)/2]
wheel.translate(0, 12 / 16f, side) .translate(0, 12 / 16f, side)
.rotateX(wheelAngle); .rotateX(wheelAngle)
finalize(wheel, ms, light, vb); .render(ms, light, vb);
if (!inInstancedContraption) if (!inInstancedContraption)
ms.popPose(); ms.popPose();
} }
@ -78,9 +79,9 @@ public class StandardBogeyRenderer {
public static class LargeStandardBogeyRenderer extends BogeyRenderer { public static class LargeStandardBogeyRenderer extends BogeyRenderer {
@Override @Override
public void initialiseContraptionModelData(MaterialManager materialManager) { public void initialiseContraptionModelData(MaterialManager materialManager, CarriageBogey carriageBogey) {
createModelInstances(materialManager, LARGE_BOGEY_WHEELS, BOGEY_DRIVE, BOGEY_PISTON, BOGEY_PIN); createModelInstance(materialManager, LARGE_BOGEY_WHEELS, BOGEY_DRIVE, BOGEY_PISTON, BOGEY_PIN);
createModelInstances(materialManager, AllBlocks.SHAFT.getDefaultState() createModelInstance(materialManager, AllBlocks.SHAFT.getDefaultState()
.setValue(ShaftBlock.AXIS, Direction.Axis.X), 2); .setValue(ShaftBlock.AXIS, Direction.Axis.X), 2);
} }
@ -93,39 +94,39 @@ public class StandardBogeyRenderer {
public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) { public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
boolean inInstancedContraption = vb == null; boolean inInstancedContraption = vb == null;
Transform<?>[] secondaryShafts = getTransformsFromBlockState(AllBlocks.SHAFT.getDefaultState() BogeyModelData[] secondaryShafts = getTransform(AllBlocks.SHAFT.getDefaultState()
.setValue(ShaftBlock.AXIS, Direction.Axis.X), ms, inInstancedContraption, 2); .setValue(ShaftBlock.AXIS, Direction.Axis.X), ms, inInstancedContraption, 2);
for (int i : Iterate.zeroAndOne) { for (int i : Iterate.zeroAndOne) {
Transform<?> secondShaft = secondaryShafts[i]; secondaryShafts[i]
secondShaft.translate(-.5f, .25f, .5f + i * -2) .translate(-.5f, .25f, .5f + i * -2)
.centre() .centre()
.rotateX(wheelAngle) .rotateX(wheelAngle)
.unCentre(); .unCentre()
finalize(secondShaft, ms, light, vb); .render(ms, light, vb);
} }
Transform<?> bogeyDrive = getTransformFromPartial(BOGEY_DRIVE, ms, inInstancedContraption); getTransform(BOGEY_DRIVE, ms, inInstancedContraption)
finalize(bogeyDrive, ms, light, vb); .render(ms, light, vb);
Transform<?> bogeyPiston = getTransformFromPartial(BOGEY_PISTON, ms, inInstancedContraption) getTransform(BOGEY_PISTON, ms, inInstancedContraption)
.translate(0, 0, 1 / 4f * Math.sin(AngleHelper.rad(wheelAngle))); .translate(0, 0, 1 / 4f * Math.sin(AngleHelper.rad(wheelAngle)))
finalize(bogeyPiston, ms, light, vb); .render(ms, light, vb);
if (!inInstancedContraption) if (!inInstancedContraption)
ms.pushPose(); ms.pushPose();
Transform<?> bogeyWheels = getTransformFromPartial(LARGE_BOGEY_WHEELS, ms, inInstancedContraption) getTransform(LARGE_BOGEY_WHEELS, ms, inInstancedContraption)
.translate(0, 1, 0) .translate(0, 1, 0)
.rotateX(wheelAngle); .rotateX(wheelAngle)
finalize(bogeyWheels, ms, light, vb); .render(ms, light, vb);
Transform<?> bogeyPin = getTransformFromPartial(BOGEY_PIN, ms, inInstancedContraption) getTransform(BOGEY_PIN, ms, inInstancedContraption)
.translate(0, 1, 0) .translate(0, 1, 0)
.rotateX(wheelAngle) .rotateX(wheelAngle)
.translate(0, 1 / 4f, 0) .translate(0, 1 / 4f, 0)
.rotateX(-wheelAngle); .rotateX(-wheelAngle)
finalize(bogeyPin, ms, light, vb); .render(ms, light, vb);
if (!inInstancedContraption) if (!inInstancedContraption)
ms.popPose(); ms.popPose();