mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-13 05:21:46 +01:00
Fix up some problems
This commit is contained in:
parent
74d98a2ad5
commit
e91753a33c
14 changed files with 140 additions and 111 deletions
|
@ -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
|
||||
|
|
|
@ -1501,7 +1501,7 @@ public class AllBlocks {
|
|||
.transform(customItemModel())
|
||||
.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)
|
||||
.properties(p -> p.color(MaterialColor.METAL)
|
||||
.strength(0.8F)
|
||||
|
|
|
@ -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<? extends Block>[]) TrackMaterial.allBlocks().toArray(new BlockEntry[0])))
|
||||
.validBlocks((NonNullSupplier<? extends TrackBlock>[]) TrackMaterial.allBlocks().toArray(new NonNullSupplier[0]))
|
||||
.register();
|
||||
|
||||
public static final BlockEntityEntry<FakeTrackTileEntity> FAKE_TRACK = REGISTRATE
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<BezierConnection.Segment>, IHasTrackMaterial {
|
||||
public class BezierConnection implements Iterable<BezierConnection.Segment> {
|
||||
|
||||
public Couple<BlockPos> tePositions;
|
||||
public Couple<Vec3> starts;
|
||||
|
@ -73,7 +74,10 @@ public class BezierConnection implements Iterable<BezierConnection.Segment>, 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<BezierConnection.Segment>, 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<BezierConnection.Segment>, 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<BezierConnection.Segment>, 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<BezierConnection.Segment>, IHa
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackMaterial getMaterial() {
|
||||
if (trackMaterial == null) {
|
||||
trackMaterial = TrackMaterial.ANDESITE;
|
||||
}
|
||||
return trackMaterial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaterial(TrackMaterial material) {
|
||||
trackMaterial = material;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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<TrackMaterial> ALL = new ArrayList<>();
|
||||
public static final Map<ResourceLocation, TrackMaterial> 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<BlockEntry<? extends TrackBlock>> trackBlock;
|
||||
public final NonNullSupplier<NonNullSupplier<? extends TrackBlock>> 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<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.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<? extends TrackBlock> getTrackBlock() {
|
||||
public NonNullSupplier<? extends TrackBlock> 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<BlockEntry<?>> allCustomBlocks(String modid) {
|
||||
List<BlockEntry<?>> list = new ArrayList<>();
|
||||
public static List<NonNullSupplier<? extends TrackBlock>> allCustomBlocks(String modid) {
|
||||
List<NonNullSupplier<? extends TrackBlock>> list = new ArrayList<>();
|
||||
for (TrackMaterial material : allCustom(modid)) {
|
||||
list.add(material.getTrackBlock());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<BlockEntry<?>> allBlocks() {
|
||||
List<BlockEntry<?>> list = new ArrayList<>();
|
||||
for (TrackMaterial material : ALL) {
|
||||
public static List<NonNullSupplier<? extends TrackBlock>> allBlocks() {
|
||||
List<NonNullSupplier<? extends TrackBlock>> 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);
|
||||
}
|
||||
|
|
|
@ -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<BlockEntry<? extends TrackBlock>> trackBlock;
|
||||
private NonNullSupplier<NonNullSupplier<? extends TrackBlock>> 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<BlockEntry<? extends TrackBlock>> trackBlock) {
|
||||
public TrackMaterialFactory block(NonNullSupplier<NonNullSupplier<? extends TrackBlock>> 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<Supplier<PartialModel>> tieModel, Supplier<Supplier<PartialModel>> leftSegmentModel, Supplier<Supplier<PartialModel>> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<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 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<TrackMaterial, Integer> otherTrackAmounts = new HashMap<>();
|
||||
Object2IntMap<TrackMaterial> 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;
|
||||
|
|
|
@ -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<TrackTileEntity> {
|
|||
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);
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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<TrackTileEntity> {
|
|||
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())
|
||||
|
|
|
@ -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<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/portal", TrackScenes::portal)
|
||||
.addStoryBoard("train_track/chunks", TrackScenes::chunks);
|
||||
|
|
Loading…
Reference in a new issue