Fix #181: Letters sent to yourself disappear in Single Player

This commit is contained in:
mezz committed 2014-09-20 01:53:15 -07:00
1 parent d459856852
commit 7f50c7e929
4 files changed
+17 -40

No files matched your search

@@ -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();
@@ -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;
@@ -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);
@@ -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;