Fix up some problems

This commit is contained in:
techno-sam 2023-04-30 19:51:26 -07:00
parent 74d98a2ad5
commit e91753a33c
14 changed files with 140 additions and 111 deletions

View file

@ -5611,7 +5611,6 @@ ac265a674626e0e832330086fd18fe0be37fc327 data/create/recipes/weathered_copper_ti
2a2700b43614f86d3294726595cb28ed7dca4387 data/create/tags/blocks/brittle.json 2a2700b43614f86d3294726595cb28ed7dca4387 data/create/tags/blocks/brittle.json
d99d5c67bdffff60789a19bd51a5c5267c75e0a4 data/create/tags/blocks/casing.json d99d5c67bdffff60789a19bd51a5c5267c75e0a4 data/create/tags/blocks/casing.json
2b4c93e5a752ebf54217594766f30d8d60cb4343 data/create/tags/blocks/fan_transparent.json 2b4c93e5a752ebf54217594766f30d8d60cb4343 data/create/tags/blocks/fan_transparent.json
ad8fa04f7bbbafd70d0ce158af78a35e899301e2 data/create/tags/blocks/girdable_tracks.json
ee6d2b53d81f2bed492662b6c06f46c4f2b9ef9b data/create/tags/blocks/movable_empty_collider.json ee6d2b53d81f2bed492662b6c06f46c4f2b9ef9b data/create/tags/blocks/movable_empty_collider.json
6e5d3b2123fbb00e7f439c091623619502551bca data/create/tags/blocks/non_movable.json 6e5d3b2123fbb00e7f439c091623619502551bca data/create/tags/blocks/non_movable.json
10781e8cfcbb3486327aace3aa00e437fb44b331 data/create/tags/blocks/ore_override_stone.json 10781e8cfcbb3486327aace3aa00e437fb44b331 data/create/tags/blocks/ore_override_stone.json
@ -5619,7 +5618,6 @@ ee6d2b53d81f2bed492662b6c06f46c4f2b9ef9b data/create/tags/blocks/movable_empty_c
23eb7cf8abff36f85320c35c69b98fdb775c8ec9 data/create/tags/blocks/safe_nbt.json 23eb7cf8abff36f85320c35c69b98fdb775c8ec9 data/create/tags/blocks/safe_nbt.json
6cdeeac1689f7b5bfd9bc40b462143d8eaf3ad0b data/create/tags/blocks/seats.json 6cdeeac1689f7b5bfd9bc40b462143d8eaf3ad0b data/create/tags/blocks/seats.json
d063e12c9ef75f39518c6d129ea35d833464d547 data/create/tags/blocks/toolboxes.json d063e12c9ef75f39518c6d129ea35d833464d547 data/create/tags/blocks/toolboxes.json
ad8fa04f7bbbafd70d0ce158af78a35e899301e2 data/create/tags/blocks/tracks.json
9460e92c8e483446318b849abe7e6f52dcd4a269 data/create/tags/blocks/tree_attachments.json 9460e92c8e483446318b849abe7e6f52dcd4a269 data/create/tags/blocks/tree_attachments.json
50936b211d94167a35ec78c89954082a336b6269 data/create/tags/blocks/valve_handles.json 50936b211d94167a35ec78c89954082a336b6269 data/create/tags/blocks/valve_handles.json
eac71740fb12bdb38b5dfaa2268613d7ba82b809 data/create/tags/blocks/windmill_sails.json eac71740fb12bdb38b5dfaa2268613d7ba82b809 data/create/tags/blocks/windmill_sails.json

View file

@ -1501,7 +1501,7 @@ public class AllBlocks {
.transform(customItemModel()) .transform(customItemModel())
.register(); .register();
public static final BlockEntry<TrackBlock> TRACK = REGISTRATE.block("track", TrackMaterial.ANDESITE::create) public static final BlockEntry<TrackBlock> TRACK = REGISTRATE.block("track", TrackMaterial.ANDESITE::createBlock)
.initialProperties(Material.STONE) .initialProperties(Material.STONE)
.properties(p -> p.color(MaterialColor.METAL) .properties(p -> p.color(MaterialColor.METAL)
.strength(0.8F) .strength(0.8F)

View file

@ -193,6 +193,7 @@ import com.simibubi.create.content.logistics.trains.management.edgePoint.station
import com.simibubi.create.content.logistics.trains.management.edgePoint.station.StationTileEntity; import com.simibubi.create.content.logistics.trains.management.edgePoint.station.StationTileEntity;
import com.simibubi.create.content.logistics.trains.track.FakeTrackTileEntity; import com.simibubi.create.content.logistics.trains.track.FakeTrackTileEntity;
import com.simibubi.create.content.logistics.trains.track.StandardBogeyTileEntity; import com.simibubi.create.content.logistics.trains.track.StandardBogeyTileEntity;
import com.simibubi.create.content.logistics.trains.track.TrackBlock;
import com.simibubi.create.content.logistics.trains.track.TrackInstance; import com.simibubi.create.content.logistics.trains.track.TrackInstance;
import com.simibubi.create.content.logistics.trains.track.TrackRenderer; import com.simibubi.create.content.logistics.trains.track.TrackRenderer;
import com.simibubi.create.content.logistics.trains.track.TrackTileEntity; import com.simibubi.create.content.logistics.trains.track.TrackTileEntity;
@ -204,6 +205,8 @@ import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRendere
import com.tterrag.registrate.util.entry.BlockEntityEntry; import com.tterrag.registrate.util.entry.BlockEntityEntry;
import com.tterrag.registrate.util.entry.BlockEntry; import com.tterrag.registrate.util.entry.BlockEntry;
import com.tterrag.registrate.util.nullness.NonNullSupplier;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
public class AllTileEntities { public class AllTileEntities {
@ -785,7 +788,7 @@ public class AllTileEntities {
.tileEntity("track", TrackTileEntity::new) .tileEntity("track", TrackTileEntity::new)
.instance(() -> TrackInstance::new) .instance(() -> TrackInstance::new)
.renderer(() -> TrackRenderer::new) .renderer(() -> TrackRenderer::new)
.validBlocks(((BlockEntry<? extends Block>[]) TrackMaterial.allBlocks().toArray(new BlockEntry[0]))) .validBlocks((NonNullSupplier<? extends TrackBlock>[]) TrackMaterial.allBlocks().toArray(new NonNullSupplier[0]))
.register(); .register();
public static final BlockEntityEntry<FakeTrackTileEntity> FAKE_TRACK = REGISTRATE public static final BlockEntityEntry<FakeTrackTileEntity> FAKE_TRACK = REGISTRATE

View file

@ -15,7 +15,6 @@ import com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSe
import com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode; import com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode;
import com.simibubi.create.content.logistics.item.filter.FilterItem; import com.simibubi.create.content.logistics.item.filter.FilterItem;
import com.simibubi.create.content.logistics.item.filter.ItemAttribute; import com.simibubi.create.content.logistics.item.filter.ItemAttribute;
import com.simibubi.create.content.logistics.trains.IHasTrackMaterial;
import com.simibubi.create.content.logistics.trains.track.TrackPlacement.PlacementInfo; import com.simibubi.create.content.logistics.trains.track.TrackPlacement.PlacementInfo;
import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllGuiTextures;
import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.gui.element.GuiGameElement;
@ -106,7 +105,7 @@ public class BlueprintOverlayRenderer {
int tracks = info.requiredTracks; int tracks = info.requiredTracks;
while (tracks > 0) { while (tracks > 0) {
ingredients.add(Pair.of(((IHasTrackMaterial) info).getMaterial().getTrackBlock().asStack(Math.min(64, tracks)), info.hasRequiredTracks)); ingredients.add(Pair.of(new ItemStack(info.trackMaterial.getTrackBlock().get(), Math.min(64, tracks)), info.hasRequiredTracks));
tracks -= 64; tracks -= 64;
} }

View file

@ -24,6 +24,7 @@ import net.minecraft.util.Mth;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameRules; import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
@ -31,7 +32,7 @@ import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BezierConnection implements Iterable<BezierConnection.Segment>, IHasTrackMaterial { public class BezierConnection implements Iterable<BezierConnection.Segment> {
public Couple<BlockPos> tePositions; public Couple<BlockPos> tePositions;
public Couple<Vec3> starts; public Couple<Vec3> starts;
@ -73,7 +74,10 @@ public class BezierConnection implements Iterable<BezierConnection.Segment>, IHa
} }
private static boolean coupleEquals(Couple<?> a, Couple<?> b) { private static boolean coupleEquals(Couple<?> a, Couple<?> b) {
return (a.getFirst().equals(b.getFirst()) && a.getSecond().equals(b.getSecond())) || (a.getFirst() instanceof Vec3 aFirst && a.getSecond() instanceof Vec3 aSecond && b.getFirst() instanceof Vec3 bFirst && b.getSecond() instanceof Vec3 bSecond && aFirst.closerThan(bFirst, 1e-6) && aSecond.closerThan(bSecond, 1e-6)); return (a.getFirst().equals(b.getFirst()) && a.getSecond().equals(b.getSecond()))
|| (a.getFirst() instanceof Vec3 aFirst && a.getSecond() instanceof Vec3 aSecond
&& b.getFirst() instanceof Vec3 bFirst && b.getSecond() instanceof Vec3 bSecond
&& aFirst.closerThan(bFirst, 1e-6) && aSecond.closerThan(bSecond, 1e-6));
} }
public boolean equalsSansMaterial(BezierConnection other) { public boolean equalsSansMaterial(BezierConnection other) {
@ -318,7 +322,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment>, IHa
Inventory inv = player.getInventory(); Inventory inv = player.getInventory();
int tracks = getTrackItemCost(); int tracks = getTrackItemCost();
while (tracks > 0) { while (tracks > 0) {
inv.placeItemBackInInventory(getMaterial().getTrackBlock().asStack(Math.min(64, tracks))); inv.placeItemBackInInventory(new ItemStack(getMaterial().getTrackBlock().get(), Math.min(64, tracks)));
tracks -= 64; tracks -= 64;
} }
int girders = getGirderItemCost(); int girders = getGirderItemCost();
@ -346,7 +350,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment>, IHa
continue; continue;
Vec3 v = VecHelper.offsetRandomly(segment.position, level.random, .125f) Vec3 v = VecHelper.offsetRandomly(segment.position, level.random, .125f)
.add(origin); .add(origin);
ItemEntity entity = new ItemEntity(level, v.x, v.y, v.z, getMaterial().getTrackBlock().asStack()); ItemEntity entity = new ItemEntity(level, v.x, v.y, v.z, new ItemStack(getMaterial().getTrackBlock().get()));
entity.setDefaultPickUpDelay(); entity.setDefaultPickUpDelay();
level.addFreshEntity(entity); level.addFreshEntity(entity);
if (!hasGirder) if (!hasGirder)
@ -360,7 +364,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment>, IHa
} }
public void spawnDestroyParticles(Level level) { public void spawnDestroyParticles(Level level) {
BlockParticleOption data = new BlockParticleOption(ParticleTypes.BLOCK, getMaterial().getTrackBlock().getDefaultState()); BlockParticleOption data = new BlockParticleOption(ParticleTypes.BLOCK, getMaterial().getTrackBlock().get().defaultBlockState());
BlockParticleOption girderData = BlockParticleOption girderData =
new BlockParticleOption(ParticleTypes.BLOCK, AllBlocks.METAL_GIRDER.getDefaultState()); new BlockParticleOption(ParticleTypes.BLOCK, AllBlocks.METAL_GIRDER.getDefaultState());
if (!(level instanceof ServerLevel slevel)) if (!(level instanceof ServerLevel slevel))
@ -378,15 +382,10 @@ public class BezierConnection implements Iterable<BezierConnection.Segment>, IHa
} }
} }
@Override
public TrackMaterial getMaterial() { public TrackMaterial getMaterial() {
if (trackMaterial == null) {
trackMaterial = TrackMaterial.ANDESITE;
}
return trackMaterial; return trackMaterial;
} }
@Override
public void setMaterial(TrackMaterial material) { public void setMaterial(TrackMaterial material) {
trackMaterial = material; trackMaterial = material;
} }

View file

@ -1,16 +0,0 @@
package com.simibubi.create.content.logistics.trains;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
public interface IHasTrackMaterial {
TrackMaterial getMaterial();
default void setMaterial(TrackMaterial material) {}
static TrackMaterial fromItem(Item item) {
if (item instanceof BlockItem blockItem && blockItem.getBlock() instanceof IHasTrackMaterial hasTrackMaterial)
return hasTrackMaterial.getMaterial();
return TrackMaterial.ANDESITE;
}
}

View file

@ -97,7 +97,7 @@ public interface ITrackBlock {
firstLocation.forceNode(); firstLocation.forceNode();
secondLocation.forceNode(); secondLocation.forceNode();
} }
boolean skipFirst = false; boolean skipFirst = false;
boolean skipSecond = false; boolean skipSecond = false;
@ -152,4 +152,6 @@ public interface ITrackBlock {
.normalize()) < 0 ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE); .normalize()) < 0 ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE);
} }
TrackMaterial getMaterial();
} }

View file

@ -6,39 +6,55 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.content.logistics.trains.track.TrackBlock; import com.simibubi.create.content.logistics.trains.track.TrackBlock;
import com.tterrag.registrate.util.entry.BlockEntry; import com.tterrag.registrate.util.nullness.NonNullSupplier;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.util.Lazy; import net.minecraftforge.common.util.Lazy;
import net.minecraftforge.fml.DistExecutor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
import static com.simibubi.create.content.logistics.trains.TrackMaterialFactory.make; import static com.simibubi.create.content.logistics.trains.TrackMaterialFactory.make;
public class TrackMaterial { public class TrackMaterial {
public static final List<TrackMaterial> ALL = new ArrayList<>(); public static final Map<ResourceLocation, TrackMaterial> ALL = new HashMap<>();
public static final TrackMaterial ANDESITE = make(Create.asResource("andesite")) public static final TrackMaterial ANDESITE = make(Create.asResource("andesite"))
.lang("Andesite") .lang("Andesite")
.block(Lazy.of(() -> AllBlocks.TRACK)) .block(NonNullSupplier.lazy(() -> AllBlocks.TRACK))
.particle(Create.asResource("block/palettes/stone_types/polished/andesite_cut_polished")) .particle(Create.asResource("block/palettes/stone_types/polished/andesite_cut_polished"))
.setBuiltin() .defaultModels()
.build(); .build();
public final ResourceLocation id; public final ResourceLocation id;
public final String langName; public final String langName;
public final Supplier<BlockEntry<? extends TrackBlock>> trackBlock; public final NonNullSupplier<NonNullSupplier<? extends TrackBlock>> trackBlock;
public final Ingredient sleeperIngredient; public final Ingredient sleeperIngredient;
public final Ingredient railsIngredient; public final Ingredient railsIngredient;
public final ResourceLocation particle; public final ResourceLocation particle;
public final TrackType trackType; public final TrackType trackType;
public final TrackModelHolder modelHolder;
public TrackMaterial(ResourceLocation id, String langName, Supplier<BlockEntry<? extends TrackBlock>> trackBlock, ResourceLocation particle, Ingredient sleeperIngredient, Ingredient railsIngredient, TrackType trackType, TrackModelHolder modelHolder) { @OnlyIn(Dist.CLIENT)
protected TrackModelHolder modelHolder;
@OnlyIn(Dist.CLIENT)
public TrackModelHolder getModelHolder() {
return modelHolder;
}
public TrackMaterial(ResourceLocation id, String langName, NonNullSupplier<NonNullSupplier<? extends TrackBlock>> trackBlock,
ResourceLocation particle, Ingredient sleeperIngredient, Ingredient railsIngredient,
TrackType trackType, Supplier<Supplier<TrackModelHolder>> modelHolder) {
this.id = id; this.id = id;
this.langName = langName; this.langName = langName;
this.trackBlock = trackBlock; this.trackBlock = trackBlock;
@ -46,15 +62,15 @@ public class TrackMaterial {
this.railsIngredient = railsIngredient; this.railsIngredient = railsIngredient;
this.particle = particle; this.particle = particle;
this.trackType = trackType; this.trackType = trackType;
this.modelHolder = modelHolder; DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> this.modelHolder = modelHolder.get().get());
ALL.add(this); ALL.put(this.id, this);
} }
public BlockEntry<? extends TrackBlock> getTrackBlock() { public NonNullSupplier<? extends TrackBlock> getTrackBlock() {
return this.trackBlock.get(); return this.trackBlock.get();
} }
public TrackBlock create(BlockBehaviour.Properties properties) { public TrackBlock createBlock(BlockBehaviour.Properties properties) {
return this.trackType.factory.create(properties, this); return this.trackType.factory.create(properties, this);
} }
@ -63,20 +79,20 @@ public class TrackMaterial {
} }
public static TrackMaterial[] allCustom(String modid) { public static TrackMaterial[] allCustom(String modid) {
return ALL.stream().filter(tm -> tm.isCustom(modid)).toArray(TrackMaterial[]::new); return ALL.values().stream().filter(tm -> tm.isCustom(modid)).toArray(TrackMaterial[]::new);
} }
public static List<BlockEntry<?>> allCustomBlocks(String modid) { public static List<NonNullSupplier<? extends TrackBlock>> allCustomBlocks(String modid) {
List<BlockEntry<?>> list = new ArrayList<>(); List<NonNullSupplier<? extends TrackBlock>> list = new ArrayList<>();
for (TrackMaterial material : allCustom(modid)) { for (TrackMaterial material : allCustom(modid)) {
list.add(material.getTrackBlock()); list.add(material.getTrackBlock());
} }
return list; return list;
} }
public static List<BlockEntry<?>> allBlocks() { public static List<NonNullSupplier<? extends TrackBlock>> allBlocks() {
List<BlockEntry<?>> list = new ArrayList<>(); List<NonNullSupplier<? extends TrackBlock>> list = new ArrayList<>();
for (TrackMaterial material : ALL) { for (TrackMaterial material : ALL.values()) {
list.add(material.getTrackBlock()); list.add(material.getTrackBlock());
} }
return list; return list;
@ -87,11 +103,16 @@ public class TrackMaterial {
} }
public static TrackMaterial deserialize(String serializedName) { public static TrackMaterial deserialize(String serializedName) {
ResourceLocation id = new ResourceLocation(serializedName); ResourceLocation id = ResourceLocation.tryParse(serializedName);
for (TrackMaterial material : ALL) { if (id == null) {
Create.LOGGER.error("Failed to parse serialized track material: "+serializedName);
return ANDESITE;
}
for (TrackMaterial material : ALL.values()) {
if (material.id.equals(id)) if (material.id.equals(id))
return material; return material;
} }
Create.LOGGER.error("Failed to locate serialized track material: "+serializedName);
return ANDESITE; return ANDESITE;
} }
@ -112,6 +133,13 @@ public class TrackMaterial {
} }
} }
public static TrackMaterial fromItem(Item item) {
if (item instanceof BlockItem blockItem && blockItem.getBlock() instanceof ITrackBlock trackBlock)
return trackBlock.getMaterial();
return TrackMaterial.ANDESITE;
}
@OnlyIn(Dist.CLIENT)
public record TrackModelHolder(PartialModel tie, PartialModel segment_left, PartialModel segment_right) { public record TrackModelHolder(PartialModel tie, PartialModel segment_left, PartialModel segment_right) {
static final TrackModelHolder DEFAULT = new TrackModelHolder(AllBlockPartials.TRACK_TIE, AllBlockPartials.TRACK_SEGMENT_LEFT, AllBlockPartials.TRACK_SEGMENT_RIGHT); static final TrackModelHolder DEFAULT = new TrackModelHolder(AllBlockPartials.TRACK_TIE, AllBlockPartials.TRACK_SEGMENT_LEFT, AllBlockPartials.TRACK_SEGMENT_RIGHT);
} }

View file

@ -3,11 +3,15 @@ package com.simibubi.create.content.logistics.trains;
import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.PartialModel;
import com.simibubi.create.AllTags; import com.simibubi.create.AllTags;
import com.simibubi.create.content.logistics.trains.track.TrackBlock; import com.simibubi.create.content.logistics.trains.track.TrackBlock;
import com.tterrag.registrate.util.entry.BlockEntry;
import com.tterrag.registrate.util.nullness.NonNullSupplier;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.ItemLike;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.DistExecutor;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -15,15 +19,20 @@ import java.util.stream.Stream;
public class TrackMaterialFactory { public class TrackMaterialFactory {
private final ResourceLocation id; private final ResourceLocation id;
private String langName; private String langName;
private Supplier<BlockEntry<? extends TrackBlock>> trackBlock; private NonNullSupplier<NonNullSupplier<? extends TrackBlock>> trackBlock;
private Ingredient sleeperIngredient = Ingredient.EMPTY; private Ingredient sleeperIngredient = Ingredient.EMPTY;
private Ingredient railsIngredient = Ingredient.fromValues(Stream.of(new Ingredient.TagValue(AllTags.forgeItemTag("nuggets/iron")), new Ingredient.TagValue(AllTags.forgeItemTag("nuggets/zinc")))); private Ingredient railsIngredient = Ingredient.fromValues(Stream.of(new Ingredient.TagValue(AllTags.forgeItemTag("nuggets/iron")), new Ingredient.TagValue(AllTags.forgeItemTag("nuggets/zinc"))));
private ResourceLocation particle; private ResourceLocation particle;
private TrackMaterial.TrackType trackType = TrackMaterial.TrackType.STANDARD; private TrackMaterial.TrackType trackType = TrackMaterial.TrackType.STANDARD;
private TrackMaterial.TrackModelHolder modelHolder = null;
private PartialModel tieModel = null; @OnlyIn(Dist.CLIENT)
private PartialModel leftSegmentModel = null; private TrackMaterial.TrackModelHolder modelHolder;
private PartialModel rightSegmentModel = null; @OnlyIn(Dist.CLIENT)
private PartialModel tieModel;
@OnlyIn(Dist.CLIENT)
private PartialModel leftSegmentModel;
@OnlyIn(Dist.CLIENT)
private PartialModel rightSegmentModel;
public TrackMaterialFactory(ResourceLocation id) { public TrackMaterialFactory(ResourceLocation id) {
this.id = id; this.id = id;
@ -38,13 +47,13 @@ public class TrackMaterialFactory {
return this; return this;
} }
public TrackMaterialFactory block(Supplier<BlockEntry<? extends TrackBlock>> trackBlock) { public TrackMaterialFactory block(NonNullSupplier<NonNullSupplier<? extends TrackBlock>> trackBlock) {
this.trackBlock = trackBlock; this.trackBlock = trackBlock;
return this; return this;
} }
public TrackMaterialFactory setBuiltin() { public TrackMaterialFactory defaultModels() { // was setBuiltin
this.modelHolder = TrackMaterial.TrackModelHolder.DEFAULT; DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> this.modelHolder = TrackMaterial.TrackModelHolder.DEFAULT);
return this; return this;
} }
@ -84,19 +93,23 @@ public class TrackMaterialFactory {
return this; return this;
} }
public TrackMaterialFactory defaultModels() { public TrackMaterialFactory standardModels() { // was defaultModels
String namespace = id.getNamespace(); DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
String prefix = "block/track/" + id.getPath() + "/"; String namespace = id.getNamespace();
tieModel = new PartialModel(new ResourceLocation(namespace, prefix + "tie")); String prefix = "block/track/" + id.getPath() + "/";
leftSegmentModel = new PartialModel(new ResourceLocation(namespace, prefix + "segment_left")); tieModel = new PartialModel(new ResourceLocation(namespace, prefix + "tie"));
rightSegmentModel = new PartialModel(new ResourceLocation(namespace, prefix + "segment_right")); leftSegmentModel = new PartialModel(new ResourceLocation(namespace, prefix + "segment_left"));
rightSegmentModel = new PartialModel(new ResourceLocation(namespace, prefix + "segment_right"));
});
return this; return this;
} }
public TrackMaterialFactory customModels(PartialModel tieModel, PartialModel leftSegmentModel, PartialModel rightSegmentModel) { public TrackMaterialFactory customModels(Supplier<Supplier<PartialModel>> tieModel, Supplier<Supplier<PartialModel>> leftSegmentModel, Supplier<Supplier<PartialModel>> rightSegmentModel) {
this.tieModel = tieModel; DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
this.leftSegmentModel = leftSegmentModel; this.tieModel = tieModel.get().get();
this.rightSegmentModel = rightSegmentModel; this.leftSegmentModel = leftSegmentModel.get().get();
this.rightSegmentModel = rightSegmentModel.get().get();
});
return this; return this;
} }
@ -108,11 +121,13 @@ public class TrackMaterialFactory {
assert sleeperIngredient != null; assert sleeperIngredient != null;
assert railsIngredient != null; assert railsIngredient != null;
assert id != null; assert id != null;
assert modelHolder != null; DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
if (tieModel != null || leftSegmentModel != null || rightSegmentModel != null) { assert modelHolder != null;
assert tieModel != null && leftSegmentModel != null && rightSegmentModel != null; if (tieModel != null || leftSegmentModel != null || rightSegmentModel != null) {
modelHolder = new TrackMaterial.TrackModelHolder(tieModel, leftSegmentModel, rightSegmentModel); assert tieModel != null && leftSegmentModel != null && rightSegmentModel != null;
} modelHolder = new TrackMaterial.TrackModelHolder(tieModel, leftSegmentModel, rightSegmentModel);
return new TrackMaterial(id, langName, trackBlock, particle, sleeperIngredient, railsIngredient, trackType, modelHolder); }
});
return new TrackMaterial(id, langName, trackBlock, particle, sleeperIngredient, railsIngredient, trackType, () -> () -> modelHolder);
} }
} }

View file

@ -11,7 +11,6 @@ import static com.simibubi.create.AllShapes.TRACK_ORTHO_LONG;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -21,10 +20,12 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.simibubi.create.AllTags; import com.simibubi.create.AllTags;
import com.simibubi.create.content.logistics.trains.IHasTrackMaterial;
import com.simibubi.create.content.logistics.trains.TrackMaterial; import com.simibubi.create.content.logistics.trains.TrackMaterial;
import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
@ -114,7 +115,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.IBlockRenderProperties; import net.minecraftforge.client.IBlockRenderProperties;
//init //init
public class TrackBlock extends Block public class TrackBlock extends Block
implements ITE<TrackTileEntity>, IWrenchable, ITrackBlock, ISpecialBlockItemRequirement, ProperWaterloggedBlock, IHasTrackMaterial { implements ITE<TrackTileEntity>, IWrenchable, ITrackBlock, ISpecialBlockItemRequirement, ProperWaterloggedBlock {
public static final EnumProperty<TrackShape> SHAPE = EnumProperty.create("shape", TrackShape.class); public static final EnumProperty<TrackShape> SHAPE = EnumProperty.create("shape", TrackShape.class);
public static final BooleanProperty HAS_TE = BooleanProperty.create("turn"); public static final BooleanProperty HAS_TE = BooleanProperty.create("turn");
@ -762,7 +763,7 @@ public class TrackBlock extends Block
@Override @Override
public ItemRequirement getRequiredItems(BlockState state, BlockEntity te) { public ItemRequirement getRequiredItems(BlockState state, BlockEntity te) {
int sameTypeTrackAmount = 1; int sameTypeTrackAmount = 1;
Map<TrackMaterial, Integer> otherTrackAmounts = new HashMap<>(); Object2IntMap<TrackMaterial> otherTrackAmounts = new Object2IntArrayMap<>();
int girderAmount = 0; int girderAmount = 0;
if (te instanceof TrackTileEntity track) { if (te instanceof TrackTileEntity track) {
@ -770,7 +771,7 @@ public class TrackBlock extends Block
.values()) { .values()) {
if (!bezierConnection.isPrimary()) if (!bezierConnection.isPrimary())
continue; continue;
TrackMaterial material = ((IHasTrackMaterial) bezierConnection).getMaterial(); TrackMaterial material = bezierConnection.getMaterial();
if (material == getMaterial()) { if (material == getMaterial()) {
sameTypeTrackAmount += bezierConnection.getTrackItemCost(); sameTypeTrackAmount += bezierConnection.getTrackItemCost();
} else { } else {
@ -786,7 +787,7 @@ public class TrackBlock extends Block
sameTypeTrackAmount -= 64; sameTypeTrackAmount -= 64;
} }
for (TrackMaterial material : otherTrackAmounts.keySet()) { for (TrackMaterial material : otherTrackAmounts.keySet()) {
int amt = otherTrackAmounts.get(material); int amt = otherTrackAmounts.getOrDefault(material, 0);
while (amt > 0) { while (amt > 0) {
stacks.add(new ItemStack(material.getTrackBlock().get(), Math.min(amt, 64))); stacks.add(new ItemStack(material.getTrackBlock().get(), Math.min(amt, 64)));
amt -= 64; amt -= 64;

View file

@ -20,7 +20,6 @@ import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.logistics.trains.BezierConnection; import com.simibubi.create.content.logistics.trains.BezierConnection;
import com.simibubi.create.content.logistics.trains.BezierConnection.GirderAngles; import com.simibubi.create.content.logistics.trains.BezierConnection.GirderAngles;
import com.simibubi.create.content.logistics.trains.BezierConnection.SegmentAngles; import com.simibubi.create.content.logistics.trains.BezierConnection.SegmentAngles;
import com.simibubi.create.content.logistics.trains.IHasTrackMaterial;
import com.simibubi.create.content.logistics.trains.TrackMaterial; import com.simibubi.create.content.logistics.trains.TrackMaterial;
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;
@ -114,7 +113,7 @@ public class TrackInstance extends BlockEntityInstance<TrackTileEntity> {
leftLightPos = new BlockPos[segCount]; leftLightPos = new BlockPos[segCount];
rightLightPos = new BlockPos[segCount]; rightLightPos = new BlockPos[segCount];
TrackMaterial.TrackModelHolder modelHolder = ((IHasTrackMaterial) bc).getMaterial().modelHolder; TrackMaterial.TrackModelHolder modelHolder = bc.getMaterial().getModelHolder();
mat.getModel(modelHolder.tie()) mat.getModel(modelHolder.tie())
.createInstances(ties); .createInstances(ties);

View file

@ -5,7 +5,6 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import com.jozufozu.flywheel.util.Color; import com.jozufozu.flywheel.util.Color;
import com.simibubi.create.AllSpecialTextures; import com.simibubi.create.AllSpecialTextures;
@ -13,7 +12,6 @@ import com.simibubi.create.AllTags;
import com.simibubi.create.CreateClient; import com.simibubi.create.CreateClient;
import com.simibubi.create.content.curiosities.tools.BlueprintOverlayRenderer; import com.simibubi.create.content.curiosities.tools.BlueprintOverlayRenderer;
import com.simibubi.create.content.logistics.trains.BezierConnection; import com.simibubi.create.content.logistics.trains.BezierConnection;
import com.simibubi.create.content.logistics.trains.IHasTrackMaterial;
import com.simibubi.create.content.logistics.trains.ITrackBlock; import com.simibubi.create.content.logistics.trains.ITrackBlock;
import com.simibubi.create.content.logistics.trains.TrackMaterial; import com.simibubi.create.content.logistics.trains.TrackMaterial;
import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.advancement.AllAdvancements;
@ -61,7 +59,12 @@ import net.minecraftforge.items.ItemHandlerHelper;
public class TrackPlacement { public class TrackPlacement {
public static class PlacementInfo implements IHasTrackMaterial { public static class PlacementInfo {
public PlacementInfo(TrackMaterial material) {
this.trackMaterial = material;
}
BezierConnection curve = null; BezierConnection curve = null;
boolean valid = false; boolean valid = false;
int end1Extent = 0; int end1Extent = 0;
@ -73,7 +76,7 @@ public class TrackPlacement {
public int requiredPavement = 0; public int requiredPavement = 0;
public boolean hasRequiredPavement = false; public boolean hasRequiredPavement = false;
private TrackMaterial trackMaterial; public final TrackMaterial trackMaterial;
// for visualisation // for visualisation
Vec3 end1; Vec3 end1;
@ -94,19 +97,6 @@ public class TrackPlacement {
curve = null; curve = null;
return this; return this;
} }
@Override
public TrackMaterial getMaterial() {
if (trackMaterial == null) {
throw new RuntimeException("Track material should never be null in TrackPlacement#PlacementInfo");
}
return trackMaterial;
}
@Override
public void setMaterial(TrackMaterial material) {
trackMaterial = material;
}
} }
public static PlacementInfo cached; public static PlacementInfo cached;
@ -126,8 +116,7 @@ public class TrackPlacement {
&& hoveringMaxed == maximiseTurn && lookAngle == hoveringAngle) && hoveringMaxed == maximiseTurn && lookAngle == hoveringAngle)
return cached; return cached;
PlacementInfo info = new PlacementInfo(); PlacementInfo info = new PlacementInfo(TrackMaterial.fromItem(stack.getItem()));
info.trackMaterial = IHasTrackMaterial.fromItem(stack.getItem());
hoveringMaxed = maximiseTurn; hoveringMaxed = maximiseTurn;
hoveringAngle = lookAngle; hoveringAngle = lookAngle;
hoveringPos = pos2; hoveringPos = pos2;
@ -211,7 +200,7 @@ public class TrackPlacement {
BlockPos targetPos2 = pos2.offset(offset2.x, offset2.y, offset2.z); BlockPos targetPos2 = pos2.offset(offset2.x, offset2.y, offset2.z);
info.curve = new BezierConnection(Couple.create(targetPos1, targetPos2), info.curve = new BezierConnection(Couple.create(targetPos1, targetPos2),
Couple.create(end1.add(offset1), end2.add(offset2)), Couple.create(normedAxis1, normedAxis2), Couple.create(end1.add(offset1), end2.add(offset2)), Couple.create(normedAxis1, normedAxis2),
Couple.create(normal1, normal2), true, girder, IHasTrackMaterial.fromItem(stack.getItem())); Couple.create(normal1, normal2), true, girder, TrackMaterial.fromItem(stack.getItem()));
} }
// S curve or Straight // S curve or Straight
@ -371,7 +360,7 @@ public class TrackPlacement {
info.curve = skipCurve ? null info.curve = skipCurve ? null
: new BezierConnection(Couple.create(targetPos1, targetPos2), : new BezierConnection(Couple.create(targetPos1, targetPos2),
Couple.create(end1.add(offset1), end2.add(offset2)), Couple.create(normedAxis1, normedAxis2), Couple.create(end1.add(offset1), end2.add(offset2)), Couple.create(normedAxis1, normedAxis2),
Couple.create(normal1, normal2), true, girder, IHasTrackMaterial.fromItem(stack.getItem())); Couple.create(normal1, normal2), true, girder, TrackMaterial.fromItem(stack.getItem()));
info.valid = true; info.valid = true;
@ -533,7 +522,7 @@ public class TrackPlacement {
BlockPos offsetPos = pos.offset(offset.x, offset.y, offset.z); BlockPos offsetPos = pos.offset(offset.x, offset.y, offset.z);
BlockState stateAtPos = level.getBlockState(offsetPos); BlockState stateAtPos = level.getBlockState(offsetPos);
// copy over all shared properties from the shaped state to the correct track material block // copy over all shared properties from the shaped state to the correct track material block
BlockState toPlace = copyProperties(state, info.getMaterial().getTrackBlock().getDefaultState()); BlockState toPlace = copyProperties(state, info.trackMaterial.getTrackBlock().get().defaultBlockState());
boolean canPlace = stateAtPos.getMaterial() boolean canPlace = stateAtPos.getMaterial()
.isReplaceable(); .isReplaceable();
@ -556,7 +545,7 @@ public class TrackPlacement {
return info; return info;
if (!simulate) { if (!simulate) {
BlockState onto = info.getMaterial().getTrackBlock().getDefaultState(); BlockState onto = info.trackMaterial.getTrackBlock().get().defaultBlockState();
BlockState stateAtPos = level.getBlockState(targetPos1); BlockState stateAtPos = level.getBlockState(targetPos1);
level.setBlock(targetPos1, ProperWaterloggedBlock.withWater(level, level.setBlock(targetPos1, ProperWaterloggedBlock.withWater(level,
(AllTags.AllBlockTags.TRACKS.matches(stateAtPos) ? stateAtPos : copyProperties(state1, onto)) (AllTags.AllBlockTags.TRACKS.matches(stateAtPos) ? stateAtPos : copyProperties(state1, onto))

View file

@ -12,7 +12,6 @@ import com.mojang.blaze3d.vertex.VertexConsumer;
import com.simibubi.create.content.logistics.trains.BezierConnection; import com.simibubi.create.content.logistics.trains.BezierConnection;
import com.simibubi.create.content.logistics.trains.BezierConnection.GirderAngles; import com.simibubi.create.content.logistics.trains.BezierConnection.GirderAngles;
import com.simibubi.create.content.logistics.trains.BezierConnection.SegmentAngles; import com.simibubi.create.content.logistics.trains.BezierConnection.SegmentAngles;
import com.simibubi.create.content.logistics.trains.IHasTrackMaterial;
import com.simibubi.create.content.logistics.trains.TrackMaterial; import com.simibubi.create.content.logistics.trains.TrackMaterial;
import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.render.CachedBufferer;
import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer;
@ -65,7 +64,7 @@ public class TrackRenderer extends SafeTileEntityRenderer<TrackTileEntity> {
SegmentAngles segment = segments[i]; SegmentAngles segment = segments[i];
int light = LevelRenderer.getLightColor(level, segment.lightPosition.offset(tePosition)); int light = LevelRenderer.getLightColor(level, segment.lightPosition.offset(tePosition));
TrackMaterial.TrackModelHolder modelHolder = ((IHasTrackMaterial) bc).getMaterial().modelHolder; TrackMaterial.TrackModelHolder modelHolder = bc.getMaterial().getModelHolder();
CachedBufferer.partial(modelHolder.tie(), air) CachedBufferer.partial(modelHolder.tie(), air)
.mulPose(segment.tieTransform.pose()) .mulPose(segment.tieTransform.pose())

View file

@ -4,6 +4,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.content.logistics.trains.TrackMaterial; import com.simibubi.create.content.logistics.trains.TrackMaterial;
import com.simibubi.create.content.logistics.trains.track.TrackBlock;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.ponder.PonderRegistrationHelper; import com.simibubi.create.foundation.ponder.PonderRegistrationHelper;
import com.simibubi.create.foundation.ponder.PonderRegistry; import com.simibubi.create.foundation.ponder.PonderRegistry;
@ -21,8 +22,15 @@ import com.simibubi.create.foundation.ponder.content.trains.TrainScenes;
import com.simibubi.create.foundation.ponder.content.trains.TrainSignalScenes; import com.simibubi.create.foundation.ponder.content.trains.TrainSignalScenes;
import com.simibubi.create.foundation.ponder.content.trains.TrainStationScenes; import com.simibubi.create.foundation.ponder.content.trains.TrainStationScenes;
import com.tterrag.registrate.util.entry.BlockEntry;
import com.tterrag.registrate.util.entry.ItemProviderEntry;
import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import java.util.stream.Collectors;
public class PonderIndex { public class PonderIndex {
@ -304,7 +312,12 @@ public class PonderIndex {
.addStoryBoard("rose_quartz_lamp", RedstoneScenes2::roseQuartzLamp); .addStoryBoard("rose_quartz_lamp", RedstoneScenes2::roseQuartzLamp);
// Trains // Trains
HELPER.forComponents(TrackMaterial.allBlocks()) HELPER.forComponents(TrackMaterial.allBlocks().stream()
.map((trackSupplier) -> new BlockEntry<TrackBlock>(
// note: these blocks probably WON'T be in the Create Registrate, but a simple code trace reveals the Entry's registrate isn't used
Create.REGISTRATE,
RegistryObject.create(trackSupplier.get().getRegistryName(), ForgeRegistries.BLOCKS)))
.toList())
.addStoryBoard("train_track/placement", TrackScenes::placement) .addStoryBoard("train_track/placement", TrackScenes::placement)
.addStoryBoard("train_track/portal", TrackScenes::portal) .addStoryBoard("train_track/portal", TrackScenes::portal)
.addStoryBoard("train_track/chunks", TrackScenes::chunks); .addStoryBoard("train_track/chunks", TrackScenes::chunks);