Skip to content

Commit

Permalink
fix: backtank crashing on ctrl+pick block (#7284)
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidLeech authored Jan 12, 2025
1 parent 18fb3b4 commit 0870d34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ public ItemStack getCloneItemStack(BlockGetter blockGetter, BlockPos pos, BlockS
Optional<BacktankBlockEntity> blockEntityOptional = getBlockEntityOptional(blockGetter, pos);

CompoundTag forgeCapsTag = blockEntityOptional.map(BacktankBlockEntity::getForgeCapsTag)
.map(CompoundTag::copy)
.orElse(null);
CompoundTag vanillaTag = blockEntityOptional.map(BacktankBlockEntity::getVanillaTag)
.map(CompoundTag::copy)
.orElse(new CompoundTag());
int air = blockEntityOptional.map(BacktankBlockEntity::getAirLevel)
.orElse(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ protected void write(CompoundTag compound, boolean clientPacket) {
compound.putInt("Air", airLevel);
compound.putInt("Timer", airLevelTimer);
compound.putInt("CapacityEnchantment", capacityEnchantLevel);

if (this.customName != null)
compound.putString("CustomName", Component.Serializer.toJson(this.customName));

compound.put("VanillaTag", vanillaTag);
if (forgeCapsTag != null)
compound.put("ForgeCapsTag", forgeCapsTag);
Expand All @@ -136,10 +136,10 @@ protected void read(CompoundTag compound, boolean clientPacket) {
airLevel = compound.getInt("Air");
airLevelTimer = compound.getInt("Timer");
capacityEnchantLevel = compound.getInt("CapacityEnchantment");

if (compound.contains("CustomName", 8))
this.customName = Component.Serializer.fromJson(compound.getString("CustomName"));

vanillaTag = compound.getCompound("VanillaTag");
forgeCapsTag = compound.contains("ForgeCapsTag") ? compound.getCompound("ForgeCapsTag") : null;

Expand Down Expand Up @@ -181,16 +181,18 @@ public void setCustomName(Component customName) {
public void setCapacityEnchantLevel(int capacityEnchantLevel) {
this.capacityEnchantLevel = capacityEnchantLevel;
}

public void setTags(CompoundTag vanillaTag, @Nullable CompoundTag forgeCapsTag) {
this.vanillaTag = vanillaTag;
this.forgeCapsTag = forgeCapsTag;
this.vanillaTag = vanillaTag.copy();
this.forgeCapsTag = forgeCapsTag == null ? null : forgeCapsTag.copy();
// Prevent nesting of the ctrl+pick block added tag
vanillaTag.remove("BlockEntityTag");
}

public CompoundTag getVanillaTag() {
return vanillaTag;
}

public CompoundTag getForgeCapsTag() {
return forgeCapsTag;
}
Expand Down

0 comments on commit 0870d34

Please sign in to comment.