mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 03:39:09 +00:00
Fix some mail glitches. Check valid addresses for writing letters
This commit is contained in:
1 parent
3d4ba15751
commit
344e842764
8 files changed
+55
-23
No files matched your search
@@ -10,12 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.proxy;
|
||||
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
|
||||
import forestry.core.network.ForestryPacket;
|
||||
|
||||
public class ClientProxyNetwork extends ProxyNetwork {
|
||||
|
||||
@Override
|
||||
public void sendToServer(ForestryPacket packet) {
|
||||
Proxies.common.getClientInstance().getNetHandler().addToSendQueue(packet.getPacket());
|
||||
NetHandlerPlayClient netHandler = Proxies.common.getClientInstance().getNetHandler();
|
||||
if (netHandler != null)
|
||||
netHandler.addToSendQueue(packet.getPacket());
|
||||
}
|
||||
}
|
||||
@@ -10,23 +10,24 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import forestry.api.core.INBTTagable;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.core.network.EntityNetData;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.core.INBTTagable;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
|
||||
public class MailAddress implements INBTTagable, IMailAddress {
|
||||
private static final GameProfile invalidGameProfile = new GameProfile(new UUID(0, 0), "");
|
||||
@EntityNetData
|
||||
|
||||
private EnumAddressee type;
|
||||
@EntityNetData
|
||||
private GameProfile gameProfile; // gameProfile is a fake GameProfile for traders, and real for players
|
||||
|
||||
public MailAddress() {
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -163,11 +164,26 @@ 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>();
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ import java.util.LinkedList;
|
||||
|
||||
public class MachineTrader extends TileBase implements ISidedInventory {
|
||||
|
||||
@EntityNetData
|
||||
private MailAddress address;
|
||||
|
||||
public MachineTrader() {
|
||||
|
||||
@@ -156,14 +156,14 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
String typeName = packet.payload.stringPayload[1];
|
||||
|
||||
EnumAddressee type = EnumAddressee.fromString(typeName);
|
||||
IMailAddress recipient;
|
||||
IMailAddress recipient = null;
|
||||
if (type == EnumAddressee.PLAYER) {
|
||||
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.getMailAddress(gameProfile);
|
||||
recipient = PostManager.postRegistry.getValidMailAddress(player.worldObj, gameProfile);
|
||||
} else if (type == EnumAddressee.TRADER) {
|
||||
recipient = PostManager.postRegistry.getMailAddress(recipientName);
|
||||
recipient = PostManager.postRegistry.getValidMailAddress(player.worldObj, recipientName);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@@ -171,7 +171,8 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
getLetter().setRecipient(recipient);
|
||||
|
||||
// Update the trading info
|
||||
updateTradeInfo(player.worldObj, recipient);
|
||||
if (recipient == null || recipient.isTrader())
|
||||
updateTradeInfo(player.worldObj, recipient);
|
||||
|
||||
// Update info on client
|
||||
Proxies.net.sendToPlayer(new PacketLetterInfo(PacketIds.LETTER_INFO, type, tradeInfo, recipient), player);
|
||||
@@ -210,12 +211,16 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
if (!Proxies.common.isSimulating(world))
|
||||
return;
|
||||
|
||||
if (address.isPlayer())
|
||||
if (address == null) {
|
||||
setTradeInfo(null);
|
||||
return;
|
||||
}
|
||||
|
||||
ITradeStation station = PostManager.postRegistry.getTradeStation(world, address);
|
||||
if (station == null)
|
||||
if (station == null) {
|
||||
setTradeInfo(null);
|
||||
return;
|
||||
}
|
||||
|
||||
setTradeInfo(station.getTradeInfo());
|
||||
}
|
||||
@@ -235,5 +240,9 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
|
||||
private void setTradeInfo(TradeStationInfo info) {
|
||||
this.tradeInfo = info;
|
||||
if (tradeInfo == null)
|
||||
getLetter().setRecipient(null);
|
||||
else
|
||||
getLetter().setRecipient(tradeInfo.address);
|
||||
}
|
||||
}
|
||||
@@ -51,13 +51,13 @@ public class ContainerTradeName extends ContainerForestry {
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.TRADING_ADDRESS_SET, payload);
|
||||
Proxies.net.sendToServer(packet);
|
||||
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(addressName);
|
||||
IMailAddress address = PostManager.postRegistry.getValidMailAddress(machine.getWorld(), addressName);
|
||||
machine.setAddress(address);
|
||||
}
|
||||
|
||||
public void handleSetAddress(PacketUpdate packet) {
|
||||
String addressName = packet.payload.stringPayload[0];
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(addressName);
|
||||
IMailAddress address = PostManager.postRegistry.getValidMailAddress(machine.getWorld(), addressName);
|
||||
machine.setAddress(address);
|
||||
}
|
||||
|
||||
|
||||
@@ -154,6 +154,9 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
if(!isProcessedLetter && !checkedSessionVars) {
|
||||
checkedSessionVars = true;
|
||||
setFromSessionVars();
|
||||
String recipient = this.address.getText();
|
||||
EnumAddressee recipientType = container.getCarrierType();
|
||||
setRecipient(recipient, recipientType);
|
||||
}
|
||||
|
||||
// Check for focus changes
|
||||
@@ -247,7 +250,7 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
address.setText(recipient);
|
||||
|
||||
EnumAddressee type = EnumAddressee.fromString(typeName);
|
||||
setRecipient(recipient, type);
|
||||
container.setCarrierType(type);
|
||||
}
|
||||
|
||||
SessionVars.clearStringVar("mail.letter.recipient");
|
||||
|
||||
Reference in new issue
Block a user