From 7f50c7e929bc952abb8466f88aa16fc1e7ec54cb Mon Sep 17 00:00:00 2001 From: mezz Date: Sat, 20 Sep 2014 01:53:15 -0700 Subject: [PATCH] Fix #181: Letters sent to yourself disappear in Single Player --- .../forestry/core/gadgets/TileForestry.java | 7 ---- .../forestry/core/proxy/ProxyNetwork.java | 3 +- .../forestry/mail/gadgets/MachineMailbox.java | 34 ++++--------------- .../forestry/mail/gui/ContainerMailbox.java | 13 ++++--- 4 files changed, 17 insertions(+), 40 deletions(-) diff --git a/src/main/java/forestry/core/gadgets/TileForestry.java b/src/main/java/forestry/core/gadgets/TileForestry.java index 9d9795ba4..38e2fcdc3 100755 --- a/src/main/java/forestry/core/gadgets/TileForestry.java +++ b/src/main/java/forestry/core/gadgets/TileForestry.java @@ -264,13 +264,6 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit return owner; } - public EntityPlayer getOwnerEntity() { - if (owner != null) - return worldObj.func_152378_a(owner.getId()); - else - return null; - } - @Override public void setOwner(EntityPlayer player) { this.owner = player.getGameProfile(); diff --git a/src/main/java/forestry/core/proxy/ProxyNetwork.java b/src/main/java/forestry/core/proxy/ProxyNetwork.java index f13fd1e63..516c76eaa 100755 --- a/src/main/java/forestry/core/proxy/ProxyNetwork.java +++ b/src/main/java/forestry/core/proxy/ProxyNetwork.java @@ -15,6 +15,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.common.util.FakePlayer; import forestry.Forestry; import forestry.core.config.Defaults; @@ -38,7 +39,7 @@ public class ProxyNetwork { } public void sendToPlayer(ForestryPacket packet, EntityPlayer entityplayer) { - if (!(entityplayer instanceof EntityPlayerMP)) + if (!(entityplayer instanceof EntityPlayerMP) || (entityplayer instanceof FakePlayer)) return; EntityPlayerMP player = (EntityPlayerMP) entityplayer; diff --git a/src/main/java/forestry/mail/gadgets/MachineMailbox.java b/src/main/java/forestry/mail/gadgets/MachineMailbox.java index 6e6645d13..f26e1dfea 100755 --- a/src/main/java/forestry/mail/gadgets/MachineMailbox.java +++ b/src/main/java/forestry/mail/gadgets/MachineMailbox.java @@ -18,6 +18,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -80,25 +81,15 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial @Override public void updateServerSide() { if (!isLinked) { - getOrCreateMailInventory(); + getOrCreateMailInventory(worldObj, getOwnerProfile()); isLinked = true; } } /* MAIL HANDLING */ - public IInventory getOrCreateMailInventory() { - return getOrCreateMailInventory(null); - } - public IInventory getOrCreateMailInventory(EntityPlayer player) { - GameProfile playerProfile; - if (player != null) { - playerProfile = player.getGameProfile(); - } else { - playerProfile = getOwnerProfile(); - } - - if (playerProfile == null) + public IInventory getOrCreateMailInventory(World world, GameProfile playerProfile) { + if (!Proxies.common.isSimulating(world)) return new InventoryAdapter(POBox.SLOT_SIZE, "Letters"); IMailAddress address = PostManager.postRegistry.getMailAddress(playerProfile); @@ -121,7 +112,7 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial @Override public boolean hasMail() { - IInventory mailInventory = getOrCreateMailInventory(); + IInventory mailInventory = getOrCreateMailInventory(worldObj, getOwnerProfile()); for (int i = 0; i < mailInventory.getSizeInventory(); i++) if (mailInventory.getStackInSlot(i) != null) return true; @@ -137,19 +128,6 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial return res; } - /* ISIDEDINVENTORY */ - private static int[] slotIndices; - - public int[] getSizeInventorySide(int side) { - IInventory inventory = getOrCreateMailInventory(); - if(slotIndices == null) { - slotIndices = new int[inventory.getSizeInventory()]; - for(int i = 0; i < inventory.getSizeInventory(); i++) - slotIndices[i] = i; - } - return slotIndices; - } - /* ISPECIALINVENTORY */ @Override public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { @@ -168,7 +146,7 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { ItemStack product = null; - IInventory mailInventory = getOrCreateMailInventory(); + IInventory mailInventory = getOrCreateMailInventory(worldObj, getOwnerProfile()); for (int i = 0; i < mailInventory.getSizeInventory(); i++) { ItemStack slotStack = mailInventory.getStackInSlot(i); diff --git a/src/main/java/forestry/mail/gui/ContainerMailbox.java b/src/main/java/forestry/mail/gui/ContainerMailbox.java index 68620e852..4569fccb8 100755 --- a/src/main/java/forestry/mail/gui/ContainerMailbox.java +++ b/src/main/java/forestry/mail/gui/ContainerMailbox.java @@ -27,6 +27,9 @@ import forestry.plugins.PluginMail; public class ContainerMailbox extends ContainerForestry { + public static final short SLOT_LETTERS = 0; + public static final short SLOT_LETTERS_COUNT = 7 * 12; + MachineMailbox mailbox; POBox mailinventory; @@ -36,7 +39,7 @@ public class ContainerMailbox extends ContainerForestry { // Mailbox contents this.mailbox = tile; - IInventory inv = mailbox.getOrCreateMailInventory(player.player); + IInventory inv = mailbox.getOrCreateMailInventory(player.player.worldObj, player.player.getGameProfile()); if (inv instanceof POBox) mailinventory = (POBox) inv; @@ -58,9 +61,11 @@ public class ContainerMailbox extends ContainerForestry { public ItemStack slotClick(int slotIndex, int button, int par3, EntityPlayer player) { ItemStack stack = super.slotClick(slotIndex, button, par3, player); - if (Proxies.common.isSimulating(player.worldObj) && mailinventory != null) { - IMailAddress address = PostManager.postRegistry.getMailAddress(mailbox.getOwnerProfile()); - PluginMail.proxy.setPOBoxInfo(mailbox.getWorldObj(), address, mailinventory.getPOBoxInfo()); + if (slotIndex >= SLOT_LETTERS && slotIndex < SLOT_LETTERS + SLOT_LETTERS_COUNT) { + if (Proxies.common.isSimulating(player.worldObj) && mailinventory != null) { + IMailAddress address = PostManager.postRegistry.getMailAddress(player.getGameProfile()); + PluginMail.proxy.setPOBoxInfo(mailbox.getWorldObj(), address, mailinventory.getPOBoxInfo()); + } } return stack;