Reimplement the changes that I reverted to fix #183 and #184

This commit is contained in:
alexbegt 2019-06-10 21:45:30 -04:00
parent 4b51dbf062
commit 0620ea0d8a
4 changed files with 69 additions and 0 deletions

View File

@ -81,6 +81,8 @@ public class ItemChestChanger extends ItemTooltip
NonNullList<ItemStack> chestContents = NonNullList.<ItemStack> withSize(27, ItemStack.EMPTY); NonNullList<ItemStack> chestContents = NonNullList.<ItemStack> withSize(27, ItemStack.EMPTY);
EnumFacing chestFacing = EnumFacing.DOWN; EnumFacing chestFacing = EnumFacing.DOWN;
boolean hasCustomName = false;
String customName = "";
if (te != null) if (te != null)
{ {
@ -88,6 +90,13 @@ public class ItemChestChanger extends ItemTooltip
{ {
chestContents = ((TileEntityIronChest) te).getItems(); chestContents = ((TileEntityIronChest) te).getItems();
chestFacing = ((TileEntityIronChest) te).getFacing(); chestFacing = ((TileEntityIronChest) te).getFacing();
if (((TileEntityIronChest) te).hasCustomName())
{
hasCustomName = true;
customName = ((TileEntityIronChest) te).getName();
}
newchest = this.type.target.makeEntity(); newchest = this.type.target.makeEntity();
if (newchest == null) if (newchest == null)
@ -110,6 +119,12 @@ public class ItemChestChanger extends ItemTooltip
return EnumActionResult.PASS; return EnumActionResult.PASS;
} }
if (chest.hasCustomName())
{
hasCustomName = true;
customName = chest.getName();
}
chestContents = NonNullList.<ItemStack> withSize(chest.getSizeInventory(), ItemStack.EMPTY); chestContents = NonNullList.<ItemStack> withSize(chest.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < chestContents.size(); i++) for (int i = 0; i < chestContents.size(); i++)
@ -144,6 +159,11 @@ public class ItemChestChanger extends ItemTooltip
{ {
((TileEntityIronChest) te2).setContents(chestContents); ((TileEntityIronChest) te2).setContents(chestContents);
((TileEntityIronChest) te2).setFacing(chestFacing); ((TileEntityIronChest) te2).setFacing(chestFacing);
if (hasCustomName)
{
((TileEntityIronChest) te2).setCustomName(customName);
}
} }
if (!playerIn.capabilities.isCreativeMode) if (!playerIn.capabilities.isCreativeMode)

View File

@ -130,6 +130,8 @@ public class ItemShulkerBoxChanger extends ItemTooltip
NonNullList<ItemStack> shulkerBoxContents = NonNullList.<ItemStack> withSize(27, ItemStack.EMPTY); NonNullList<ItemStack> shulkerBoxContents = NonNullList.<ItemStack> withSize(27, ItemStack.EMPTY);
EnumFacing shulkerBoxFacing = EnumFacing.UP; EnumFacing shulkerBoxFacing = EnumFacing.UP;
EnumDyeColor shulkerBoxColor = EnumDyeColor.PURPLE; EnumDyeColor shulkerBoxColor = EnumDyeColor.PURPLE;
boolean hasCustomName = false;
String customName = "";
if (te != null) if (te != null)
{ {
@ -140,6 +142,12 @@ public class ItemShulkerBoxChanger extends ItemTooltip
shulkerBoxColor = getColorFromTileEntity(te, worldIn); shulkerBoxColor = getColorFromTileEntity(te, worldIn);
((TileEntityIronShulkerBox) te).setHasBeenUpgraded(); ((TileEntityIronShulkerBox) te).setHasBeenUpgraded();
if (((TileEntityIronShulkerBox) te).hasCustomName())
{
hasCustomName = true;
customName = ((TileEntityIronShulkerBox) te).getName();
}
newShulkerBox = this.type.target.makeEntity(shulkerBoxColor); newShulkerBox = this.type.target.makeEntity(shulkerBoxColor);
if (newShulkerBox == null) if (newShulkerBox == null)
@ -165,6 +173,12 @@ public class ItemShulkerBoxChanger extends ItemTooltip
shulkerBoxContents.set(i, shulkerBox.getStackInSlot(i)); shulkerBoxContents.set(i, shulkerBox.getStackInSlot(i));
} }
if (shulkerBox.hasCustomName())
{
hasCustomName = true;
customName = shulkerBox.getName();
}
shulkerBoxColor = getColorFromTileEntity(te, worldIn); shulkerBoxColor = getColorFromTileEntity(te, worldIn);
shulkerBox.clear(); shulkerBox.clear();
@ -202,6 +216,11 @@ public class ItemShulkerBoxChanger extends ItemTooltip
{ {
((TileEntityIronShulkerBox) te2).setContents(shulkerBoxContents); ((TileEntityIronShulkerBox) te2).setContents(shulkerBoxContents);
((TileEntityIronShulkerBox) te2).setFacing(shulkerBoxFacing); ((TileEntityIronShulkerBox) te2).setFacing(shulkerBoxFacing);
if (hasCustomName)
{
((TileEntityIronShulkerBox) te2).setCustomName(customName);
}
} }
if (!playerIn.capabilities.isCreativeMode) if (!playerIn.capabilities.isCreativeMode)

View File

@ -598,7 +598,19 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
public NBTTagCompound getUpdateTag() public NBTTagCompound getUpdateTag()
{ {
NBTTagCompound compound = super.getUpdateTag(); NBTTagCompound compound = super.getUpdateTag();
if (!this.checkLootAndWrite(compound))
{
ItemStackHelper.saveAllItems(compound, this.chestContents);
}
compound.setByte("facing", (byte) this.facing.ordinal()); compound.setByte("facing", (byte) this.facing.ordinal());
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
return compound; return compound;
} }

View File

@ -686,7 +686,25 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
public NBTTagCompound getUpdateTag() public NBTTagCompound getUpdateTag()
{ {
NBTTagCompound compound = super.getUpdateTag(); NBTTagCompound compound = super.getUpdateTag();
if (!this.checkLootAndWrite(compound))
{
ItemStackHelper.saveAllItems(compound, this.items, false);
}
compound.setInteger("ShulkerBoxSize", this.getSizeInventory());
compound.setByte("facing", (byte) this.facing.ordinal()); compound.setByte("facing", (byte) this.facing.ordinal());
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
if (!compound.hasKey("Lock") && this.isLocked())
{
this.getLockCode().toNBT(compound);
}
return compound; return compound;
} }