Skip to content

Commit

Permalink
fix owner information not saving during alch chest change
Browse files Browse the repository at this point in the history
The lid not working after a color change is a known issue, but I'm not that concerned.
  • Loading branch information
DonovanDMC committed Nov 19, 2022
1 parent 75bd227 commit 291c8ba
Showing 1 changed file with 10 additions and 1 deletion.
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.world.level.block.entity.ChestLidController;
import net.minecraft.world.level.block.entity.ContainerOpenersCounter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
Expand Down Expand Up @@ -96,7 +97,15 @@ public InteractionResult handleActivation(Player player, InteractionHand hand) {
this.saveAdditional(new CompoundTag());
if(level != null) {
BlockAdvancedAlchemicalChest block = AdvancedAlchemicalChest.getBlock(bag.color);
level.setBlockAndUpdate(worldPosition, block.defaultBlockState());
BlockEntityType<BlockEntityAdvancedAlchemicalChest> blockEntityType = AdvancedAlchemicalChest.getBlockEntityType(bag.color);

BlockEntityAdvancedAlchemicalChest newBlockEntity = new BlockEntityAdvancedAlchemicalChest(worldPosition, getBlockState(), blockEntityType, bag.color);
newBlockEntity.owner = owner;
newBlockEntity.ownerName = ownerName;
newBlockEntity.saveAdditional(new CompoundTag());
level.setBlockAndUpdate(worldPosition, block.defaultBlockState().setValue(BlockStateProperties.HORIZONTAL_FACING, getBlockState().getValue(BlockStateProperties.HORIZONTAL_FACING)).setValue(BlockStateProperties.WATERLOGGED, getBlockState().getValue(BlockStateProperties.WATERLOGGED)));
level.removeBlockEntity(worldPosition);
level.setBlockEntity(newBlockEntity);
Util.markDirty(level, worldPosition);
}
player.displayClientMessage(new TranslatableComponent("block.projectexpansion.advanced_alchemical_chest.color_set", bag.color.getName()), true);
Expand Down

0 comments on commit 291c8ba

Please sign in to comment.