From e91753a33cde6dbe0caaface45a7f377d75acbed Mon Sep 17 00:00:00 2001 From: techno-sam Date: Sun, 30 Apr 2023 19:51:26 -0700 Subject: [PATCH] Fix up some problems --- src/generated/resources/.cache/cache | 2 - .../java/com/simibubi/create/AllBlocks.java | 2 +- .../com/simibubi/create/AllTileEntities.java | 5 +- .../tools/BlueprintOverlayRenderer.java | 3 +- .../logistics/trains/BezierConnection.java | 19 +++--- .../logistics/trains/IHasTrackMaterial.java | 16 ----- .../content/logistics/trains/ITrackBlock.java | 4 +- .../logistics/trains/TrackMaterial.java | 66 +++++++++++++------ .../trains/TrackMaterialFactory.java | 65 +++++++++++------- .../logistics/trains/track/TrackBlock.java | 13 ++-- .../logistics/trains/track/TrackInstance.java | 3 +- .../trains/track/TrackPlacement.java | 35 ++++------ .../logistics/trains/track/TrackRenderer.java | 3 +- .../ponder/content/PonderIndex.java | 15 ++++- 14 files changed, 140 insertions(+), 111 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/content/logistics/trains/IHasTrackMaterial.java diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index b60cd2d8d..d50c09db9 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -5611,7 +5611,6 @@ ac265a674626e0e832330086fd18fe0be37fc327 data/create/recipes/weathered_copper_ti 2a2700b43614f86d3294726595cb28ed7dca4387 data/create/tags/blocks/brittle.json d99d5c67bdffff60789a19bd51a5c5267c75e0a4 data/create/tags/blocks/casing.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 6e5d3b2123fbb00e7f439c091623619502551bca data/create/tags/blocks/non_movable.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 6cdeeac1689f7b5bfd9bc40b462143d8eaf3ad0b data/create/tags/blocks/seats.json d063e12c9ef75f39518c6d129ea35d833464d547 data/create/tags/blocks/toolboxes.json -ad8fa04f7bbbafd70d0ce158af78a35e899301e2 data/create/tags/blocks/tracks.json 9460e92c8e483446318b849abe7e6f52dcd4a269 data/create/tags/blocks/tree_attachments.json 50936b211d94167a35ec78c89954082a336b6269 data/create/tags/blocks/valve_handles.json eac71740fb12bdb38b5dfaa2268613d7ba82b809 data/create/tags/blocks/windmill_sails.json diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 071f944d3..3dfe2f87a 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -1501,7 +1501,7 @@ public class AllBlocks { .transform(customItemModel()) .register(); - public static final BlockEntry TRACK = REGISTRATE.block("track", TrackMaterial.ANDESITE::create) + public static final BlockEntry TRACK = REGISTRATE.block("track", TrackMaterial.ANDESITE::createBlock) .initialProperties(Material.STONE) .properties(p -> p.color(MaterialColor.METAL) .strength(0.8F) diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index be3363772..ba342d0f8 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -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.track.FakeTrackTileEntity; 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.TrackRenderer; 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.BlockEntry; +import com.tterrag.registrate.util.nullness.NonNullSupplier; + import net.minecraft.world.level.block.Block; public class AllTileEntities { @@ -785,7 +788,7 @@ public class AllTileEntities { .tileEntity("track", TrackTileEntity::new) .instance(() -> TrackInstance::new) .renderer(() -> TrackRenderer::new) - .validBlocks(((BlockEntry[]) TrackMaterial.allBlocks().toArray(new BlockEntry[0]))) + .validBlocks((NonNullSupplier[]) TrackMaterial.allBlocks().toArray(new NonNullSupplier[0])) .register(); public static final BlockEntityEntry FAKE_TRACK = REGISTRATE diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintOverlayRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintOverlayRenderer.java index 884d034cc..a3aec3eab 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintOverlayRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintOverlayRenderer.java @@ -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.FilterItem; 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.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.element.GuiGameElement; @@ -106,7 +105,7 @@ public class BlueprintOverlayRenderer { int tracks = info.requiredTracks; 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; } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/BezierConnection.java b/src/main/java/com/simibubi/create/content/logistics/trains/BezierConnection.java index 10b2fbead..a65cdb8f6 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/BezierConnection.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/BezierConnection.java @@ -24,6 +24,7 @@ import net.minecraft.util.Mth; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; 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.OnlyIn; -public class BezierConnection implements Iterable, IHasTrackMaterial { +public class BezierConnection implements Iterable { public Couple tePositions; public Couple starts; @@ -73,7 +74,10 @@ public class BezierConnection implements Iterable, IHa } 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) { @@ -318,7 +322,7 @@ public class BezierConnection implements Iterable, IHa Inventory inv = player.getInventory(); int tracks = getTrackItemCost(); 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; } int girders = getGirderItemCost(); @@ -346,7 +350,7 @@ public class BezierConnection implements Iterable, IHa continue; Vec3 v = VecHelper.offsetRandomly(segment.position, level.random, .125f) .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(); level.addFreshEntity(entity); if (!hasGirder) @@ -360,7 +364,7 @@ public class BezierConnection implements Iterable, IHa } 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 = new BlockParticleOption(ParticleTypes.BLOCK, AllBlocks.METAL_GIRDER.getDefaultState()); if (!(level instanceof ServerLevel slevel)) @@ -378,15 +382,10 @@ public class BezierConnection implements Iterable, IHa } } - @Override public TrackMaterial getMaterial() { - if (trackMaterial == null) { - trackMaterial = TrackMaterial.ANDESITE; - } return trackMaterial; } - @Override public void setMaterial(TrackMaterial material) { trackMaterial = material; } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/IHasTrackMaterial.java b/src/main/java/com/simibubi/create/content/logistics/trains/IHasTrackMaterial.java deleted file mode 100644 index 8abe19640..000000000 --- a/src/main/java/com/simibubi/create/content/logistics/trains/IHasTrackMaterial.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/ITrackBlock.java b/src/main/java/com/simibubi/create/content/logistics/trains/ITrackBlock.java index 33946c2a5..ad3f7c99b 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/ITrackBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/ITrackBlock.java @@ -97,7 +97,7 @@ public interface ITrackBlock { firstLocation.forceNode(); secondLocation.forceNode(); } - + boolean skipFirst = false; boolean skipSecond = false; @@ -152,4 +152,6 @@ public interface ITrackBlock { .normalize()) < 0 ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE); } + TrackMaterial getMaterial(); + } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/TrackMaterial.java b/src/main/java/com/simibubi/create/content/logistics/trains/TrackMaterial.java index d3ccd3910..759a243ea 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/TrackMaterial.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/TrackMaterial.java @@ -6,39 +6,55 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.Create; 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.world.item.BlockItem; +import net.minecraft.world.item.Item; import net.minecraft.world.item.crafting.Ingredient; 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.fml.DistExecutor; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.function.Supplier; import static com.simibubi.create.content.logistics.trains.TrackMaterialFactory.make; public class TrackMaterial { - public static final List ALL = new ArrayList<>(); + public static final Map ALL = new HashMap<>(); public static final TrackMaterial ANDESITE = make(Create.asResource("andesite")) .lang("Andesite") - .block(Lazy.of(() -> AllBlocks.TRACK)) + .block(NonNullSupplier.lazy(() -> AllBlocks.TRACK)) .particle(Create.asResource("block/palettes/stone_types/polished/andesite_cut_polished")) - .setBuiltin() + .defaultModels() .build(); public final ResourceLocation id; public final String langName; - public final Supplier> trackBlock; + public final NonNullSupplier> trackBlock; public final Ingredient sleeperIngredient; public final Ingredient railsIngredient; public final ResourceLocation particle; public final TrackType trackType; - public final TrackModelHolder modelHolder; - public TrackMaterial(ResourceLocation id, String langName, Supplier> 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> trackBlock, + ResourceLocation particle, Ingredient sleeperIngredient, Ingredient railsIngredient, + TrackType trackType, Supplier> modelHolder) { this.id = id; this.langName = langName; this.trackBlock = trackBlock; @@ -46,15 +62,15 @@ public class TrackMaterial { this.railsIngredient = railsIngredient; this.particle = particle; this.trackType = trackType; - this.modelHolder = modelHolder; - ALL.add(this); + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> this.modelHolder = modelHolder.get().get()); + ALL.put(this.id, this); } - public BlockEntry getTrackBlock() { + public NonNullSupplier getTrackBlock() { return this.trackBlock.get(); } - public TrackBlock create(BlockBehaviour.Properties properties) { + public TrackBlock createBlock(BlockBehaviour.Properties properties) { return this.trackType.factory.create(properties, this); } @@ -63,20 +79,20 @@ public class TrackMaterial { } 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> allCustomBlocks(String modid) { - List> list = new ArrayList<>(); + public static List> allCustomBlocks(String modid) { + List> list = new ArrayList<>(); for (TrackMaterial material : allCustom(modid)) { list.add(material.getTrackBlock()); } return list; } - public static List> allBlocks() { - List> list = new ArrayList<>(); - for (TrackMaterial material : ALL) { + public static List> allBlocks() { + List> list = new ArrayList<>(); + for (TrackMaterial material : ALL.values()) { list.add(material.getTrackBlock()); } return list; @@ -87,11 +103,16 @@ public class TrackMaterial { } public static TrackMaterial deserialize(String serializedName) { - ResourceLocation id = new ResourceLocation(serializedName); - for (TrackMaterial material : ALL) { + ResourceLocation id = ResourceLocation.tryParse(serializedName); + 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)) return material; } + Create.LOGGER.error("Failed to locate serialized track material: "+serializedName); 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) { static final TrackModelHolder DEFAULT = new TrackModelHolder(AllBlockPartials.TRACK_TIE, AllBlockPartials.TRACK_SEGMENT_LEFT, AllBlockPartials.TRACK_SEGMENT_RIGHT); } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/TrackMaterialFactory.java b/src/main/java/com/simibubi/create/content/logistics/trains/TrackMaterialFactory.java index f0f54e27e..878f09ce2 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/TrackMaterialFactory.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/TrackMaterialFactory.java @@ -3,11 +3,15 @@ package com.simibubi.create.content.logistics.trains; import com.jozufozu.flywheel.core.PartialModel; import com.simibubi.create.AllTags; 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.world.item.crafting.Ingredient; 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.stream.Stream; @@ -15,15 +19,20 @@ import java.util.stream.Stream; public class TrackMaterialFactory { private final ResourceLocation id; private String langName; - private Supplier> trackBlock; + private NonNullSupplier> trackBlock; 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 ResourceLocation particle; private TrackMaterial.TrackType trackType = TrackMaterial.TrackType.STANDARD; - private TrackMaterial.TrackModelHolder modelHolder = null; - private PartialModel tieModel = null; - private PartialModel leftSegmentModel = null; - private PartialModel rightSegmentModel = null; + + @OnlyIn(Dist.CLIENT) + private TrackMaterial.TrackModelHolder modelHolder; + @OnlyIn(Dist.CLIENT) + private PartialModel tieModel; + @OnlyIn(Dist.CLIENT) + private PartialModel leftSegmentModel; + @OnlyIn(Dist.CLIENT) + private PartialModel rightSegmentModel; public TrackMaterialFactory(ResourceLocation id) { this.id = id; @@ -38,13 +47,13 @@ public class TrackMaterialFactory { return this; } - public TrackMaterialFactory block(Supplier> trackBlock) { + public TrackMaterialFactory block(NonNullSupplier> trackBlock) { this.trackBlock = trackBlock; return this; } - public TrackMaterialFactory setBuiltin() { - this.modelHolder = TrackMaterial.TrackModelHolder.DEFAULT; + public TrackMaterialFactory defaultModels() { // was setBuiltin + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> this.modelHolder = TrackMaterial.TrackModelHolder.DEFAULT); return this; } @@ -84,19 +93,23 @@ public class TrackMaterialFactory { return this; } - public TrackMaterialFactory defaultModels() { - String namespace = id.getNamespace(); - String prefix = "block/track/" + id.getPath() + "/"; - tieModel = new PartialModel(new ResourceLocation(namespace, prefix + "tie")); - leftSegmentModel = new PartialModel(new ResourceLocation(namespace, prefix + "segment_left")); - rightSegmentModel = new PartialModel(new ResourceLocation(namespace, prefix + "segment_right")); + public TrackMaterialFactory standardModels() { // was defaultModels + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { + String namespace = id.getNamespace(); + String prefix = "block/track/" + id.getPath() + "/"; + tieModel = new PartialModel(new ResourceLocation(namespace, prefix + "tie")); + leftSegmentModel = new PartialModel(new ResourceLocation(namespace, prefix + "segment_left")); + rightSegmentModel = new PartialModel(new ResourceLocation(namespace, prefix + "segment_right")); + }); return this; } - public TrackMaterialFactory customModels(PartialModel tieModel, PartialModel leftSegmentModel, PartialModel rightSegmentModel) { - this.tieModel = tieModel; - this.leftSegmentModel = leftSegmentModel; - this.rightSegmentModel = rightSegmentModel; + public TrackMaterialFactory customModels(Supplier> tieModel, Supplier> leftSegmentModel, Supplier> rightSegmentModel) { + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { + this.tieModel = tieModel.get().get(); + this.leftSegmentModel = leftSegmentModel.get().get(); + this.rightSegmentModel = rightSegmentModel.get().get(); + }); return this; } @@ -108,11 +121,13 @@ public class TrackMaterialFactory { assert sleeperIngredient != null; assert railsIngredient != null; assert id != null; - assert modelHolder != null; - if (tieModel != null || leftSegmentModel != null || rightSegmentModel != null) { - 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); + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { + assert modelHolder != null; + if (tieModel != null || leftSegmentModel != null || rightSegmentModel != null) { + 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); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackBlock.java b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackBlock.java index 6b03ccad9..c764f143f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackBlock.java @@ -11,7 +11,6 @@ import static com.simibubi.create.AllShapes.TRACK_ORTHO_LONG; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -21,10 +20,12 @@ import java.util.Set; import java.util.function.Consumer; import com.simibubi.create.AllTags; -import com.simibubi.create.content.logistics.trains.IHasTrackMaterial; 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 com.google.common.base.Predicates; @@ -114,7 +115,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.IBlockRenderProperties; //init public class TrackBlock extends Block - implements ITE, IWrenchable, ITrackBlock, ISpecialBlockItemRequirement, ProperWaterloggedBlock, IHasTrackMaterial { + implements ITE, IWrenchable, ITrackBlock, ISpecialBlockItemRequirement, ProperWaterloggedBlock { public static final EnumProperty SHAPE = EnumProperty.create("shape", TrackShape.class); public static final BooleanProperty HAS_TE = BooleanProperty.create("turn"); @@ -762,7 +763,7 @@ public class TrackBlock extends Block @Override public ItemRequirement getRequiredItems(BlockState state, BlockEntity te) { int sameTypeTrackAmount = 1; - Map otherTrackAmounts = new HashMap<>(); + Object2IntMap otherTrackAmounts = new Object2IntArrayMap<>(); int girderAmount = 0; if (te instanceof TrackTileEntity track) { @@ -770,7 +771,7 @@ public class TrackBlock extends Block .values()) { if (!bezierConnection.isPrimary()) continue; - TrackMaterial material = ((IHasTrackMaterial) bezierConnection).getMaterial(); + TrackMaterial material = bezierConnection.getMaterial(); if (material == getMaterial()) { sameTypeTrackAmount += bezierConnection.getTrackItemCost(); } else { @@ -786,7 +787,7 @@ public class TrackBlock extends Block sameTypeTrackAmount -= 64; } for (TrackMaterial material : otherTrackAmounts.keySet()) { - int amt = otherTrackAmounts.get(material); + int amt = otherTrackAmounts.getOrDefault(material, 0); while (amt > 0) { stacks.add(new ItemStack(material.getTrackBlock().get(), Math.min(amt, 64))); amt -= 64; diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackInstance.java b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackInstance.java index 76118bac9..37cb3b6e0 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackInstance.java @@ -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.GirderAngles; 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.foundation.utility.Couple; import com.simibubi.create.foundation.utility.Iterate; @@ -114,7 +113,7 @@ public class TrackInstance extends BlockEntityInstance { leftLightPos = new BlockPos[segCount]; rightLightPos = new BlockPos[segCount]; - TrackMaterial.TrackModelHolder modelHolder = ((IHasTrackMaterial) bc).getMaterial().modelHolder; + TrackMaterial.TrackModelHolder modelHolder = bc.getMaterial().getModelHolder(); mat.getModel(modelHolder.tie()) .createInstances(ties); diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackPlacement.java b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackPlacement.java index 28a0cd4ce..adf3e9707 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackPlacement.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackPlacement.java @@ -5,7 +5,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.function.Function; import com.jozufozu.flywheel.util.Color; import com.simibubi.create.AllSpecialTextures; @@ -13,7 +12,6 @@ import com.simibubi.create.AllTags; import com.simibubi.create.CreateClient; import com.simibubi.create.content.curiosities.tools.BlueprintOverlayRenderer; 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.TrackMaterial; import com.simibubi.create.foundation.advancement.AllAdvancements; @@ -61,7 +59,12 @@ import net.minecraftforge.items.ItemHandlerHelper; public class TrackPlacement { - public static class PlacementInfo implements IHasTrackMaterial { + public static class PlacementInfo { + + public PlacementInfo(TrackMaterial material) { + this.trackMaterial = material; + } + BezierConnection curve = null; boolean valid = false; int end1Extent = 0; @@ -73,7 +76,7 @@ public class TrackPlacement { public int requiredPavement = 0; public boolean hasRequiredPavement = false; - private TrackMaterial trackMaterial; + public final TrackMaterial trackMaterial; // for visualisation Vec3 end1; @@ -94,19 +97,6 @@ public class TrackPlacement { curve = null; 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; @@ -126,8 +116,7 @@ public class TrackPlacement { && hoveringMaxed == maximiseTurn && lookAngle == hoveringAngle) return cached; - PlacementInfo info = new PlacementInfo(); - info.trackMaterial = IHasTrackMaterial.fromItem(stack.getItem()); + PlacementInfo info = new PlacementInfo(TrackMaterial.fromItem(stack.getItem())); hoveringMaxed = maximiseTurn; hoveringAngle = lookAngle; hoveringPos = pos2; @@ -211,7 +200,7 @@ public class TrackPlacement { BlockPos targetPos2 = pos2.offset(offset2.x, offset2.y, offset2.z); info.curve = new BezierConnection(Couple.create(targetPos1, targetPos2), 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 @@ -371,7 +360,7 @@ public class TrackPlacement { info.curve = skipCurve ? null : new BezierConnection(Couple.create(targetPos1, targetPos2), 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; @@ -533,7 +522,7 @@ public class TrackPlacement { BlockPos offsetPos = pos.offset(offset.x, offset.y, offset.z); BlockState stateAtPos = level.getBlockState(offsetPos); // 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() .isReplaceable(); @@ -556,7 +545,7 @@ public class TrackPlacement { return info; if (!simulate) { - BlockState onto = info.getMaterial().getTrackBlock().getDefaultState(); + BlockState onto = info.trackMaterial.getTrackBlock().get().defaultBlockState(); BlockState stateAtPos = level.getBlockState(targetPos1); level.setBlock(targetPos1, ProperWaterloggedBlock.withWater(level, (AllTags.AllBlockTags.TRACKS.matches(stateAtPos) ? stateAtPos : copyProperties(state1, onto)) diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackRenderer.java b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackRenderer.java index cb5f3f9d7..fdb66a005 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/track/TrackRenderer.java @@ -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.GirderAngles; 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.foundation.render.CachedBufferer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -65,7 +64,7 @@ public class TrackRenderer extends SafeTileEntityRenderer { SegmentAngles segment = segments[i]; 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) .mulPose(segment.tieTransform.pose()) diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java index c2b2d4742..e3905f033 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java @@ -4,6 +4,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.Create; 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.ponder.PonderRegistrationHelper; 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.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.level.block.Blocks; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegistryObject; + +import java.util.stream.Collectors; public class PonderIndex { @@ -304,7 +312,12 @@ public class PonderIndex { .addStoryBoard("rose_quartz_lamp", RedstoneScenes2::roseQuartzLamp); // Trains - HELPER.forComponents(TrackMaterial.allBlocks()) + HELPER.forComponents(TrackMaterial.allBlocks().stream() + .map((trackSupplier) -> new BlockEntry( + // 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/portal", TrackScenes::portal) .addStoryBoard("train_track/chunks", TrackScenes::chunks);