Fix #411 Trade Station does not show its name in the GUI

This commit is contained in:
mezz committed 2014-12-28 12:56:31 -08:00
1 parent daa3ab13be
commit 0d1d8295b4
5 files changed
+31 -26

No files matched your search

+1 -1
View File
@@ -75,7 +75,7 @@ public class MailAddress implements INBTTagable, IMailAddress {
@Override
public boolean isValid() {
return !PlayerUtil.isSameGameProfile(gameProfile, invalidGameProfile);
return gameProfile.getName() != null && !PlayerUtil.isSameGameProfile(gameProfile, invalidGameProfile);
}
@Override
@@ -160,26 +160,11 @@ public class PostRegistry implements IPostRegistry {
return new MailAddress(gameProfile);
}
public IMailAddress getValidMailAddress(World world, GameProfile gameProfile) {
IMailAddress address = new MailAddress(gameProfile);
if (getPOBox(world, address) != null)
return address;
return null;
}
@Override
public IMailAddress getMailAddress(String traderName) {
return new MailAddress(traderName);
}
@Override
public IMailAddress getValidMailAddress(World world, String traderName) {
IMailAddress address = new MailAddress(traderName);
if (getTradeStation(world, address) != null)
return address;
return null;
}
/* CARRIER */
private final HashMap<EnumAddressee, IPostalCarrier> carriers = new HashMap<EnumAddressee, IPostalCarrier>();
@@ -34,6 +34,7 @@ import forestry.core.config.Defaults;
import forestry.core.gadgets.TileBase;
import forestry.core.inventory.InventoryAdapter;
import forestry.core.network.GuiId;
import forestry.core.network.PacketPayload;
import forestry.core.proxy.Proxies;
import forestry.core.utils.EnumAccess;
import forestry.core.utils.StackUtils;
@@ -46,7 +47,7 @@ import buildcraft.api.statements.ITriggerExternal;
public class MachineTrader extends TileBase implements ISidedInventory {
private MailAddress address;
private IMailAddress address;
public MachineTrader() {
address = new MailAddress();
@@ -91,6 +92,27 @@ public class MachineTrader extends TileBase implements ISidedInventory {
address = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("address"));
}
@Override
public PacketPayload getPacketPayload() {
if (address == null)
return null;
PacketPayload payload = new PacketPayload(0, 0, 1);
payload.stringPayload[0] = address.getName();
return payload;
}
@Override
public void fromPacketPayload(PacketPayload payload) {
if (payload.isEmpty()) {
address = null;
return;
}
String addressName = payload.stringPayload[0];
address = PostManager.postRegistry.getMailAddress(addressName);
}
/* UPDATING */
/**
* The trade station should show errors for missing stamps and paper first.
@@ -149,7 +171,7 @@ public class MachineTrader extends TileBase implements ISidedInventory {
/* STATE INFORMATION */
public boolean isLinked() {
return address.isValid();
return address.isValid() && getErrorState() != EnumErrorCode.NOTALPHANUMERIC && getErrorState() != EnumErrorCode.NOTUNIQUE;
}
/**
@@ -255,11 +277,10 @@ public class MachineTrader extends TileBase implements ISidedInventory {
return;
}
this.address = new MailAddress(address);
this.address = address;
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address);
setErrorState(EnumErrorCode.OK);
} else
this.address = new MailAddress(address);
}
}
/* TRADING */
@@ -275,7 +296,6 @@ public class MachineTrader extends TileBase implements ISidedInventory {
return PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address);
}
/* ISIDEDINVENTORY */
@Override
public int getSizeInventory() {
@@ -334,7 +354,7 @@ public class MachineTrader extends TileBase implements ISidedInventory {
public boolean isUseableByPlayer(EntityPlayer player) {
if (!Utils.isUseableByPlayer(player, this))
return false;
return getOrCreateTradeInventory().isUseableByPlayer(player);
return allowsInteraction(player);
}
/* ISIDEDINVENTORY */
@@ -158,9 +158,9 @@ public class ContainerLetter extends ContainerItemInventory {
GameProfile gameProfile = MinecraftServer.getServer().func_152358_ax().func_152655_a(recipientName);
if (gameProfile == null)
gameProfile = new GameProfile(new UUID(0, 0), recipientName);
recipient = PostManager.postRegistry.getValidMailAddress(player.worldObj, gameProfile);
recipient = PostManager.postRegistry.getMailAddress(gameProfile);
} else if (type == EnumAddressee.TRADER) {
recipient = PostManager.postRegistry.getValidMailAddress(player.worldObj, recipientName);
recipient = PostManager.postRegistry.getMailAddress(recipientName);
} else {
return;
}