fix: backtank crashing on ctrl+pick block (#7284)

This commit is contained in:
VoidLeech 2025-01-12 22:31:15 +01:00 committed by GitHub
parent 18fb3b4beb
commit 0870d34033
Failed to generate hash of commit
2 changed files with 12 additions and 8 deletions

View file

@ -184,8 +184,10 @@ public class BacktankBlock extends HorizontalKineticBlock implements IBE<Backtan
Optional<BacktankBlockEntity> blockEntityOptional = getBlockEntityOptional(blockGetter, pos); Optional<BacktankBlockEntity> blockEntityOptional = getBlockEntityOptional(blockGetter, pos);
CompoundTag forgeCapsTag = blockEntityOptional.map(BacktankBlockEntity::getForgeCapsTag) CompoundTag forgeCapsTag = blockEntityOptional.map(BacktankBlockEntity::getForgeCapsTag)
.map(CompoundTag::copy)
.orElse(null); .orElse(null);
CompoundTag vanillaTag = blockEntityOptional.map(BacktankBlockEntity::getVanillaTag) CompoundTag vanillaTag = blockEntityOptional.map(BacktankBlockEntity::getVanillaTag)
.map(CompoundTag::copy)
.orElse(new CompoundTag()); .orElse(new CompoundTag());
int air = blockEntityOptional.map(BacktankBlockEntity::getAirLevel) int air = blockEntityOptional.map(BacktankBlockEntity::getAirLevel)
.orElse(0); .orElse(0);

View file

@ -120,10 +120,10 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable
compound.putInt("Air", airLevel); compound.putInt("Air", airLevel);
compound.putInt("Timer", airLevelTimer); compound.putInt("Timer", airLevelTimer);
compound.putInt("CapacityEnchantment", capacityEnchantLevel); compound.putInt("CapacityEnchantment", capacityEnchantLevel);
if (this.customName != null) if (this.customName != null)
compound.putString("CustomName", Component.Serializer.toJson(this.customName)); compound.putString("CustomName", Component.Serializer.toJson(this.customName));
compound.put("VanillaTag", vanillaTag); compound.put("VanillaTag", vanillaTag);
if (forgeCapsTag != null) if (forgeCapsTag != null)
compound.put("ForgeCapsTag", forgeCapsTag); compound.put("ForgeCapsTag", forgeCapsTag);
@ -136,10 +136,10 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable
airLevel = compound.getInt("Air"); airLevel = compound.getInt("Air");
airLevelTimer = compound.getInt("Timer"); airLevelTimer = compound.getInt("Timer");
capacityEnchantLevel = compound.getInt("CapacityEnchantment"); capacityEnchantLevel = compound.getInt("CapacityEnchantment");
if (compound.contains("CustomName", 8)) if (compound.contains("CustomName", 8))
this.customName = Component.Serializer.fromJson(compound.getString("CustomName")); this.customName = Component.Serializer.fromJson(compound.getString("CustomName"));
vanillaTag = compound.getCompound("VanillaTag"); vanillaTag = compound.getCompound("VanillaTag");
forgeCapsTag = compound.contains("ForgeCapsTag") ? compound.getCompound("ForgeCapsTag") : null; forgeCapsTag = compound.contains("ForgeCapsTag") ? compound.getCompound("ForgeCapsTag") : null;
@ -181,16 +181,18 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable
public void setCapacityEnchantLevel(int capacityEnchantLevel) { public void setCapacityEnchantLevel(int capacityEnchantLevel) {
this.capacityEnchantLevel = capacityEnchantLevel; this.capacityEnchantLevel = capacityEnchantLevel;
} }
public void setTags(CompoundTag vanillaTag, @Nullable CompoundTag forgeCapsTag) { public void setTags(CompoundTag vanillaTag, @Nullable CompoundTag forgeCapsTag) {
this.vanillaTag = vanillaTag; this.vanillaTag = vanillaTag.copy();
this.forgeCapsTag = forgeCapsTag; this.forgeCapsTag = forgeCapsTag == null ? null : forgeCapsTag.copy();
// Prevent nesting of the ctrl+pick block added tag
vanillaTag.remove("BlockEntityTag");
} }
public CompoundTag getVanillaTag() { public CompoundTag getVanillaTag() {
return vanillaTag; return vanillaTag;
} }
public CompoundTag getForgeCapsTag() { public CompoundTag getForgeCapsTag() {
return forgeCapsTag; return forgeCapsTag;
} }