resolve review issues

This commit is contained in:
techno-sam 2023-05-09 20:15:00 -07:00
parent b1bffbf7fd
commit bae8244873
8 changed files with 61 additions and 27 deletions

View file

@ -105,7 +105,7 @@ public class BlueprintOverlayRenderer {
int tracks = info.requiredTracks;
while (tracks > 0) {
ingredients.add(Pair.of(new ItemStack(info.trackMaterial.getTrackBlock().get(), Math.min(64, tracks)), info.hasRequiredTracks));
ingredients.add(Pair.of(new ItemStack(info.trackMaterial.getBlock(), Math.min(64, tracks)), info.hasRequiredTracks));
tracks -= 64;
}

View file

@ -322,7 +322,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
Inventory inv = player.getInventory();
int tracks = getTrackItemCost();
while (tracks > 0) {
inv.placeItemBackInInventory(new ItemStack(getMaterial().getTrackBlock().get(), Math.min(64, tracks)));
inv.placeItemBackInInventory(new ItemStack(getMaterial().getBlock(), Math.min(64, tracks)));
tracks -= 64;
}
int girders = getGirderItemCost();
@ -350,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, new ItemStack(getMaterial().getTrackBlock().get()));
ItemEntity entity = new ItemEntity(level, v.x, v.y, v.z, getMaterial().asStack());
entity.setDefaultPickUpDelay();
level.addFreshEntity(entity);
if (!hasGirder)
@ -364,7 +364,7 @@ public class BezierConnection implements Iterable<BezierConnection.Segment> {
}
public void spawnDestroyParticles(Level level) {
BlockParticleOption data = new BlockParticleOption(ParticleTypes.BLOCK, getMaterial().getTrackBlock().get().defaultBlockState());
BlockParticleOption data = new BlockParticleOption(ParticleTypes.BLOCK, getMaterial().getBlock().defaultBlockState());
BlockParticleOption girderData =
new BlockParticleOption(ParticleTypes.BLOCK, AllBlocks.METAL_GIRDER.getDefaultState());
if (!(level instanceof ServerLevel slevel))

View file

@ -48,7 +48,7 @@ public class BogeySizes {
return BOGEY_SIZES.size();
}
public record BogeySize(ResourceLocation location, Float wheelRadius) {
public record BogeySize(ResourceLocation location, float wheelRadius) {
public BogeySize(String modId, String name, float wheelRadius) {
this(new ResourceLocation(modId, name), wheelRadius);
}

View file

@ -274,7 +274,7 @@ public class TrackGraphVisualizer {
if (extended) {
Vec3 materialPos = edge.getPosition(0.5).add(0, 1, 0);
CreateClient.OUTLINER.showItem(Pair.of(edge, edge.edgeData), materialPos,
new ItemStack(edge.getTrackMaterial().trackBlock.get().get()));
edge.getTrackMaterial().asStack());
CreateClient.OUTLINER.showAABB(edge.edgeData, AABB.ofSize(materialPos, 1, 1, 1))
.colored(graph.color);
}
@ -292,7 +292,7 @@ public class TrackGraphVisualizer {
if (extended) {
Vec3 materialPos = edge.getPosition(0.5).add(0, 1, 0);
CreateClient.OUTLINER.showItem(Pair.of(edge, edge.edgeData), materialPos,
new ItemStack(edge.getTrackMaterial().trackBlock.get().get()));
edge.getTrackMaterial().asStack());
CreateClient.OUTLINER.showAABB(edge.edgeData, AABB.ofSize(materialPos, 1, 1, 1))
.colored(graph.color);
}

View file

@ -11,13 +11,15 @@ 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.ItemStack;
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 org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -44,6 +46,9 @@ public class TrackMaterial {
public final ResourceLocation particle;
public final TrackType trackType;
@Nullable
private final TrackMaterial.TrackType.TrackBlockFactory customFactory;
@OnlyIn(Dist.CLIENT)
protected TrackModelHolder modelHolder;
@ -55,6 +60,13 @@ public class TrackMaterial {
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, langName, trackBlock, particle, sleeperIngredient, railsIngredient, trackType, modelHolder, null);
}
public TrackMaterial(ResourceLocation id, String langName, NonNullSupplier<NonNullSupplier<? extends TrackBlock>> trackBlock,
ResourceLocation particle, Ingredient sleeperIngredient, Ingredient railsIngredient,
TrackType trackType, Supplier<Supplier<TrackModelHolder>> modelHolder,
@Nullable TrackType.TrackBlockFactory customFactory) {
this.id = id;
this.langName = langName;
this.trackBlock = trackBlock;
@ -62,30 +74,44 @@ public class TrackMaterial {
this.railsIngredient = railsIngredient;
this.particle = particle;
this.trackType = trackType;
this.customFactory = customFactory;
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> this.modelHolder = modelHolder.get().get());
ALL.put(this.id, this);
}
public NonNullSupplier<? extends TrackBlock> getTrackBlock() {
public NonNullSupplier<? extends TrackBlock> getBlockSupplier() {
return this.trackBlock.get();
}
public TrackBlock createBlock(BlockBehaviour.Properties properties) {
return this.trackType.factory.create(properties, this);
public TrackBlock getBlock() {
return getBlockSupplier().get();
}
public boolean isCustom(String modId) {
public ItemStack asStack() {
return asStack(1);
}
public ItemStack asStack(int count) {
return new ItemStack(getBlock(), count);
}
public TrackBlock createBlock(BlockBehaviour.Properties properties) {
return (this.customFactory != null ? this.customFactory : this.trackType.factory)
.create(properties, this);
}
public boolean isFromMod(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<TrackMaterial> allFromMod(String modid) {
return ALL.values().stream().filter(tm -> tm.isFromMod(modid)).toList();
}
public static List<NonNullSupplier<? extends TrackBlock>> allCustomBlocks(String modid) {
public static List<NonNullSupplier<? extends TrackBlock>> allBlocksFromMod(String modid) {
List<NonNullSupplier<? extends TrackBlock>> list = new ArrayList<>();
for (TrackMaterial material : allCustom(modid)) {
list.add(material.getTrackBlock());
for (TrackMaterial material : allFromMod(modid)) {
list.add(material.getBlockSupplier());
}
return list;
}
@ -93,7 +119,7 @@ public class TrackMaterial {
public static List<NonNullSupplier<? extends TrackBlock>> allBlocks() {
List<NonNullSupplier<? extends TrackBlock>> list = new ArrayList<>();
for (TrackMaterial material : ALL.values()) {
list.add(material.getTrackBlock());
list.add(material.getBlockSupplier());
}
return list;
}
@ -108,17 +134,15 @@ public class TrackMaterial {
Create.LOGGER.error("Failed to parse serialized track material: "+serializedName);
return ANDESITE;
}
for (TrackMaterial material : ALL.values()) {
if (material.id.equals(id))
return material;
}
if (ALL.containsKey(id))
return ALL.get(id);
Create.LOGGER.error("Failed to locate serialized track material: "+serializedName);
return ANDESITE;
}
public static class TrackType {
@FunctionalInterface
protected interface TrackBlockFactory {
public interface TrackBlockFactory {
TrackBlock create(BlockBehaviour.Properties properties, TrackMaterial material);
}

View file

@ -13,6 +13,8 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.DistExecutor;
import org.jetbrains.annotations.Nullable;
import java.util.function.Supplier;
import java.util.stream.Stream;
@ -25,6 +27,9 @@ public class TrackMaterialFactory {
private ResourceLocation particle;
private TrackMaterial.TrackType trackType = TrackMaterial.TrackType.STANDARD;
@Nullable
private TrackMaterial.TrackType.TrackBlockFactory customFactory = null;
@OnlyIn(Dist.CLIENT)
private TrackMaterial.TrackModelHolder modelHolder;
@OnlyIn(Dist.CLIENT)
@ -113,6 +118,11 @@ public class TrackMaterialFactory {
return this;
}
public TrackMaterialFactory customBlockFactory(TrackMaterial.TrackType.TrackBlockFactory factory) {
this.customFactory = factory;
return this;
}
public TrackMaterial build() {
assert trackBlock != null;
assert langName != null;
@ -128,6 +138,6 @@ public class TrackMaterialFactory {
modelHolder = new TrackMaterial.TrackModelHolder(tieModel, leftSegmentModel, rightSegmentModel);
}
});
return new TrackMaterial(id, langName, trackBlock, particle, sleeperIngredient, railsIngredient, trackType, () -> () -> modelHolder);
return new TrackMaterial(id, langName, trackBlock, particle, sleeperIngredient, railsIngredient, trackType, () -> () -> modelHolder, customFactory);
}
}

View file

@ -789,7 +789,7 @@ public class TrackBlock extends Block
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)));
stacks.add(material.asStack(Math.min(amt, 64)));
amt -= 64;
}
}

View file

@ -522,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.trackMaterial.getTrackBlock().get().defaultBlockState());
BlockState toPlace = copyProperties(state, info.trackMaterial.getBlock().defaultBlockState());
boolean canPlace = stateAtPos.getMaterial()
.isReplaceable();
@ -545,7 +545,7 @@ public class TrackPlacement {
return info;
if (!simulate) {
BlockState onto = info.trackMaterial.getTrackBlock().get().defaultBlockState();
BlockState onto = info.trackMaterial.getBlock().defaultBlockState();
BlockState stateAtPos = level.getBlockState(targetPos1);
level.setBlock(targetPos1, ProperWaterloggedBlock.withWater(level,
(AllTags.AllBlockTags.TRACKS.matches(stateAtPos) ? stateAtPos : copyProperties(state1, onto))