Linked Style Registry To Bogey Blocks

This commit is contained in:
Rabbitminers 2023-04-01 18:39:58 +01:00
parent 71f839ee51
commit 0c0b5a1ed6
12 changed files with 119 additions and 37 deletions

View file

@ -1,6 +1,7 @@
package com.simibubi.create; package com.simibubi.create;
import com.simibubi.create.content.logistics.trains.BogeyRenderer; import com.simibubi.create.content.logistics.trains.BogeyRenderer;
import com.simibubi.create.content.logistics.trains.StandardBogeyRenderer;
import com.simibubi.create.content.logistics.trains.entity.BogeyStyle; import com.simibubi.create.content.logistics.trains.entity.BogeyStyle;
import com.simibubi.create.content.logistics.trains.entity.StandardBogeyInstance; import com.simibubi.create.content.logistics.trains.entity.StandardBogeyInstance;
import com.tterrag.registrate.util.entry.RegistryEntry; import com.tterrag.registrate.util.entry.RegistryEntry;
@ -12,9 +13,10 @@ import static com.simibubi.create.Create.REGISTRATE;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class AllBogeyStyles { public class AllBogeyStyles {
public static final RegistryEntry<BogeyStyle> STANDARD = REGISTRATE public static final RegistryEntry<BogeyStyle> STANDARD = REGISTRATE
.bogeyStyle("standard", new BogeyStyle()) .bogeyStyle("standard", new BogeyStyle(StandardBogeyInstance.getInstanceFactory()))
.block(BogeyRenderer.BogeySize.SMALL, AllBlocks.SMALL_BOGEY) .block(BogeyRenderer.BogeySize.SMALL, AllBlocks.SMALL_BOGEY)
.block(BogeyRenderer.BogeySize.LARGE, AllBlocks.LARGE_BOGEY) .block(BogeyRenderer.BogeySize.LARGE, AllBlocks.LARGE_BOGEY)
.renderer(new StandardBogeyRenderer())
.register(); .register();
public static void register() { public static void register() {

View file

@ -13,6 +13,8 @@ import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Vector3f; import com.mojang.math.Vector3f;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllBogeyStyles;
import com.simibubi.create.AllRegistries;
import com.simibubi.create.AllTileEntities; import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.wrench.IWrenchable; import com.simibubi.create.content.contraptions.wrench.IWrenchable;
import com.simibubi.create.content.logistics.trains.entity.BogeyStyle; import com.simibubi.create.content.logistics.trains.entity.BogeyStyle;
@ -21,6 +23,7 @@ import com.simibubi.create.content.schematics.ISpecialBlockItemRequirement;
import com.simibubi.create.content.schematics.ItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement;
import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.block.ProperWaterloggedBlock; import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
import com.simibubi.create.foundation.utility.NBTHelper;
import com.simibubi.create.foundation.utility.RegisteredObjects; import com.simibubi.create.foundation.utility.RegisteredObjects;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
@ -98,8 +101,8 @@ public abstract class AbstractBogeyBlock extends Block implements ITE<StandardBo
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void render(@Nullable BlockState state, float wheelAngle, PoseStack ms, float partialTicks, public void render(@Nullable BlockState state, float wheelAngle, PoseStack ms, float partialTicks,
MultiBufferSource buffers, int light, int overlay, CompoundTag bogeyData) { MultiBufferSource buffers, int light, int overlay, StandardBogeyTileEntity sbte) {
final BogeyRenderer renderer = getStyle().renderer; final BogeyRenderer renderer = getStyle(sbte).renderer;
if (state != null) { if (state != null) {
ms.translate(.5f, .5f, .5f); ms.translate(.5f, .5f, .5f);
if (state.getValue(AXIS) == Direction.Axis.X) if (state.getValue(AXIS) == Direction.Axis.X)
@ -107,7 +110,7 @@ public abstract class AbstractBogeyBlock extends Block implements ITE<StandardBo
} }
ms.translate(0, -1.5 - 1 / 128f, 0); ms.translate(0, -1.5 - 1 / 128f, 0);
VertexConsumer vb = buffers.getBuffer(RenderType.cutoutMipped()); VertexConsumer vb = buffers.getBuffer(RenderType.cutoutMipped());
renderer.render(bogeyData, wheelAngle, ms, light, vb, getSize()); renderer.render(sbte.bogeyData, wheelAngle, ms, light, vb, getSize());
} }
public abstract BogeyRenderer.BogeySize getSize(); public abstract BogeyRenderer.BogeySize getSize();
@ -168,11 +171,8 @@ public abstract class AbstractBogeyBlock extends Block implements ITE<StandardBo
return new ItemRequirement(ItemRequirement.ItemUseType.CONSUME, AllBlocks.RAILWAY_CASING.asStack()); return new ItemRequirement(ItemRequirement.ItemUseType.CONSUME, AllBlocks.RAILWAY_CASING.asStack());
} }
public CompoundTag getBogeyData(@NotNull Level level, BlockPos pos) { public BogeyStyle getStyle(StandardBogeyTileEntity sbte) {
BlockEntity te = level.getBlockEntity(pos); sbte.setBogeyStyle(AllBogeyStyles.STANDARD.get());
if (te == null) return new CompoundTag(); return AllBogeyStyles.STANDARD.get();
return te.getTileData();
} }
public abstract BogeyStyle getStyle();
} }

View file

@ -17,11 +17,11 @@ public class BogeyTileEntityRenderer<T extends BlockEntity> extends SafeTileEnti
protected void renderSafe(T te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, protected void renderSafe(T te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light,
int overlay) { int overlay) {
BlockState blockState = te.getBlockState(); BlockState blockState = te.getBlockState();
float angle = 0; if (te instanceof StandardBogeyTileEntity sbte) {
if (te instanceof StandardBogeyTileEntity sbte) float angle = sbte.getVirtualAngle(partialTicks);
angle = sbte.getVirtualAngle(partialTicks); if (blockState.getBlock() instanceof AbstractBogeyBlock bogey)
if (blockState.getBlock()instanceof AbstractBogeyBlock bogey) bogey.render(blockState, angle, ms, partialTicks, buffer, light, overlay, sbte);
bogey.render(blockState, angle, ms, partialTicks, buffer, light, overlay, te.getTileData()); }
} }
} }

View file

@ -39,8 +39,6 @@ public abstract class BogeyInstance {
renderer.initialiseContraptionModelData(materialManager, size); renderer.initialiseContraptionModelData(materialManager, size);
} }
public abstract BogeyInstanceFactory getInstanceFactory();
protected void hiddenFrame() { protected void hiddenFrame() {
beginFrame(0, null); beginFrame(0, null);
} }

View file

@ -22,12 +22,16 @@ import java.util.stream.Stream;
public final class BogeyStyle extends ForgeRegistryEntry<BogeyStyle> implements IForgeRegistryEntry<BogeyStyle> { public final class BogeyStyle extends ForgeRegistryEntry<BogeyStyle> implements IForgeRegistryEntry<BogeyStyle> {
public Map<BogeySize, ResourceLocation> blocks = new EnumMap<>(BogeySize.class); public Map<BogeySize, ResourceLocation> blocks = new EnumMap<>(BogeySize.class);
public BogeyInstance.BogeyInstanceFactory instance; public BogeyInstance.BogeyInstanceFactory instanceFactory;
public Component displayName; public Component displayName;
public SoundType soundType; public SoundType soundType;
public CompoundTag defaultData; public CompoundTag defaultData;
public BogeyRenderer renderer; public BogeyRenderer renderer;
public BogeyStyle(BogeyInstance.BogeyInstanceFactory factory) {
this.instanceFactory = factory;
}
public <T extends AbstractBogeyBlock> void addBlockForSize(BogeySize size, T block) { public <T extends AbstractBogeyBlock> void addBlockForSize(BogeySize size, T block) {
this.addBlockForSize(size, block.getRegistryName()); this.addBlockForSize(size, block.getRegistryName());
} }
@ -55,6 +59,6 @@ public final class BogeyStyle extends ForgeRegistryEntry<BogeyStyle> implements
} }
public BogeyInstance createInstance(CarriageBogey bogey, BogeySize size, MaterialManager materialManager) { public BogeyInstance createInstance(CarriageBogey bogey, BogeySize size, MaterialManager materialManager) {
return instance.create(bogey, size, materialManager); return instanceFactory.create(bogey, size, materialManager);
} }
} }

View file

@ -3,6 +3,8 @@ package com.simibubi.create.content.logistics.trains.entity;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.jozufozu.flywheel.api.MaterialManager; import com.jozufozu.flywheel.api.MaterialManager;
import com.simibubi.create.AllBogeyStyles;
import com.simibubi.create.AllRegistries;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.content.logistics.trains.DimensionPalette; import com.simibubi.create.content.logistics.trains.DimensionPalette;
import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock; import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock;
@ -10,6 +12,7 @@ import com.simibubi.create.content.logistics.trains.TrackGraph;
import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.Couple;
import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.NBTHelper;
import com.simibubi.create.foundation.utility.RegisteredObjects; import com.simibubi.create.foundation.utility.RegisteredObjects;
import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.foundation.utility.animation.LerpedFloat;
@ -25,12 +28,16 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;
public class CarriageBogey { public class CarriageBogey {
public Carriage carriage; public Carriage carriage;
boolean isLeading; boolean isLeading;
public BogeyStyle style = AllBogeyStyles.STANDARD.get();
public CompoundTag bogeyData;
AbstractBogeyBlock type; AbstractBogeyBlock type;
Couple<TravellingPoint> points; Couple<TravellingPoint> points;
@ -42,7 +49,14 @@ public class CarriageBogey {
int derailAngle; int derailAngle;
public CarriageBogey(AbstractBogeyBlock type, TravellingPoint point, TravellingPoint point2) { public static CarriageBogey fromLocation(AbstractBogeyBlock type, ResourceLocation style, TravellingPoint point, TravellingPoint point2) {
BogeyStyle bogeyStyle = AllRegistries.BOGEY_REGISTRY.get().getValue(style);
return new CarriageBogey(type, bogeyStyle, point, point2);
}
public CarriageBogey(AbstractBogeyBlock type, BogeyStyle style, TravellingPoint point, TravellingPoint point2) {
if (style != null)
this.style = style;
this.type = type; this.type = type;
points = Couple.create(point, point2); points = Couple.create(point, point2);
wheelAngle = LerpedFloat.angular(); wheelAngle = LerpedFloat.angular();
@ -150,6 +164,8 @@ public class CarriageBogey {
tag.putString("Type", RegisteredObjects.getKeyOrThrow((Block) type) tag.putString("Type", RegisteredObjects.getKeyOrThrow((Block) type)
.toString()); .toString());
tag.put("Points", points.serializeEach(tp -> tp.write(dimensions))); tag.put("Points", points.serializeEach(tp -> tp.write(dimensions)));
if (style.getRegistryName() != null)
NBTHelper.writeResourceLocation(tag, "bogeyStyle", style.getRegistryName());
return tag; return tag;
} }
@ -158,12 +174,12 @@ public class CarriageBogey {
AbstractBogeyBlock type = (AbstractBogeyBlock) ForgeRegistries.BLOCKS.getValue(location); AbstractBogeyBlock type = (AbstractBogeyBlock) ForgeRegistries.BLOCKS.getValue(location);
Couple<TravellingPoint> points = Couple.deserializeEach(tag.getList("Points", Tag.TAG_COMPOUND), Couple<TravellingPoint> points = Couple.deserializeEach(tag.getList("Points", Tag.TAG_COMPOUND),
c -> TravellingPoint.read(c, graph, dimensions)); c -> TravellingPoint.read(c, graph, dimensions));
CarriageBogey carriageBogey = new CarriageBogey(type, points.getFirst(), points.getSecond()); ResourceLocation styleLocation = NBTHelper.readResourceLocation(tag,"bogeyStyle");
return carriageBogey; return CarriageBogey.fromLocation(type, styleLocation, points.getFirst(), points.getSecond());
} }
public BogeyInstance createInstance(MaterialManager materialManager) { public BogeyInstance createInstance(MaterialManager materialManager) {
return type.getStyle().createInstance(this, type.getSize(), materialManager); return style.createInstance(this, type.getSize(), materialManager);
} }
void setLeading() { void setLeading() {

View file

@ -7,6 +7,8 @@ import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionEntityRenderer;
import com.simibubi.create.content.logistics.trains.track.StandardBogeyTileEntity;
import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.culling.Frustum; import net.minecraft.client.renderer.culling.Frustum;
@ -69,7 +71,7 @@ public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer
BlockEntity be = entity.getContraption().presentTileEntities.get(bogeyPos); BlockEntity be = entity.getContraption().presentTileEntities.get(bogeyPos);
bogey.type.render(null, bogey.wheelAngle.getValue(partialTicks), ms, partialTicks, buffers, light, bogey.type.render(null, bogey.wheelAngle.getValue(partialTicks), ms, partialTicks, buffers, light,
overlay, be.getTileData()); overlay, (StandardBogeyTileEntity) be);
ms.popPose(); ms.popPose();
} }

View file

@ -18,8 +18,7 @@ public class StandardBogeyInstance extends BogeyInstance {
return new StandardBogeyInstance(bogey, BogeyRenderer.BogeySize.SMALL, materialManager); return new StandardBogeyInstance(bogey, BogeyRenderer.BogeySize.SMALL, materialManager);
} }
@Override public static BogeyInstanceFactory getInstanceFactory() {
public BogeyInstanceFactory getInstanceFactory() {
return StandardBogeyInstance::new; return StandardBogeyInstance::new;
} }
} }

View file

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.simibubi.create.AllRegistries;
import com.simibubi.create.CreateClient; import com.simibubi.create.CreateClient;
import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock; import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock;
import com.simibubi.create.foundation.networking.SimplePacketBase; import com.simibubi.create.foundation.networking.SimplePacketBase;
@ -15,10 +16,13 @@ import com.simibubi.create.foundation.utility.RegisteredObjects;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraftforge.network.NetworkEvent.Context; import net.minecraftforge.network.NetworkEvent.Context;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nullable;
public class TrainPacket extends SimplePacketBase { public class TrainPacket extends SimplePacketBase {
UUID trainId; UUID trainId;
@ -44,11 +48,12 @@ public class TrainPacket extends SimplePacketBase {
int size = buffer.readVarInt(); int size = buffer.readVarInt();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Couple<CarriageBogey> bogies = Couple.create(null, null); Couple<CarriageBogey> bogies = Couple.create(null, null);
for (boolean first : Iterate.trueAndFalse) { for (boolean isFirst : Iterate.trueAndFalse) {
if (!first && !buffer.readBoolean()) if (!isFirst && !buffer.readBoolean())
continue; continue;
AbstractBogeyBlock type = (AbstractBogeyBlock) ForgeRegistries.BLOCKS.getValue(buffer.readResourceLocation()); AbstractBogeyBlock type = (AbstractBogeyBlock) ForgeRegistries.BLOCKS.getValue(buffer.readResourceLocation());
bogies.set(first, new CarriageBogey(type, new TravellingPoint(), new TravellingPoint())); BogeyStyle style = AllRegistries.BOGEY_REGISTRY.get().getValue(buffer.readResourceLocation());
bogies.set(isFirst, new CarriageBogey(type, style, new TravellingPoint(), new TravellingPoint()));
} }
int spacing = buffer.readVarInt(); int spacing = buffer.readVarInt();
carriages.add(new Carriage(bogies.getFirst(), bogies.getSecond(), spacing)); carriages.add(new Carriage(bogies.getFirst(), bogies.getSecond(), spacing));
@ -86,6 +91,7 @@ public class TrainPacket extends SimplePacketBase {
} }
CarriageBogey bogey = carriage.bogeys.get(first); CarriageBogey bogey = carriage.bogeys.get(first);
buffer.writeResourceLocation(RegisteredObjects.getKeyOrThrow((Block) bogey.type)); buffer.writeResourceLocation(RegisteredObjects.getKeyOrThrow((Block) bogey.type));
buffer.writeResourceLocation(RegisteredObjects.getKeyOrThrow(AllRegistries.BOGEY_REGISTRY.get(), bogey.style));
} }
buffer.writeVarInt(carriage.bogeySpacing); buffer.writeVarInt(carriage.bogeySpacing);
} }

View file

@ -31,6 +31,7 @@ import com.simibubi.create.content.logistics.trains.TrackNodeLocation.Discovered
import com.simibubi.create.content.logistics.trains.entity.Carriage; import com.simibubi.create.content.logistics.trains.entity.Carriage;
import com.simibubi.create.content.logistics.trains.entity.CarriageBogey; import com.simibubi.create.content.logistics.trains.entity.CarriageBogey;
import com.simibubi.create.content.logistics.trains.entity.CarriageContraption; import com.simibubi.create.content.logistics.trains.entity.CarriageContraption;
import com.simibubi.create.content.logistics.trains.entity.StandardBogeyInstance;
import com.simibubi.create.content.logistics.trains.entity.Train; import com.simibubi.create.content.logistics.trains.entity.Train;
import com.simibubi.create.content.logistics.trains.entity.TrainPacket; import com.simibubi.create.content.logistics.trains.entity.TrainPacket;
import com.simibubi.create.content.logistics.trains.entity.TravellingPoint; import com.simibubi.create.content.logistics.trains.entity.TravellingPoint;
@ -38,6 +39,7 @@ import com.simibubi.create.content.logistics.trains.management.edgePoint.EdgePoi
import com.simibubi.create.content.logistics.trains.management.edgePoint.TrackTargetingBehaviour; import com.simibubi.create.content.logistics.trains.management.edgePoint.TrackTargetingBehaviour;
import com.simibubi.create.content.logistics.trains.management.schedule.Schedule; import com.simibubi.create.content.logistics.trains.management.schedule.Schedule;
import com.simibubi.create.content.logistics.trains.management.schedule.ScheduleItem; import com.simibubi.create.content.logistics.trains.management.schedule.ScheduleItem;
import com.simibubi.create.content.logistics.trains.track.StandardBogeyTileEntity;
import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.advancement.AllAdvancements;
import com.simibubi.create.foundation.block.ProperWaterloggedBlock; import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;
@ -65,7 +67,9 @@ import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.BoundingBox;
@ -592,8 +596,10 @@ public class StationTileEntity extends SmartTileEntity implements ITransformable
} }
AbstractBogeyBlock typeOfFirstBogey = bogeyTypes[bogeyIndex]; AbstractBogeyBlock typeOfFirstBogey = bogeyTypes[bogeyIndex];
BlockPos firstBogeyPos = contraption.anchor;
StandardBogeyTileEntity firstBogeyTileEntity = (StandardBogeyTileEntity) level.getBlockEntity(firstBogeyPos);
CarriageBogey firstBogey = CarriageBogey firstBogey =
new CarriageBogey(typeOfFirstBogey, points.get(pointIndex), points.get(pointIndex + 1)); new CarriageBogey(typeOfFirstBogey, firstBogeyTileEntity.getStyle(), points.get(pointIndex), points.get(pointIndex + 1));
CarriageBogey secondBogey = null; CarriageBogey secondBogey = null;
BlockPos secondBogeyPos = contraption.getSecondBogeyPos(); BlockPos secondBogeyPos = contraption.getSecondBogeyPos();
int bogeySpacing = 0; int bogeySpacing = 0;
@ -605,10 +611,11 @@ public class StationTileEntity extends SmartTileEntity implements ITransformable
contraptions.size() + 1); contraptions.size() + 1);
return; return;
} }
StandardBogeyTileEntity secondBogeyTileEntity =
(StandardBogeyTileEntity) level.getBlockEntity(secondBogeyPos);
bogeySpacing = bogeyLocations[bogeyIndex + 1] - bogeyLocations[bogeyIndex]; bogeySpacing = bogeyLocations[bogeyIndex + 1] - bogeyLocations[bogeyIndex];
secondBogey = new CarriageBogey(bogeyTypes[bogeyIndex + 1], points.get(pointIndex + 2), secondBogey = new CarriageBogey(bogeyTypes[bogeyIndex + 1], secondBogeyTileEntity.getStyle(),
points.get(pointIndex + 3)); points.get(pointIndex + 2), points.get(pointIndex + 3));
bogeyIndex++; bogeyIndex++;
} else if (!typeOfFirstBogey.allowsSingleBogeyCarriage()) { } else if (!typeOfFirstBogey.allowsSingleBogeyCarriage()) {

View file

@ -1,20 +1,63 @@
package com.simibubi.create.content.logistics.trains.track; package com.simibubi.create.content.logistics.trains.track;
import com.simibubi.create.AllBogeyStyles;
import com.simibubi.create.AllRegistries;
import com.simibubi.create.content.contraptions.processing.BasinTileEntity;
import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock; import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock;
import com.simibubi.create.content.logistics.trains.entity.BogeyStyle;
import com.simibubi.create.foundation.tileEntity.CachedRenderBBTileEntity; import com.simibubi.create.foundation.tileEntity.CachedRenderBBTileEntity;
import com.simibubi.create.foundation.utility.NBTHelper;
import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.foundation.utility.animation.LerpedFloat;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
public class StandardBogeyTileEntity extends CachedRenderBBTileEntity { public class StandardBogeyTileEntity extends CachedRenderBBTileEntity {
private BogeyStyle style;
public CompoundTag bogeyData;
public StandardBogeyTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) { public StandardBogeyTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state); super(type, pos, state);
} }
public void setBogeyStyle(BogeyStyle style) {
this.style = style;
markUpdated();
}
public BogeyStyle getStyle() {
return this.style;
}
@Override
protected void saveAdditional(CompoundTag pTag) {
if (style != null && style.getRegistryName() != null)
NBTHelper.writeResourceLocation(pTag, "bogeyStyle", style.getRegistryName());
if (bogeyData != null)
pTag.put("bogeyData", bogeyData);
super.saveAdditional(pTag);
}
@Override
public void load(CompoundTag pTag) {
if (pTag.contains("bogeyStyle")) {
ResourceLocation location = NBTHelper.readResourceLocation(pTag, "bogeyStyle");
this.style = AllRegistries.BOGEY_REGISTRY.get().getValue(location);
} else {
this.style = AllBogeyStyles.STANDARD.get();
}
if (pTag.contains("bogeyData"))
this.bogeyData = pTag.getCompound("bogeyData");
super.load(pTag);
}
@Override @Override
protected AABB createRenderBoundingBox() { protected AABB createRenderBoundingBox() {
return super.createRenderBoundingBox().inflate(2); return super.createRenderBoundingBox().inflate(2);
@ -36,4 +79,10 @@ public class StandardBogeyTileEntity extends CachedRenderBBTileEntity {
virtualAnimation.setValue(newWheelAngle); virtualAnimation.setValue(newWheelAngle);
} }
private void markUpdated() {
setChanged();
Level level = getLevel();
if (level != null)
getLevel().sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3);
}
} }

View file

@ -3,6 +3,7 @@ package com.simibubi.create.foundation.data;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllParticleTypes; import com.simibubi.create.AllParticleTypes;
import com.simibubi.create.AllRegistries; import com.simibubi.create.AllRegistries;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.content.logistics.trains.BogeyRenderer; import com.simibubi.create.content.logistics.trains.BogeyRenderer;
import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock; import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock;
import com.simibubi.create.content.logistics.trains.entity.BogeyStyle; import com.simibubi.create.content.logistics.trains.entity.BogeyStyle;
@ -34,7 +35,7 @@ import java.util.function.Supplier;
public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<BogeyStyle, T, P, BogeyStyleBuilder<T, P>> { public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<BogeyStyle, T, P, BogeyStyleBuilder<T, P>> {
private final T style; private final T style;
private NonNullSupplier<BogeyRenderer> renderer; private NonNullSupplier<BogeyRenderer> renderer;
private Supplier<SoundType> soundType; private Supplier<AllSoundEvents.SoundEntry> soundType;
private Supplier<CompoundTag> data; private Supplier<CompoundTag> data;
private Supplier<ParticleType<?>> particles; private Supplier<ParticleType<?>> particles;
@ -62,7 +63,6 @@ public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<
} }
public BogeyStyleBuilder<T, P> soundType(SoundType soundEntry) { public BogeyStyleBuilder<T, P> soundType(SoundType soundEntry) {
this.soundType = () -> soundEntry;
return this; return this;
} }
@ -82,7 +82,6 @@ public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<
@Override @Override
protected @NotNull T createEntry() { protected @NotNull T createEntry() {
style.soundType = soundType.get();
style.defaultData = data.get(); style.defaultData = data.get();
style.renderer = renderer.get(); style.renderer = renderer.get();
return style; return style;