Bug Hydra

- Squash one bug and three more pop up
- Fix an assortment of issues
This commit is contained in:
IThundxr 2025-01-19 22:28:15 -05:00
parent f4be0420e9
commit 83372da0af
Failed to generate hash of commit
14 changed files with 52 additions and 42 deletions

View file

@ -740,7 +740,7 @@ public abstract class Contraption {
nbt.getList("Actors", Tag.TAG_COMPOUND)
.forEach(c -> {
CompoundTag comp = (CompoundTag) c;
StructureBlockInfo info = this.blocks.get(NbtUtils.readBlockPos(comp, "Pos").orElseThrow());
StructureBlockInfo info = this.blocks.get(NbtUtils.readBlockPos(comp, "Pos").orElse(BlockPos.ZERO));
if (info == null)
return;
MovementContext context = MovementContext.readNBT(world, info, comp, this);
@ -976,7 +976,7 @@ public abstract class Contraption {
}
private static StructureBlockInfo legacyReadStructureBlockInfo(CompoundTag blockListEntry, HolderGetter<Block> holderGetter) {
return new StructureBlockInfo(NbtUtils.readBlockPos(blockListEntry, "Pos").orElseThrow(),
return new StructureBlockInfo(NbtUtils.readBlockPos(blockListEntry, "Pos").orElse(BlockPos.ZERO),
NbtUtils.readBlockState(holderGetter, blockListEntry.getCompound("Block")),
blockListEntry.contains("Data") ? blockListEntry.getCompound("Data") : null);
}

View file

@ -98,11 +98,11 @@ public class MountedStorageManager {
public void read(CompoundTag nbt, HolderLookup.Provider registries, Map<BlockPos, BlockEntity> presentBlockEntities, boolean clientPacket) {
storage.clear();
NBTHelper.iterateCompoundList(nbt.getList("Storage", Tag.TAG_COMPOUND), c -> storage
.put(NbtUtils.readBlockPos(c, "Pos").orElseThrow(), MountedStorage.deserialize(c.getCompound("Data"), registries)));
.put(NbtUtils.readBlockPos(c, "Pos").orElse(BlockPos.ZERO), MountedStorage.deserialize(c.getCompound("Data"), registries)));
fluidStorage.clear();
NBTHelper.iterateCompoundList(nbt.getList("FluidStorage", Tag.TAG_COMPOUND), c -> fluidStorage
.put(NbtUtils.readBlockPos(c, "Pos").orElseThrow(), MountedFluidStorage.deserialize(c.getCompound("Data"), registries)));
.put(NbtUtils.readBlockPos(c, "Pos").orElse(BlockPos.ZERO), MountedFluidStorage.deserialize(c.getCompound("Data"), registries)));
if (clientPacket && presentBlockEntities != null)
bindTanksAndDepots(presentBlockEntities);

View file

@ -294,7 +294,7 @@ public class PulleyBlockEntity extends LinearActuatorBlockEntity implements Thre
BlockPos prevMirrorParent = mirrorParent;
mirrorParent = NbtUtils.readBlockPos(compound, "MirrorParent").orElse(null);
mirrorChildren = NBTHelper.readCompoundList(compound.getList("MirrorChildren", Tag.TAG_COMPOUND), t -> NbtUtils.readBlockPos(t, "Pos").orElseThrow());
mirrorChildren = NBTHelper.readCompoundList(compound.getList("MirrorChildren", Tag.TAG_COMPOUND), t -> NbtUtils.readBlockPos(t, "Pos").orElse(BlockPos.ZERO));
if (mirrorParent != null) {
offset = 0;

View file

@ -45,7 +45,7 @@ public record ToolboxDisposeAllPacket(BlockPos toolboxPos) implements Serverboun
toolbox.inventory.inLimitedMode(inventory -> {
for (int i = 0; i < 36; i++) {
String key = String.valueOf(i);
if (compound.contains(key) && NbtUtils.readBlockPos(compound.getCompound(key),"Pos").orElseThrow()
if (compound.contains(key) && NbtUtils.readBlockPos(compound.getCompound(key),"Pos").orElse(BlockPos.ZERO)
.equals(toolboxPos)) {
ToolboxHandler.unequip(player, i, true);
sendData.setTrue();

View file

@ -31,9 +31,9 @@ import dev.engine_room.flywheel.api.visualization.VisualizationManager;
import net.createmod.catnip.codecs.CatnipCodecUtils;
import net.createmod.catnip.codecs.CatnipCodecs;
import net.createmod.catnip.data.Iterate;
import net.createmod.catnip.nbt.NBTHelper;
import net.createmod.catnip.math.VecHelper;
import net.createmod.catnip.math.AngleHelper;
import net.createmod.catnip.math.VecHelper;
import net.createmod.catnip.nbt.NBTHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.HolderLookup;
@ -62,7 +62,7 @@ public class ChainConveyorBlockEntity extends KineticBlockEntity implements ITra
public record ConnectionStats(float tangentAngle, float chainLength, Vec3 start, Vec3 end) {
}
public record ConnectedPort(float chainPosition, BlockPos connection, String filter) {
public record ConnectedPort(float chainPosition, @Nullable BlockPos connection, String filter) {
}
public Set<BlockPos> connections = new HashSet<>();
@ -693,14 +693,14 @@ public class ChainConveyorBlockEntity extends KineticBlockEntity implements ITra
protected void read(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
super.read(compound, registries, clientPacket);
if (clientPacket && compound.contains("DestroyEffect") && level != null)
spawnDestroyParticles(NbtUtils.readBlockPos(compound, "DestroyEffect").orElseThrow());
spawnDestroyParticles(NbtUtils.readBlockPos(compound, "DestroyEffect").orElse(BlockPos.ZERO));
int sizeBefore = connections.size();
connections.clear();
CatnipCodecUtils.decode(CatnipCodecs.set(BlockPos.CODEC), compound.get("Connections")).ifPresent(connections::addAll);
travellingPackages.clear();
NBTHelper.iterateCompoundList(compound.getList("TravellingPackages", Tag.TAG_COMPOUND),
c -> travellingPackages.put(NbtUtils.readBlockPos(c, "Target").orElseThrow(),
c -> travellingPackages.put(NbtUtils.readBlockPos(c, "Target").orElse(BlockPos.ZERO),
NBTHelper.readCompoundList(c.getList("Packages", Tag.TAG_COMPOUND), t -> ChainConveyorPackage.read(t, registries))));
loopingPackages = NBTHelper.readCompoundList(compound.getList("LoopingPackages", Tag.TAG_COMPOUND),
t -> ChainConveyorPackage.read(t, registries));

View file

@ -2,6 +2,7 @@ package com.simibubi.create.content.logistics.box;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
@ -15,10 +16,9 @@ import com.simibubi.create.content.logistics.box.PackageStyles.PackageStyle;
import com.simibubi.create.content.logistics.stockTicker.PackageOrder;
import com.simibubi.create.foundation.item.ItemHelper;
import net.createmod.catnip.codecs.CatnipCodecs;
import net.createmod.catnip.codecs.stream.CatnipStreamCodecBuilders;
import net.createmod.catnip.math.VecHelper;
import net.createmod.catnip.lang.Components;
import net.createmod.catnip.math.VecHelper;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@ -49,6 +49,7 @@ import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.items.ItemHandlerHelper;
import net.neoforged.neoforge.items.ItemStackHandler;
@ -389,8 +390,9 @@ public class PackageItem extends Item {
Codec.BOOL.fieldOf("is_final_link").forGetter(PackageOrderData::isFinalLink),
Codec.INT.fieldOf("fragment_index").forGetter(PackageOrderData::fragmentIndex),
Codec.BOOL.fieldOf("is_final").forGetter(PackageOrderData::isFinal),
CatnipCodecs.nullableFieldOf(PackageOrder.CODEC, "order_context").forGetter(PackageOrderData::orderContext)
).apply(instance, PackageOrderData::new));
PackageOrder.CODEC.optionalFieldOf("order_context").forGetter(i -> Optional.ofNullable(i.orderContext))
).apply(instance, (orderId, linkIndex, isFinalLink, fragmentIndex, isFinal, orderContext) ->
new PackageOrderData(orderId, linkIndex, isFinalLink, fragmentIndex, isFinal, orderContext.orElse(null))));
public static StreamCodec<RegistryFriendlyByteBuf, PackageOrderData> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.INT, PackageOrderData::orderId,

View file

@ -564,7 +564,7 @@ public class EjectorBlockEntity extends KineticBlockEntity {
earlyTargetTime = 0;
if (compound.contains("EarlyTarget")) {
earlyTarget = Pair.of(VecHelper.readNBT(compound.getList("EarlyTarget", Tag.TAG_DOUBLE)),
NbtUtils.readBlockPos(compound, "EarlyTargetPos").orElseThrow());
NbtUtils.readBlockPos(compound, "EarlyTargetPos").orElse(BlockPos.ZERO));
earlyTargetTime = compound.getFloat("EarlyTargetTime");
}

View file

@ -1,6 +1,7 @@
package com.simibubi.create.content.logistics.packagePort;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nullable;
@ -68,23 +69,27 @@ public abstract class PackagePortTarget {
public static class ChainConveyorFrogportTarget extends PackagePortTarget {
public static MapCodec<ChainConveyorFrogportTarget> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
BlockPos.CODEC.fieldOf("relativePos").forGetter(i -> i.relativePos),
Codec.FLOAT.fieldOf("chainPos").forGetter(i -> i.chainPos),
BlockPos.CODEC.fieldOf("connection").forGetter(i -> i.connection)
BlockPos.CODEC.fieldOf("relative_pos").forGetter(i -> i.relativePos),
Codec.FLOAT.fieldOf("chain_pos").forGetter(i -> i.chainPos),
BlockPos.CODEC.optionalFieldOf("connection").forGetter(i -> i.connection)
).apply(instance, ChainConveyorFrogportTarget::new));
public static StreamCodec<ByteBuf, ChainConveyorFrogportTarget> STREAM_CODEC = StreamCodec.composite(
BlockPos.STREAM_CODEC, i -> i.relativePos,
ByteBufCodecs.FLOAT, i -> i.chainPos,
BlockPos.STREAM_CODEC, i -> i.connection,
ByteBufCodecs.optional(BlockPos.STREAM_CODEC), i -> i.connection,
ChainConveyorFrogportTarget::new
);
public float chainPos;
public BlockPos connection;
public Optional<BlockPos> connection;
public boolean flipped;
public ChainConveyorFrogportTarget(BlockPos relativePos, float chainPos, @Nullable BlockPos connection) {
this(relativePos, chainPos, Optional.ofNullable(connection));
}
public ChainConveyorFrogportTarget(BlockPos relativePos, float chainPos, Optional<BlockPos> connection) {
super(relativePos);
this.chainPos = chainPos;
this.connection = connection;
@ -105,14 +110,14 @@ public abstract class PackagePortTarget {
public boolean export(LevelAccessor level, BlockPos portPos, ItemStack box, boolean simulate) {
if (!(be(level, portPos) instanceof ChainConveyorBlockEntity clbe))
return false;
if (connection != null && !clbe.connections.contains(connection))
if (connection.isPresent() && !clbe.connections.contains(connection.get()))
return false;
if (simulate)
return clbe.getSpeed() != 0 && clbe.canAcceptPackagesFor(connection);
return clbe.getSpeed() != 0 && clbe.canAcceptPackagesFor(connection.get());
ChainConveyorPackage box2 = new ChainConveyorPackage(chainPos, box.copy());
if (connection == null)
if (connection.isEmpty())
return clbe.addLoopingPackage(box2);
return clbe.addTravellingPackage(box2, connection);
return clbe.addTravellingPackage(box2, connection.get());
}
@Override
@ -122,32 +127,32 @@ public abstract class PackagePortTarget {
ChainConveyorBlockEntity actualBe = clbe;
// Jump to opposite chain if motion reversed
if (connection != null && clbe.getSpeed() < 0 != flipped) {
if (connection.isPresent() && clbe.getSpeed() < 0 != flipped) {
deregister(ppbe, level, portPos);
actualBe = AllBlocks.CHAIN_CONVEYOR.get()
.getBlockEntity(level, clbe.getBlockPos()
.offset(connection));
.offset(connection.get()));
if (actualBe == null)
return;
clbe.prepareStats();
ConnectionStats stats = clbe.connectionStats.get(connection);
ConnectionStats stats = clbe.connectionStats.get(connection.get());
if (stats != null)
chainPos = stats.chainLength() - chainPos;
connection = connection.multiply(-1);
connection = Optional.of(connection.get().multiply(-1));
flipped = !flipped;
relativePos = actualBe.getBlockPos()
.subtract(portPos);
ppbe.notifyUpdate();
}
if (connection != null && !actualBe.connections.contains(connection))
if (connection.isPresent() && !actualBe.connections.contains(connection.get()))
return;
String portFilter = ppbe.getFilterString();
if (portFilter == null)
return;
actualBe.routingTable.receivePortInfo(portFilter, connection == null ? BlockPos.ZERO : connection);
Map<BlockPos, ConnectedPort> portMap = connection == null ? actualBe.loopPorts : actualBe.travelPorts;
portMap.put(relativePos.multiply(-1), new ConnectedPort(chainPos, connection, portFilter));
actualBe.routingTable.receivePortInfo(portFilter, connection.orElse(BlockPos.ZERO));
Map<BlockPos, ConnectedPort> portMap = connection.isEmpty() ? actualBe.loopPorts : actualBe.travelPorts;
portMap.put(relativePos.multiply(-1), new ConnectedPort(chainPos, connection.orElse(null), portFilter));
}
@Override
@ -168,7 +173,7 @@ public abstract class PackagePortTarget {
public Vec3 getExactTargetLocation(PackagePortBlockEntity ppbe, LevelAccessor level, BlockPos portPos) {
if (!(be(level, portPos) instanceof ChainConveyorBlockEntity clbe))
return Vec3.ZERO;
return clbe.getPackagePosition(chainPos, connection);
return clbe.getPackagePosition(chainPos, connection.orElse(null));
}
@Override
@ -184,7 +189,7 @@ public abstract class PackagePortTarget {
public static class TrainStationFrogportTarget extends PackagePortTarget {
public static MapCodec<TrainStationFrogportTarget> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
BlockPos.CODEC.fieldOf("relativePos").forGetter(i -> i.relativePos)
BlockPos.CODEC.fieldOf("relative_pos").forGetter(i -> i.relativePos)
).apply(instance, TrainStationFrogportTarget::new));
public static StreamCodec<ByteBuf, TrainStationFrogportTarget> STREAM_CODEC = StreamCodec.composite(

View file

@ -1,5 +1,7 @@
package com.simibubi.create.content.logistics.packager;
import java.util.Optional;
import javax.annotation.Nullable;
import org.apache.commons.lang3.mutable.MutableBoolean;
@ -22,8 +24,9 @@ public record PackagingRequest(ItemStack item, MutableInt count, String address,
CatnipCodecs.MUTABLE_BOOLEAN_CODEC.fieldOf("final_link").forGetter(PackagingRequest::finalLink),
CatnipCodecs.MUTABLE_INT_CODEC.fieldOf("package_counter").forGetter(PackagingRequest::packageCounter),
Codec.INT.fieldOf("order_id").forGetter(PackagingRequest::orderId),
CatnipCodecs.nullableFieldOf(PackageOrder.CODEC, "context").forGetter(PackagingRequest::context)
).apply(instance, PackagingRequest::new));
PackageOrder.CODEC.optionalFieldOf("context").forGetter(i -> Optional.ofNullable(i.context()))
).apply(instance, (item, count, address, linkIndex, finalLink, packageCounter, orderId, context) ->
new PackagingRequest(item, count, address, linkIndex, finalLink, packageCounter, orderId, context.orElse(null))));
public static PackagingRequest create(ItemStack item, int count, String address, int linkIndex,
MutableBoolean finalLink, int packageCount, int orderId, @Nullable PackageOrder context) {

View file

@ -70,7 +70,7 @@ public class SchematicPrinter {
printingEntityIndex = compound.getInt("EntityProgress");
printStage = PrintStage.valueOf(compound.getString("PrintStage"));
compound.getList("DeferredBlocks", 10).stream()
.map(p -> NbtUtils.readBlockPos((CompoundTag) p, "Pos").orElseThrow())
.map(p -> NbtUtils.readBlockPos((CompoundTag) p, "Pos").orElse(BlockPos.ZERO))
.collect(Collectors.toCollection(() -> deferredBlocks));
}

View file

@ -101,7 +101,7 @@ public class ArrivalSoundQueue {
CompoundTag tag = tagIn.getCompound("SoundQueue");
offset = tag.getInt("Offset");
NBTHelper.iterateCompoundList(tag.getList("Sources", Tag.TAG_COMPOUND),
c -> add(c.getInt("Tick"), NbtUtils.readBlockPos(c, "Pos").orElseThrow()));
c -> add(c.getInt("Tick"), NbtUtils.readBlockPos(c, "Pos").orElse(BlockPos.ZERO)));
}
public void add(int offset, BlockPos localPos) {

View file

@ -218,7 +218,7 @@ public class CarriageContraption extends Contraption {
Couple.create(nbt.getBoolean("FrontBlazeConductor"), nbt.getBoolean("BackBlazeConductor"));
conductorSeats.clear();
NBTHelper.iterateCompoundList(nbt.getList("ConductorSeats", Tag.TAG_COMPOUND),
c -> conductorSeats.put(NbtUtils.readBlockPos(c, "Pos").orElseThrow(),
c -> conductorSeats.put(NbtUtils.readBlockPos(c, "Pos").orElse(BlockPos.ZERO),
Couple.create(c.getBoolean("Forward"), c.getBoolean("Backward"))));
soundQueue.deserialize(nbt);
super.readNBT(world, nbt, spawnData);

View file

@ -83,7 +83,7 @@ public class TrackNodeLocation extends Vec3i {
}
public static TrackNodeLocation read(CompoundTag tag, DimensionPalette dimensions) {
TrackNodeLocation location = fromPackedPos(NbtUtils.readBlockPos(tag, "Pos").orElseThrow());
TrackNodeLocation location = fromPackedPos(NbtUtils.readBlockPos(tag, "Pos").orElse(BlockPos.ZERO));
if (dimensions != null)
location.dimension = dimensions.decode(tag.getInt("D"));
location.yOffsetPixels = tag.getInt("YO");

View file

@ -71,7 +71,7 @@ public class GlobalStation extends SingleBlockEntityEdgePoint {
port.address = c.getString("Address");
port.offlineBuffer.deserializeNBT(registries, c.getCompound("OfflineBuffer"));
port.primed = c.getBoolean("Primed");
connectedPorts.put(NbtUtils.readBlockPos(c, "Pos").orElseThrow(), port);
connectedPorts.put(NbtUtils.readBlockPos(c, "Pos").orElse(BlockPos.ZERO), port);
});
}