mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-05 03:32:36 +01:00
Merge branch '1.18/api' into mc1.18/dev
This commit is contained in:
commit
6564f4fa73
26 changed files with 489 additions and 68 deletions
|
@ -13,6 +13,7 @@
|
|||
"cs": "cs_cz",
|
||||
"da": "da_dk",
|
||||
"de": "de_de",
|
||||
"eo": "eo_uy",
|
||||
"es-CL": "es_cl",
|
||||
"es-ES": "es_es",
|
||||
"es-MX": "es_mx",
|
||||
|
@ -30,6 +31,7 @@
|
|||
"pt-BR": "pt_br",
|
||||
"pt-PT": "pt_pt",
|
||||
"ro": "ro_ro",
|
||||
"rpr": "rpr",
|
||||
"ru": "ru_ru",
|
||||
"sv-SE": "sv_se",
|
||||
"th": "th_th",
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"create:track"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"create:track"
|
||||
]
|
||||
}
|
|
@ -209,6 +209,7 @@ import com.simibubi.create.content.logistics.block.vault.ItemVaultItem;
|
|||
import com.simibubi.create.content.logistics.item.LecternControllerBlock;
|
||||
import com.simibubi.create.content.logistics.trains.BogeyRenderer;
|
||||
import com.simibubi.create.content.logistics.trains.BogeySizes;
|
||||
import com.simibubi.create.content.logistics.trains.TrackMaterial;
|
||||
import com.simibubi.create.content.logistics.trains.management.display.FlapDisplayBlock;
|
||||
import com.simibubi.create.content.logistics.trains.management.edgePoint.EdgePointType;
|
||||
import com.simibubi.create.content.logistics.trains.management.edgePoint.TrackTargetingBlockItem;
|
||||
|
@ -1502,7 +1503,7 @@ public class AllBlocks {
|
|||
.transform(customItemModel())
|
||||
.register();
|
||||
|
||||
public static final BlockEntry<TrackBlock> TRACK = REGISTRATE.block("track", TrackBlock::new)
|
||||
public static final BlockEntry<TrackBlock> TRACK = REGISTRATE.block("track", TrackMaterial.ANDESITE::createBlock)
|
||||
.initialProperties(Material.STONE)
|
||||
.properties(p -> p.color(MaterialColor.METAL)
|
||||
.strength(0.8F)
|
||||
|
@ -1512,6 +1513,8 @@ public class AllBlocks {
|
|||
.transform(pickaxeOnly())
|
||||
.blockstate(new TrackBlockStateGenerator()::generate)
|
||||
.tag(AllBlockTags.RELOCATION_NOT_SUPPORTED.tag)
|
||||
.tag(AllBlockTags.TRACKS.tag)
|
||||
.tag(AllBlockTags.GIRDABLE_TRACKS.tag)
|
||||
.lang("Train Track")
|
||||
.item(TrackBlockItem::new)
|
||||
.model((c, p) -> p.generated(c, Create.asResource("item/" + c.getName())))
|
||||
|
|
|
@ -107,6 +107,8 @@ public class AllTags {
|
|||
SAFE_NBT,
|
||||
SEATS,
|
||||
TOOLBOXES,
|
||||
TRACKS,
|
||||
GIRDABLE_TRACKS,
|
||||
TREE_ATTACHMENTS,
|
||||
VALVE_HANDLES,
|
||||
WINDMILL_SAILS,
|
||||
|
@ -155,6 +157,10 @@ public class AllTags {
|
|||
.is(tag);
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack stack) {
|
||||
return stack != null && stack.getItem() instanceof BlockItem blockItem && matches(blockItem.getBlock());
|
||||
}
|
||||
|
||||
public boolean matches(BlockState state) {
|
||||
return state.is(tag);
|
||||
}
|
||||
|
|
|
@ -182,6 +182,7 @@ import com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity;
|
|||
import com.simibubi.create.content.logistics.item.LecternControllerRenderer;
|
||||
import com.simibubi.create.content.logistics.item.LecternControllerTileEntity;
|
||||
import com.simibubi.create.content.logistics.trains.BogeyTileEntityRenderer;
|
||||
import com.simibubi.create.content.logistics.trains.TrackMaterial;
|
||||
import com.simibubi.create.content.logistics.trains.management.display.FlapDisplayRenderer;
|
||||
import com.simibubi.create.content.logistics.trains.management.display.FlapDisplayTileEntity;
|
||||
import com.simibubi.create.content.logistics.trains.management.edgePoint.observer.TrackObserverRenderer;
|
||||
|
@ -192,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;
|
||||
|
@ -201,6 +203,11 @@ import com.simibubi.create.content.schematics.block.SchematicannonRenderer;
|
|||
import com.simibubi.create.content.schematics.block.SchematicannonTileEntity;
|
||||
import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer;
|
||||
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 {
|
||||
|
||||
|
@ -656,7 +663,7 @@ public class AllTileEntities {
|
|||
.validBlocks(AllBlocks.ANALOG_LEVER)
|
||||
.renderer(() -> AnalogLeverRenderer::new)
|
||||
.register();
|
||||
|
||||
|
||||
public static final BlockEntityEntry<PlacardTileEntity> PLACARD = REGISTRATE
|
||||
.tileEntity("placard", PlacardTileEntity::new)
|
||||
.validBlocks(AllBlocks.PLACARD)
|
||||
|
@ -781,9 +788,9 @@ public class AllTileEntities {
|
|||
.tileEntity("track", TrackTileEntity::new)
|
||||
.instance(() -> TrackInstance::new)
|
||||
.renderer(() -> TrackRenderer::new)
|
||||
.validBlocks(AllBlocks.TRACK)
|
||||
.validBlocks((NonNullSupplier<? extends TrackBlock>[]) TrackMaterial.allBlocks().toArray(new NonNullSupplier[0]))
|
||||
.register();
|
||||
|
||||
|
||||
public static final BlockEntityEntry<FakeTrackTileEntity> FAKE_TRACK = REGISTRATE
|
||||
.tileEntity("fake_track", FakeTrackTileEntity::new)
|
||||
.validBlocks(AllBlocks.FAKE_TRACK)
|
||||
|
@ -800,7 +807,7 @@ public class AllTileEntities {
|
|||
.renderer(() -> StationRenderer::new)
|
||||
.validBlocks(AllBlocks.TRACK_STATION)
|
||||
.register();
|
||||
|
||||
|
||||
public static final BlockEntityEntry<SlidingDoorTileEntity> SLIDING_DOOR = REGISTRATE
|
||||
.tileEntity("sliding_door", SlidingDoorTileEntity::new)
|
||||
.renderer(() -> SlidingDoorRenderer::new)
|
||||
|
|
|
@ -4,7 +4,7 @@ import javax.annotation.Nullable;
|
|||
|
||||
import com.jozufozu.flywheel.api.MaterialManager;
|
||||
import com.jozufozu.flywheel.core.virtual.VirtualRenderWorld;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllTags;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices;
|
||||
|
@ -61,7 +61,7 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour {
|
|||
@Override
|
||||
public boolean canBreak(Level world, BlockPos breakingPos, BlockState state) {
|
||||
return super.canBreak(world, breakingPos, state) && !state.getCollisionShape(world, breakingPos)
|
||||
.isEmpty() && !AllBlocks.TRACK.has(state);
|
||||
.isEmpty() && !AllTags.AllBlockTags.TRACKS.matches(state);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.crank;
|
|||
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
|
||||
|
@ -74,7 +75,8 @@ public class HandCrankBlock extends DirectionalKineticBlock
|
|||
return InteractionResult.PASS;
|
||||
|
||||
withTileEntityDo(worldIn, pos, te -> te.turn(player.isShiftKeyDown()));
|
||||
player.causeFoodExhaustion(getRotationSpeed() * AllConfigs.SERVER.kinetics.crankHungerMultiplier.getF());
|
||||
if(!player.getItemInHand(handIn).is(AllItems.EXTENDO_GRIP.get()))
|
||||
player.causeFoodExhaustion(getRotationSpeed() * AllConfigs.SERVER.kinetics.crankHungerMultiplier.getF());
|
||||
|
||||
if (player.getFoodData()
|
||||
.getFoodLevel() == 0)
|
||||
|
@ -117,14 +119,14 @@ public class HandCrankBlock extends DirectionalKineticBlock
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState updateShape(BlockState pState, Direction pDirection, BlockState pNeighborState,
|
||||
LevelAccessor pLevel, BlockPos pCurrentPos, BlockPos pNeighborPos) {
|
||||
updateWater(pLevel, pState, pCurrentPos);
|
||||
return pState;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FluidState getFluidState(BlockState pState) {
|
||||
return fluidState(pState);
|
||||
|
|
|
@ -3,8 +3,8 @@ package com.simibubi.create.content.contraptions.components.press;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllRecipeTypes;
|
||||
import com.simibubi.create.AllTags;
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.contraptions.components.crafter.MechanicalCraftingRecipe;
|
||||
import com.simibubi.create.content.contraptions.components.press.PressingBehaviour.Mode;
|
||||
|
@ -69,7 +69,7 @@ public class MechanicalPressTileEntity extends BasinOperatingTileEntity implemen
|
|||
|
||||
public void onItemPressed(ItemStack result) {
|
||||
award(AllAdvancements.PRESS);
|
||||
if (AllBlocks.TRACK.isIn(result))
|
||||
if (AllTags.AllBlockTags.TRACKS.matches(result))
|
||||
tracksCreated += result.getCount();
|
||||
if (tracksCreated >= 1000) {
|
||||
award(AllAdvancements.TRACK_CRAFTING);
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.Random;
|
|||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.AllTags;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.content.contraptions.fluids.pipes.BracketBlock;
|
||||
import com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour;
|
||||
|
@ -224,7 +225,7 @@ public class GirderBlock extends Block implements SimpleWaterloggedBlock, IWrenc
|
|||
for (Direction d2 : Iterate.directionsInAxis(axis == Axis.X ? Axis.Z : Axis.X)) {
|
||||
BlockState above = level.getBlockState(pos.above()
|
||||
.relative(d2));
|
||||
if (AllBlocks.TRACK.has(above)) {
|
||||
if (AllTags.AllBlockTags.GIRDABLE_TRACKS.matches(above)) {
|
||||
TrackShape shape = above.getValue(TrackBlock.SHAPE);
|
||||
if (shape == (axis == Axis.X ? TrackShape.XO : TrackShape.ZO))
|
||||
state = state.setValue(updateProperty, true);
|
||||
|
|
|
@ -44,6 +44,10 @@ public class GirderEncasedShaftBlock extends HorizontalAxisKineticBlock
|
|||
|
||||
public GirderEncasedShaftBlock(Properties properties) {
|
||||
super(properties);
|
||||
registerDefaultState(super.defaultBlockState()
|
||||
.setValue(WATERLOGGED, false)
|
||||
.setValue(TOP, false)
|
||||
.setValue(BOTTOM, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.util.Optional;
|
|||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintCraftingInventory;
|
||||
import com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection;
|
||||
|
@ -106,7 +105,7 @@ public class BlueprintOverlayRenderer {
|
|||
|
||||
int tracks = info.requiredTracks;
|
||||
while (tracks > 0) {
|
||||
ingredients.add(Pair.of(AllBlocks.TRACK.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;
|
||||
|
@ -39,6 +40,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
|
|||
public Couple<Vec3> normals;
|
||||
public boolean primary;
|
||||
public boolean hasGirder;
|
||||
protected TrackMaterial trackMaterial;
|
||||
|
||||
// runtime
|
||||
|
||||
|
@ -55,19 +57,37 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
|
|||
private AABB bounds;
|
||||
|
||||
public BezierConnection(Couple<BlockPos> positions, Couple<Vec3> starts, Couple<Vec3> axes, Couple<Vec3> normals,
|
||||
boolean primary, boolean girder) {
|
||||
boolean primary, boolean girder, TrackMaterial material) {
|
||||
tePositions = positions;
|
||||
this.starts = starts;
|
||||
this.axes = axes;
|
||||
this.normals = normals;
|
||||
this.primary = primary;
|
||||
this.hasGirder = girder;
|
||||
this.trackMaterial = material;
|
||||
resolved = false;
|
||||
}
|
||||
|
||||
public BezierConnection secondary() {
|
||||
return new BezierConnection(tePositions.swap(), starts.swap(), axes.swap(), normals.swap(), !primary,
|
||||
hasGirder);
|
||||
hasGirder, trackMaterial);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public boolean equalsSansMaterial(BezierConnection other) {
|
||||
return equalsSansMaterialInner(other) || equalsSansMaterialInner(other.secondary());
|
||||
}
|
||||
|
||||
private boolean equalsSansMaterialInner(BezierConnection other) {
|
||||
return this == other || (other != null && coupleEquals(this.tePositions, other.tePositions) && coupleEquals(this.starts, other.starts)
|
||||
&& coupleEquals(this.axes, other.axes) && coupleEquals(this.normals, other.normals)
|
||||
&& this.hasGirder == other.hasGirder);
|
||||
}
|
||||
|
||||
public BezierConnection(CompoundTag compound, BlockPos localTo) {
|
||||
|
@ -77,7 +97,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
|
|||
.map(v -> v.add(Vec3.atLowerCornerOf(localTo))),
|
||||
Couple.deserializeEach(compound.getList("Axes", Tag.TAG_COMPOUND), VecHelper::readNBTCompound),
|
||||
Couple.deserializeEach(compound.getList("Normals", Tag.TAG_COMPOUND), VecHelper::readNBTCompound),
|
||||
compound.getBoolean("Primary"), compound.getBoolean("Girder"));
|
||||
compound.getBoolean("Primary"), compound.getBoolean("Girder"), TrackMaterial.deserialize(compound.getString("Material")));
|
||||
}
|
||||
|
||||
public CompoundTag write(BlockPos localTo) {
|
||||
|
@ -91,13 +111,14 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
|
|||
compound.put("Starts", starts.serializeEach(VecHelper::writeNBTCompound));
|
||||
compound.put("Axes", axes.serializeEach(VecHelper::writeNBTCompound));
|
||||
compound.put("Normals", normals.serializeEach(VecHelper::writeNBTCompound));
|
||||
compound.putString("Material", getMaterial().id.toString());
|
||||
return compound;
|
||||
}
|
||||
|
||||
public BezierConnection(FriendlyByteBuf buffer) {
|
||||
this(Couple.create(buffer::readBlockPos), Couple.create(() -> VecHelper.read(buffer)),
|
||||
Couple.create(() -> VecHelper.read(buffer)), Couple.create(() -> VecHelper.read(buffer)),
|
||||
buffer.readBoolean(), buffer.readBoolean());
|
||||
buffer.readBoolean(), buffer.readBoolean(), TrackMaterial.deserialize(buffer.readUtf()));
|
||||
}
|
||||
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
|
@ -107,6 +128,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
|
|||
normals.forEach(v -> VecHelper.write(v, buffer));
|
||||
buffer.writeBoolean(primary);
|
||||
buffer.writeBoolean(hasGirder);
|
||||
buffer.writeUtf(getMaterial().id.toString());
|
||||
}
|
||||
|
||||
public BlockPos getKey() {
|
||||
|
@ -300,7 +322,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
|
|||
Inventory inv = player.getInventory();
|
||||
int tracks = getTrackItemCost();
|
||||
while (tracks > 0) {
|
||||
inv.placeItemBackInInventory(AllBlocks.TRACK.asStack(Math.min(64, tracks)));
|
||||
inv.placeItemBackInInventory(new ItemStack(getMaterial().getTrackBlock().get(), Math.min(64, tracks)));
|
||||
tracks -= 64;
|
||||
}
|
||||
int girders = getGirderItemCost();
|
||||
|
@ -328,7 +350,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
|
|||
continue;
|
||||
Vec3 v = VecHelper.offsetRandomly(segment.position, level.random, .125f)
|
||||
.add(origin);
|
||||
ItemEntity entity = new ItemEntity(level, v.x, v.y, v.z, AllBlocks.TRACK.asStack());
|
||||
ItemEntity entity = new ItemEntity(level, v.x, v.y, v.z, new ItemStack(getMaterial().getTrackBlock().get()));
|
||||
entity.setDefaultPickUpDelay();
|
||||
level.addFreshEntity(entity);
|
||||
if (!hasGirder)
|
||||
|
@ -342,7 +364,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
|
|||
}
|
||||
|
||||
public void spawnDestroyParticles(Level level) {
|
||||
BlockParticleOption data = new BlockParticleOption(ParticleTypes.BLOCK, AllBlocks.TRACK.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))
|
||||
|
@ -360,6 +382,14 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
|
|||
}
|
||||
}
|
||||
|
||||
public TrackMaterial getMaterial() {
|
||||
return trackMaterial;
|
||||
}
|
||||
|
||||
public void setMaterial(TrackMaterial material) {
|
||||
trackMaterial = material;
|
||||
}
|
||||
|
||||
public static class Segment {
|
||||
|
||||
public int index;
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
package com.simibubi.create.content.logistics.trains;
|
||||
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.logistics.trains.track.TrackBlock;
|
||||
|
||||
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 Map<ResourceLocation, TrackMaterial> ALL = new HashMap<>();
|
||||
|
||||
public static final TrackMaterial ANDESITE = make(Create.asResource("andesite"))
|
||||
.lang("Andesite")
|
||||
.block(NonNullSupplier.lazy(() -> AllBlocks.TRACK))
|
||||
.particle(Create.asResource("block/palettes/stone_types/polished/andesite_cut_polished"))
|
||||
.defaultModels()
|
||||
.build();
|
||||
|
||||
public final ResourceLocation id;
|
||||
public final String langName;
|
||||
public final NonNullSupplier<NonNullSupplier<? extends TrackBlock>> trackBlock;
|
||||
public final Ingredient sleeperIngredient;
|
||||
public final Ingredient railsIngredient;
|
||||
public final ResourceLocation particle;
|
||||
public final TrackType trackType;
|
||||
|
||||
@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;
|
||||
this.sleeperIngredient = sleeperIngredient;
|
||||
this.railsIngredient = railsIngredient;
|
||||
this.particle = particle;
|
||||
this.trackType = trackType;
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> this.modelHolder = modelHolder.get().get());
|
||||
ALL.put(this.id, this);
|
||||
}
|
||||
|
||||
public NonNullSupplier<? extends TrackBlock> getTrackBlock() {
|
||||
return this.trackBlock.get();
|
||||
}
|
||||
|
||||
public TrackBlock createBlock(BlockBehaviour.Properties properties) {
|
||||
return this.trackType.factory.create(properties, this);
|
||||
}
|
||||
|
||||
public boolean isCustom(String modId) {
|
||||
return this.id.getNamespace().equals(modId);
|
||||
}
|
||||
|
||||
public static TrackMaterial[] allCustom(String modid) {
|
||||
return ALL.values().stream().filter(tm -> tm.isCustom(modid)).toArray(TrackMaterial[]::new);
|
||||
}
|
||||
|
||||
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<NonNullSupplier<? extends TrackBlock>> allBlocks() {
|
||||
List<NonNullSupplier<? extends TrackBlock>> list = new ArrayList<>();
|
||||
for (TrackMaterial material : ALL.values()) {
|
||||
list.add(material.getTrackBlock());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public String resourceName() {
|
||||
return this.id.getPath();
|
||||
}
|
||||
|
||||
public static TrackMaterial deserialize(String serializedName) {
|
||||
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;
|
||||
}
|
||||
|
||||
public static class TrackType {
|
||||
@FunctionalInterface
|
||||
protected interface TrackBlockFactory {
|
||||
TrackBlock create(BlockBehaviour.Properties properties, TrackMaterial material);
|
||||
}
|
||||
|
||||
public static final TrackType STANDARD = new TrackType(Create.asResource("standard"), TrackBlock::new);
|
||||
|
||||
public final ResourceLocation id;
|
||||
protected final TrackBlockFactory factory;
|
||||
|
||||
public TrackType(ResourceLocation id, TrackBlockFactory factory) {
|
||||
this.id = id;
|
||||
this.factory = factory;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
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.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;
|
||||
|
||||
public class TrackMaterialFactory {
|
||||
private final ResourceLocation id;
|
||||
private String langName;
|
||||
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;
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
public static TrackMaterialFactory make(ResourceLocation id) { // Convenience function for static import
|
||||
return new TrackMaterialFactory(id);
|
||||
}
|
||||
|
||||
public TrackMaterialFactory lang(String langName) {
|
||||
this.langName = langName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackMaterialFactory block(NonNullSupplier<NonNullSupplier<? extends TrackBlock>> trackBlock) {
|
||||
this.trackBlock = trackBlock;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackMaterialFactory defaultModels() { // was setBuiltin
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> this.modelHolder = TrackMaterial.TrackModelHolder.DEFAULT);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackMaterialFactory sleeper(Ingredient sleeperIngredient) {
|
||||
this.sleeperIngredient = sleeperIngredient;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackMaterialFactory sleeper(ItemLike... items) {
|
||||
this.sleeperIngredient = Ingredient.of(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackMaterialFactory rails(Ingredient railsIngredient) {
|
||||
this.railsIngredient = railsIngredient;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackMaterialFactory rails(ItemLike... items) {
|
||||
this.railsIngredient = Ingredient.of(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackMaterialFactory noRecipeGen() {
|
||||
this.railsIngredient = Ingredient.EMPTY;
|
||||
this.sleeperIngredient = Ingredient.EMPTY;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackMaterialFactory particle(ResourceLocation particle) {
|
||||
this.particle = particle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackMaterialFactory trackType(TrackMaterial.TrackType trackType) {
|
||||
this.trackType = trackType;
|
||||
return this;
|
||||
}
|
||||
|
||||
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(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;
|
||||
}
|
||||
|
||||
public TrackMaterial build() {
|
||||
assert trackBlock != null;
|
||||
assert langName != null;
|
||||
assert particle != null;
|
||||
assert trackType != null;
|
||||
assert sleeperIngredient != null;
|
||||
assert railsIngredient != null;
|
||||
assert id != null;
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.simibubi.create.content.logistics.trains.track;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.AllTags;
|
||||
import com.simibubi.create.content.logistics.trains.management.edgePoint.TrackTargetingBlockItem;
|
||||
import com.simibubi.create.content.logistics.trains.track.TrackBlockOutline.BezierPointSelection;
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
|
@ -117,7 +117,7 @@ public class CurvedTrackInteraction {
|
|||
if (event.isUseItem()) {
|
||||
ItemStack heldItem = player.getMainHandItem();
|
||||
Item item = heldItem.getItem();
|
||||
if (AllBlocks.TRACK.isIn(heldItem)) {
|
||||
if (AllTags.AllBlockTags.TRACKS.matches(heldItem)) {
|
||||
player.displayClientMessage(Lang.translateDirect("track.turn_start")
|
||||
.withStyle(ChatFormatting.RED), true);
|
||||
player.swing(InteractionHand.MAIN_HAND);
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.simibubi.create.content.logistics.trains.track;
|
|||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllTags;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -16,7 +16,7 @@ public class PlaceExtendedCurvePacket extends SimplePacketBase {
|
|||
|
||||
boolean mainHand;
|
||||
boolean ctrlDown;
|
||||
|
||||
|
||||
public PlaceExtendedCurvePacket(boolean mainHand, boolean ctrlDown) {
|
||||
this.mainHand = mainHand;
|
||||
this.ctrlDown = ctrlDown;
|
||||
|
@ -39,7 +39,7 @@ public class PlaceExtendedCurvePacket extends SimplePacketBase {
|
|||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer sender = ctx.getSender();
|
||||
ItemStack stack = sender.getItemInHand(mainHand ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND);
|
||||
if (!AllBlocks.TRACK.isIn(stack) || !stack.hasTag())
|
||||
if (!AllTags.AllBlockTags.TRACKS.matches(stack) || !stack.hasTag())
|
||||
return;
|
||||
CompoundTag tag = stack.getTag();
|
||||
tag.putBoolean("ExtendCurve", true);
|
||||
|
|
|
@ -19,6 +19,13 @@ import java.util.Random;
|
|||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.simibubi.create.AllTags;
|
||||
|
||||
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;
|
||||
|
@ -113,13 +120,18 @@ public class TrackBlock extends Block
|
|||
public static final EnumProperty<TrackShape> SHAPE = EnumProperty.create("shape", TrackShape.class);
|
||||
public static final BooleanProperty HAS_TE = BooleanProperty.create("turn");
|
||||
|
||||
public TrackBlock(Properties p_49795_) {
|
||||
protected final TrackMaterial material;
|
||||
|
||||
public TrackBlock(Properties p_49795_, TrackMaterial material) {
|
||||
super(p_49795_);
|
||||
registerDefaultState(defaultBlockState().setValue(SHAPE, TrackShape.ZO)
|
||||
.setValue(HAS_TE, false)
|
||||
.setValue(WATERLOGGED, false));
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(Builder<Block, BlockState> p_49915_) {
|
||||
super.createBlockStateDefinition(p_49915_.add(SHAPE, HAS_TE, WATERLOGGED));
|
||||
|
@ -407,7 +419,7 @@ public class TrackBlock extends Block
|
|||
return list;
|
||||
BlockPos boundPos = trackTE.boundLocation.getSecond();
|
||||
BlockState boundState = otherLevel.getBlockState(boundPos);
|
||||
if (!AllBlocks.TRACK.has(boundState))
|
||||
if (!AllTags.AllBlockTags.TRACKS.matches(boundState))
|
||||
return list;
|
||||
|
||||
Vec3 center = Vec3.atBottomCenterOf(pos)
|
||||
|
@ -750,7 +762,8 @@ public class TrackBlock extends Block
|
|||
|
||||
@Override
|
||||
public ItemRequirement getRequiredItems(BlockState state, BlockEntity te) {
|
||||
int trackAmount = 1;
|
||||
int sameTypeTrackAmount = 1;
|
||||
Object2IntMap<TrackMaterial> otherTrackAmounts = new Object2IntArrayMap<>();
|
||||
int girderAmount = 0;
|
||||
|
||||
if (te instanceof TrackTileEntity track) {
|
||||
|
@ -758,15 +771,27 @@ public class TrackBlock extends Block
|
|||
.values()) {
|
||||
if (!bezierConnection.isPrimary())
|
||||
continue;
|
||||
trackAmount += bezierConnection.getTrackItemCost();
|
||||
TrackMaterial material = bezierConnection.getMaterial();
|
||||
if (material == getMaterial()) {
|
||||
sameTypeTrackAmount += bezierConnection.getTrackItemCost();
|
||||
} else {
|
||||
otherTrackAmounts.put(material, otherTrackAmounts.getOrDefault(material, 0) + 1);
|
||||
}
|
||||
girderAmount += bezierConnection.getGirderItemCost();
|
||||
}
|
||||
}
|
||||
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
while (trackAmount > 0) {
|
||||
stacks.add(AllBlocks.TRACK.asStack(Math.min(trackAmount, 64)));
|
||||
trackAmount -= 64;
|
||||
while (sameTypeTrackAmount > 0) {
|
||||
stacks.add(new ItemStack(state.getBlock(), Math.min(sameTypeTrackAmount, 64)));
|
||||
sameTypeTrackAmount -= 64;
|
||||
}
|
||||
for (TrackMaterial material : otherTrackAmounts.keySet()) {
|
||||
int amt = otherTrackAmounts.getOrDefault(material, 0);
|
||||
while (amt > 0) {
|
||||
stacks.add(new ItemStack(material.getTrackBlock().get(), Math.min(amt, 64)));
|
||||
amt -= 64;
|
||||
}
|
||||
}
|
||||
while (girderAmount > 0) {
|
||||
stacks.add(AllBlocks.METAL_GIRDER.asStack(Math.min(girderAmount, 64)));
|
||||
|
@ -776,6 +801,11 @@ public class TrackBlock extends Block
|
|||
return new ItemRequirement(ItemUseType.CONSUME, stacks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackMaterial getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public static class RenderProperties extends ReducedDestroyEffects implements MultiPosDestructionHandler {
|
||||
@Override
|
||||
@Nullable
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.logistics.trains.track;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllSoundEvents;
|
||||
import com.simibubi.create.AllTags;
|
||||
import com.simibubi.create.content.logistics.trains.ITrackBlock;
|
||||
import com.simibubi.create.content.logistics.trains.track.TrackPlacement.PlacementInfo;
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
|
@ -111,7 +112,7 @@ public class TrackBlockItem extends BlockItem {
|
|||
return InteractionResult.SUCCESS;
|
||||
|
||||
stack = player.getMainHandItem();
|
||||
if (AllBlocks.TRACK.isIn(stack)) {
|
||||
if (AllTags.AllBlockTags.TRACKS.matches(stack)) {
|
||||
stack.setTag(null);
|
||||
player.setItemInHand(pContext.getHand(), stack);
|
||||
}
|
||||
|
@ -154,7 +155,7 @@ public class TrackBlockItem extends BlockItem {
|
|||
@OnlyIn(Dist.CLIENT)
|
||||
public static void sendExtenderPacket(PlayerInteractEvent.RightClickBlock event) {
|
||||
ItemStack stack = event.getItemStack();
|
||||
if (!AllBlocks.TRACK.isIn(stack) || !stack.hasTag())
|
||||
if (!AllTags.AllBlockTags.TRACKS.matches(stack) || !stack.hasTag())
|
||||
return;
|
||||
if (Minecraft.getInstance().options.keySprint.isDown())
|
||||
AllPackets.channel
|
||||
|
|
|
@ -8,8 +8,8 @@ import java.util.function.Consumer;
|
|||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.AllTags;
|
||||
import com.simibubi.create.content.logistics.trains.BezierConnection;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||
|
@ -161,7 +161,7 @@ public class TrackBlockOutline {
|
|||
.rotateXRadians(angles.x)
|
||||
.translate(-.5, -.125f, -.5);
|
||||
|
||||
boolean holdingTrack = AllBlocks.TRACK.isIn(Minecraft.getInstance().player.getMainHandItem());
|
||||
boolean holdingTrack = AllTags.AllBlockTags.TRACKS.matches(Minecraft.getInstance().player.getMainHandItem());
|
||||
renderShape(AllShapes.TRACK_ORTHO.get(Direction.SOUTH), ms, vb, holdingTrack ? false : null);
|
||||
ms.popPose();
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ public class TrackBlockOutline {
|
|||
ms.pushPose();
|
||||
ms.translate(pos.getX() - camPos.x, pos.getY() - camPos.y, pos.getZ() - camPos.z);
|
||||
|
||||
boolean holdingTrack = AllBlocks.TRACK.isIn(Minecraft.getInstance().player.getMainHandItem());
|
||||
boolean holdingTrack = AllTags.AllBlockTags.TRACKS.matches(Minecraft.getInstance().player.getMainHandItem());
|
||||
TrackShape shape = blockstate.getValue(TrackBlock.SHAPE);
|
||||
boolean isJunction = shape.isJunction();
|
||||
walkShapes(shape, TransformStack.cast(ms), s -> {
|
||||
|
|
|
@ -20,6 +20,7 @@ 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.TrackMaterial;
|
||||
import com.simibubi.create.foundation.utility.Couple;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
|
||||
|
@ -38,7 +39,7 @@ public class TrackInstance extends BlockEntityInstance<TrackTileEntity> {
|
|||
|
||||
@Override
|
||||
public void update() {
|
||||
if (blockEntity.connections.isEmpty())
|
||||
if (blockEntity.connections.isEmpty())
|
||||
return;
|
||||
|
||||
remove();
|
||||
|
@ -112,11 +113,13 @@ public class TrackInstance extends BlockEntityInstance<TrackTileEntity> {
|
|||
leftLightPos = new BlockPos[segCount];
|
||||
rightLightPos = new BlockPos[segCount];
|
||||
|
||||
mat.getModel(AllBlockPartials.TRACK_TIE)
|
||||
TrackMaterial.TrackModelHolder modelHolder = bc.getMaterial().getModelHolder();
|
||||
|
||||
mat.getModel(modelHolder.tie())
|
||||
.createInstances(ties);
|
||||
mat.getModel(AllBlockPartials.TRACK_SEGMENT_LEFT)
|
||||
mat.getModel(modelHolder.segment_left())
|
||||
.createInstances(left);
|
||||
mat.getModel(AllBlockPartials.TRACK_SEGMENT_RIGHT)
|
||||
mat.getModel(modelHolder.segment_right())
|
||||
.createInstances(right);
|
||||
|
||||
SegmentAngles[] segments = bc.getBakedSegments();
|
||||
|
|
|
@ -7,12 +7,13 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import com.jozufozu.flywheel.util.Color;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllSpecialTextures;
|
||||
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.ITrackBlock;
|
||||
import com.simibubi.create.content.logistics.trains.TrackMaterial;
|
||||
import com.simibubi.create.foundation.advancement.AllAdvancements;
|
||||
import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
|
@ -47,6 +48,7 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.HitResult.Type;
|
||||
|
@ -58,6 +60,11 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
|||
public class TrackPlacement {
|
||||
|
||||
public static class PlacementInfo {
|
||||
|
||||
public PlacementInfo(TrackMaterial material) {
|
||||
this.trackMaterial = material;
|
||||
}
|
||||
|
||||
BezierConnection curve = null;
|
||||
boolean valid = false;
|
||||
int end1Extent = 0;
|
||||
|
@ -69,6 +76,7 @@ public class TrackPlacement {
|
|||
|
||||
public int requiredPavement = 0;
|
||||
public boolean hasRequiredPavement = false;
|
||||
public final TrackMaterial trackMaterial;
|
||||
|
||||
// for visualisation
|
||||
Vec3 end1;
|
||||
|
@ -108,7 +116,7 @@ public class TrackPlacement {
|
|||
&& hoveringMaxed == maximiseTurn && lookAngle == hoveringAngle)
|
||||
return cached;
|
||||
|
||||
PlacementInfo info = new PlacementInfo();
|
||||
PlacementInfo info = new PlacementInfo(TrackMaterial.fromItem(stack.getItem()));
|
||||
hoveringMaxed = maximiseTurn;
|
||||
hoveringAngle = lookAngle;
|
||||
hoveringPos = pos2;
|
||||
|
@ -192,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);
|
||||
Couple.create(normal1, normal2), true, girder, TrackMaterial.fromItem(stack.getItem()));
|
||||
}
|
||||
|
||||
// S curve or Straight
|
||||
|
@ -281,10 +289,10 @@ public class TrackPlacement {
|
|||
if (skipCurve && !Mth.equal(ascend, 0)) {
|
||||
int hDistance = info.end1Extent;
|
||||
if (axis1.y == 0 || !Mth.equal(absAscend + 1, dist / axis1.length())) {
|
||||
|
||||
|
||||
if (axis1.y != 0 && axis1.y == -axis2.y)
|
||||
return info.withMessage("ascending_s_curve");
|
||||
|
||||
|
||||
info.end1Extent = 0;
|
||||
double minHDistance = Math.max(absAscend < 4 ? absAscend * 4 : absAscend * 3, 6) / axis1.length();
|
||||
if (hDistance < minHDistance)
|
||||
|
@ -352,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);
|
||||
Couple.create(normal1, normal2), true, girder, TrackMaterial.fromItem(stack.getItem()));
|
||||
|
||||
info.valid = true;
|
||||
|
||||
|
@ -397,7 +405,7 @@ public class TrackPlacement {
|
|||
continue;
|
||||
|
||||
ItemStack stackInSlot = (offhand ? inv.offhand : inv.items).get(i);
|
||||
boolean isTrack = AllBlocks.TRACK.isIn(stackInSlot);
|
||||
boolean isTrack = AllTags.AllBlockTags.TRACKS.matches(stackInSlot) && stackInSlot.is(stack.getItem());
|
||||
if (!isTrack && (!shouldPave || offhandItem.getItem() != stackInSlot.getItem()))
|
||||
continue;
|
||||
if (isTrack ? foundTracks >= tracks : foundPavement >= pavement)
|
||||
|
@ -445,10 +453,10 @@ public class TrackPlacement {
|
|||
BlockItem paveItem = (BlockItem) offhandItem.getItem();
|
||||
paveTracks(level, info, paveItem, false);
|
||||
}
|
||||
|
||||
|
||||
if (info.curve != null && info.curve.getLength() > 29)
|
||||
AllAdvancements.LONG_BEND.awardTo(player);
|
||||
|
||||
|
||||
return placeTracks(level, info, state1, state2, targetPos1, targetPos2, false);
|
||||
}
|
||||
|
||||
|
@ -474,6 +482,18 @@ public class TrackPlacement {
|
|||
info.requiredPavement += TrackPaver.paveCurve(level, info.curve, block, simulate, visited);
|
||||
}
|
||||
|
||||
private static BlockState copyProperties(BlockState from, BlockState onto) {
|
||||
for (Property property : onto.getProperties()) {
|
||||
if (from.hasProperty(property))
|
||||
onto = onto.setValue(property, from.getValue(property));
|
||||
}
|
||||
return onto;
|
||||
}
|
||||
|
||||
private static BlockState copyProperties(BlockState from, BlockState onto, boolean keepFrom) {
|
||||
return keepFrom ? from : copyProperties(from, onto);
|
||||
}
|
||||
|
||||
private static PlacementInfo placeTracks(Level level, PlacementInfo info, BlockState state1, BlockState state2,
|
||||
BlockPos targetPos1, BlockPos targetPos2, boolean simulate) {
|
||||
info.requiredTracks = 0;
|
||||
|
@ -501,7 +521,8 @@ public class TrackPlacement {
|
|||
Vec3 offset = axis.scale(i);
|
||||
BlockPos offsetPos = pos.offset(offset.x, offset.y, offset.z);
|
||||
BlockState stateAtPos = level.getBlockState(offsetPos);
|
||||
BlockState toPlace = state;
|
||||
// copy over all shared properties from the shaped state to the correct track material block
|
||||
BlockState toPlace = copyProperties(state, info.trackMaterial.getTrackBlock().get().defaultBlockState());
|
||||
|
||||
boolean canPlace = stateAtPos.getMaterial()
|
||||
.isReplaceable();
|
||||
|
@ -524,15 +545,16 @@ public class TrackPlacement {
|
|||
return info;
|
||||
|
||||
if (!simulate) {
|
||||
BlockState onto = info.trackMaterial.getTrackBlock().get().defaultBlockState();
|
||||
BlockState stateAtPos = level.getBlockState(targetPos1);
|
||||
level.setBlock(targetPos1, ProperWaterloggedBlock.withWater(level,
|
||||
(stateAtPos.getBlock() == state1.getBlock() ? stateAtPos : state1).setValue(TrackBlock.HAS_TE, true),
|
||||
targetPos1), 3);
|
||||
(AllTags.AllBlockTags.TRACKS.matches(stateAtPos) ? stateAtPos : copyProperties(state1, onto))
|
||||
.setValue(TrackBlock.HAS_TE, true), targetPos1), 3);
|
||||
|
||||
stateAtPos = level.getBlockState(targetPos2);
|
||||
level.setBlock(targetPos2, ProperWaterloggedBlock.withWater(level,
|
||||
(stateAtPos.getBlock() == state2.getBlock() ? stateAtPos : state2).setValue(TrackBlock.HAS_TE, true),
|
||||
targetPos2), 3);
|
||||
(AllTags.AllBlockTags.TRACKS.matches(stateAtPos) ? stateAtPos : copyProperties(state2, onto))
|
||||
.setValue(TrackBlock.HAS_TE, true), targetPos2), 3);
|
||||
}
|
||||
|
||||
BlockEntity te1 = level.getBlockEntity(targetPos1);
|
||||
|
@ -579,10 +601,10 @@ public class TrackPlacement {
|
|||
return;
|
||||
|
||||
InteractionHand hand = InteractionHand.MAIN_HAND;
|
||||
if (!AllBlocks.TRACK.isIn(stack)) {
|
||||
if (!AllTags.AllBlockTags.TRACKS.matches(stack)) {
|
||||
stack = player.getOffhandItem();
|
||||
hand = InteractionHand.OFF_HAND;
|
||||
if (!AllBlocks.TRACK.isIn(stack))
|
||||
if (!AllTags.AllBlockTags.TRACKS.matches(stack))
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -621,7 +643,7 @@ public class TrackPlacement {
|
|||
if (bhr.getDirection() == Direction.UP) {
|
||||
Vec3 lookVec = player.getLookAngle();
|
||||
int lookAngle = (int) (22.5 + AngleHelper.deg(Mth.atan2(lookVec.z, lookVec.x)) % 360) / 8;
|
||||
|
||||
|
||||
if (!pos.equals(hintPos) || lookAngle != hintAngle) {
|
||||
hints = Couple.create(ArrayList::new);
|
||||
hintAngle = lookAngle;
|
||||
|
|
|
@ -3,9 +3,6 @@ package com.simibubi.create.content.logistics.trains.track;
|
|||
import static com.simibubi.create.AllBlockPartials.GIRDER_SEGMENT_BOTTOM;
|
||||
import static com.simibubi.create.AllBlockPartials.GIRDER_SEGMENT_MIDDLE;
|
||||
import static com.simibubi.create.AllBlockPartials.GIRDER_SEGMENT_TOP;
|
||||
import static com.simibubi.create.AllBlockPartials.TRACK_SEGMENT_LEFT;
|
||||
import static com.simibubi.create.AllBlockPartials.TRACK_SEGMENT_RIGHT;
|
||||
import static com.simibubi.create.AllBlockPartials.TRACK_TIE;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
||||
|
@ -15,6 +12,7 @@ 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.TrackMaterial;
|
||||
import com.simibubi.create.foundation.render.CachedBufferer;
|
||||
import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
|
@ -66,7 +64,9 @@ public class TrackRenderer extends SafeTileEntityRenderer<TrackTileEntity> {
|
|||
SegmentAngles segment = segments[i];
|
||||
int light = LevelRenderer.getLightColor(level, segment.lightPosition.offset(tePosition));
|
||||
|
||||
CachedBufferer.partial(TRACK_TIE, air)
|
||||
TrackMaterial.TrackModelHolder modelHolder = bc.getMaterial().getModelHolder();
|
||||
|
||||
CachedBufferer.partial(modelHolder.tie(), air)
|
||||
.mulPose(segment.tieTransform.pose())
|
||||
.mulNormal(segment.tieTransform.normal())
|
||||
.light(light)
|
||||
|
@ -74,7 +74,7 @@ public class TrackRenderer extends SafeTileEntityRenderer<TrackTileEntity> {
|
|||
|
||||
for (boolean first : Iterate.trueAndFalse) {
|
||||
Pose transform = segment.railTransforms.get(first);
|
||||
CachedBufferer.partial(first ? TRACK_SEGMENT_LEFT : TRACK_SEGMENT_RIGHT, air)
|
||||
CachedBufferer.partial(first ? modelHolder.segment_left() : modelHolder.segment_right(), air)
|
||||
.mulPose(transform.pose())
|
||||
.mulNormal(transform.normal())
|
||||
.light(light)
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Set;
|
|||
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllTags;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ITransformableTE;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.StructureTransform;
|
||||
import com.simibubi.create.content.logistics.trains.BezierConnection;
|
||||
|
@ -112,6 +113,9 @@ public class TrackTileEntity extends SmartTileEntity implements ITransformableTE
|
|||
}
|
||||
|
||||
public void addConnection(BezierConnection connection) {
|
||||
// don't replace existing connections with different materials
|
||||
if (connections.containsKey(connection.getKey()) && connection.equalsSansMaterial(connections.get(connection.getKey())))
|
||||
return;
|
||||
connections.put(connection.getKey(), connection);
|
||||
level.scheduleTick(worldPosition, getBlockState().getBlock(), 1);
|
||||
notifyUpdate();
|
||||
|
@ -287,7 +291,7 @@ public class TrackTileEntity extends SmartTileEntity implements ITransformableTE
|
|||
.getLevel(boundLocation.getFirst());
|
||||
if (otherLevel == null)
|
||||
return;
|
||||
if (AllBlocks.TRACK.has(otherLevel.getBlockState(boundLocation.getSecond())))
|
||||
if (AllTags.AllBlockTags.TRACKS.matches(otherLevel.getBlockState(boundLocation.getSecond())))
|
||||
otherLevel.destroyBlock(boundLocation.getSecond(), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.simibubi.create.foundation.ponder.content;
|
|||
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;
|
||||
|
@ -20,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 {
|
||||
|
||||
|
@ -303,7 +312,12 @@ public class PonderIndex {
|
|||
.addStoryBoard("rose_quartz_lamp", RedstoneScenes2::roseQuartzLamp);
|
||||
|
||||
// Trains
|
||||
HELPER.forComponents(AllBlocks.TRACK)
|
||||
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