mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-26 23:03:18 +00:00
Update for 1.11. Missing assets, unstable.
This commit is contained in:
1 parent
30d7365518
commit
9611ae08ae
1145 files changed
+15561
-18107
No files matched your search
@@ -10,8 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.mail.IPostalState;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
@@ -25,7 +23,7 @@ public enum EnumDeliveryState implements IPostalState {
|
||||
|
||||
private final String unlocalizedDescription;
|
||||
|
||||
EnumDeliveryState(@Nonnull String unlocalizedDescription) {
|
||||
EnumDeliveryState(String unlocalizedDescription) {
|
||||
this.unlocalizedDescription = unlocalizedDescription;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.gui.GuiMailboxInfo;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoResponse;
|
||||
|
||||
public class EventHandlerMailAlert {
|
||||
@SubscribeEvent
|
||||
@@ -29,7 +29,7 @@ public class EventHandlerMailAlert {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Minecraft.getMinecraft().theWorld != null && GuiMailboxInfo.instance.hasPOBoxInfo()) {
|
||||
if (Minecraft.getMinecraft().world != null && GuiMailboxInfo.instance.hasPOBoxInfo()) {
|
||||
GuiMailboxInfo.instance.render();
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,8 @@ public class EventHandlerMailAlert {
|
||||
EntityPlayer player = event.player;
|
||||
if (player != null) {
|
||||
MailAddress address = new MailAddress(player.getGameProfile());
|
||||
POBox pobox = PostRegistry.getOrCreatePOBox(player.worldObj, address);
|
||||
if (pobox != null) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoUpdate(pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
POBox pobox = PostRegistry.getOrCreatePOBox(player.world, address);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,23 +10,22 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.IStamps;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class Letter implements ILetter {
|
||||
private static final Random rand = new Random();
|
||||
@@ -38,27 +37,23 @@ public class Letter implements ILetter {
|
||||
private boolean isProcessed = false;
|
||||
|
||||
private IMailAddress sender;
|
||||
private IMailAddress[] recipient;
|
||||
@Nullable
|
||||
private IMailAddress recipient;
|
||||
|
||||
private String text;
|
||||
private String text = "";
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(22, "INV");
|
||||
private final String uid;
|
||||
|
||||
public Letter(IMailAddress sender, IMailAddress recipient) {
|
||||
this.sender = sender;
|
||||
this.recipient = new IMailAddress[]{recipient};
|
||||
this.recipient = recipient;
|
||||
this.uid = String.valueOf(rand.nextInt());
|
||||
}
|
||||
|
||||
public Letter(@Nonnull NBTTagCompound nbttagcompound) {
|
||||
public Letter(NBTTagCompound nbttagcompound) {
|
||||
this.isProcessed = nbttagcompound.getBoolean("PRC");
|
||||
this.sender = new MailAddress(nbttagcompound.getCompoundTag("SDR"));
|
||||
|
||||
int recipientCount = nbttagcompound.getShort("CRC");
|
||||
this.recipient = new MailAddress[recipientCount];
|
||||
for (int i = 0; i < recipientCount; i++) {
|
||||
this.recipient[i] = new MailAddress(nbttagcompound.getCompoundTag("RC" + i));
|
||||
}
|
||||
this.recipient = new MailAddress(nbttagcompound.getCompoundTag("RC"));
|
||||
|
||||
this.text = nbttagcompound.getString("TXT");
|
||||
this.uid = nbttagcompound.getString("UID");
|
||||
@@ -74,11 +69,10 @@ public class Letter implements ILetter {
|
||||
this.sender.writeToNBT(subcompound);
|
||||
nbttagcompound.setTag("SDR", subcompound);
|
||||
|
||||
nbttagcompound.setShort("CRC", (short) recipient.length);
|
||||
for (int i = 0; i < recipient.length; i++) {
|
||||
if (this.recipient != null) {
|
||||
subcompound = new NBTTagCompound();
|
||||
this.recipient[i].writeToNBT(subcompound);
|
||||
nbttagcompound.setTag("RC" + i, subcompound);
|
||||
this.recipient.writeToNBT(subcompound);
|
||||
nbttagcompound.setTag("RC", subcompound);
|
||||
}
|
||||
|
||||
nbttagcompound.setString("TXT", this.text);
|
||||
@@ -88,12 +82,12 @@ public class Letter implements ILetter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getPostage() {
|
||||
public NonNullList<ItemStack> getPostage() {
|
||||
return InventoryUtil.getStacks(inventory, SLOT_POSTAGE_1, SLOT_POSTAGE_COUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getAttachments() {
|
||||
public NonNullList<ItemStack> getAttachments() {
|
||||
return InventoryUtil.getStacks(inventory, SLOT_ATTACHMENT_1, SLOT_ATTACHMENT_COUNT);
|
||||
}
|
||||
|
||||
@@ -115,7 +109,7 @@ public class Letter implements ILetter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAttachments(ItemStack[] itemstacks) {
|
||||
public void addAttachments(NonNullList<ItemStack> itemstacks) {
|
||||
for (ItemStack stack : itemstacks) {
|
||||
addAttachment(stack);
|
||||
}
|
||||
@@ -124,7 +118,7 @@ public class Letter implements ILetter {
|
||||
@Override
|
||||
public void invalidatePostage() {
|
||||
for (int i = SLOT_POSTAGE_1; i < SLOT_POSTAGE_1 + SLOT_POSTAGE_COUNT; i++) {
|
||||
inventory.setInventorySlotContents(i, null);
|
||||
inventory.setInventorySlotContents(i, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +136,7 @@ public class Letter implements ILetter {
|
||||
public boolean isMailable() {
|
||||
// Can't resend an already sent letter
|
||||
// Requires at least one recipient
|
||||
return !isProcessed && recipient != null && recipient.length > 0;
|
||||
return !isProcessed && recipient != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,7 +152,7 @@ public class Letter implements ILetter {
|
||||
continue;
|
||||
}
|
||||
|
||||
posted += ((IStamps) stamp.getItem()).getPostage(stamp).getValue() * stamp.stackSize;
|
||||
posted += ((IStamps) stamp.getItem()).getPostage(stamp).getValue() * stamp.getCount();
|
||||
}
|
||||
|
||||
return posted >= requiredPostage();
|
||||
@@ -184,16 +178,7 @@ public class Letter implements ILetter {
|
||||
|
||||
@Override
|
||||
public boolean hasRecipient() {
|
||||
if (getRecipients().length <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IMailAddress recipient = getRecipients()[0];
|
||||
if (recipient == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !StringUtils.isBlank(recipient.getName());
|
||||
return recipient != null && !StringUtils.isBlank(recipient.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -207,30 +192,22 @@ public class Letter implements ILetter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipient(IMailAddress address) {
|
||||
if (address == null) {
|
||||
this.recipient = new IMailAddress[]{};
|
||||
} else {
|
||||
this.recipient = new IMailAddress[]{address};
|
||||
}
|
||||
public void setRecipient(@Nullable IMailAddress address) {
|
||||
this.recipient = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMailAddress[] getRecipients() {
|
||||
@Nullable
|
||||
public IMailAddress getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipientString() {
|
||||
StringBuilder recipientString = new StringBuilder();
|
||||
for (IMailAddress address : recipient) {
|
||||
if (recipientString.length() > 0) {
|
||||
recipientString.append(", ");
|
||||
}
|
||||
recipientString.append(address.getName());
|
||||
if (recipient == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return recipientString.toString();
|
||||
return recipient.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -245,15 +222,20 @@ public class Letter implements ILetter {
|
||||
|
||||
@Override
|
||||
public void addTooltip(List<String> list) {
|
||||
if (this.sender != null && StringUtils.isNotBlank(this.sender.getName())) {
|
||||
if (StringUtils.isNotBlank(this.sender.getName())) {
|
||||
list.add(Translator.translateToLocal("for.gui.mail.from") + ": " + this.sender.getName());
|
||||
}
|
||||
if (this.recipient != null && this.recipient.length > 0) {
|
||||
if (this.recipient != null) {
|
||||
list.add(Translator.translateToLocal("for.gui.mail.to") + ": " + this.getRecipientString());
|
||||
}
|
||||
}
|
||||
|
||||
// / IINVENTORY
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return inventory.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inventory.getSizeInventory();
|
||||
@@ -268,7 +250,7 @@ public class Letter implements ILetter {
|
||||
public ItemStack decrStackSize(int var1, int var2) {
|
||||
return inventory.decrStackSize(var1, var2);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index) {
|
||||
return inventory.removeStackFromSlot(index);
|
||||
@@ -295,7 +277,7 @@ public class Letter implements ILetter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1) {
|
||||
public boolean isUsableByPlayer(EntityPlayer var1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,26 +10,23 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class MailAddress implements INbtWritable, IMailAddress {
|
||||
|
||||
private static final GameProfile invalidGameProfile = new GameProfile(new UUID(0, 0), "");
|
||||
|
||||
@Nonnull
|
||||
private final EnumAddressee type;
|
||||
@Nonnull
|
||||
private final GameProfile gameProfile; // gameProfile is a fake GameProfile for traders, and real for players
|
||||
|
||||
public MailAddress() {
|
||||
@@ -37,27 +34,24 @@ public class MailAddress implements INbtWritable, IMailAddress {
|
||||
this.gameProfile = invalidGameProfile;
|
||||
}
|
||||
|
||||
public MailAddress(@Nonnull GameProfile gameProfile) {
|
||||
if (gameProfile == null) {
|
||||
throw new IllegalArgumentException("gameProfile must not be null");
|
||||
}
|
||||
public MailAddress(GameProfile gameProfile) {
|
||||
Preconditions.checkNotNull(gameProfile, "gameProfile must not be null");
|
||||
|
||||
this.type = EnumAddressee.PLAYER;
|
||||
this.gameProfile = gameProfile;
|
||||
}
|
||||
|
||||
public MailAddress(@Nonnull String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("name must not be null");
|
||||
}
|
||||
public MailAddress(String name) {
|
||||
Preconditions.checkNotNull(name, "name must not be null");
|
||||
Preconditions.checkArgument(StringUtils.isNotBlank(name), "name must not be blank");
|
||||
|
||||
this.type = EnumAddressee.TRADER;
|
||||
this.gameProfile = new GameProfile(null, name);
|
||||
}
|
||||
|
||||
public MailAddress(@Nonnull NBTTagCompound nbt) {
|
||||
public MailAddress(NBTTagCompound nbt) {
|
||||
EnumAddressee type = null;
|
||||
GameProfile gameProfile = null;
|
||||
GameProfile gameProfile = invalidGameProfile;
|
||||
if (nbt.hasKey("TP")) {
|
||||
String typeName = nbt.getString("TP");
|
||||
type = EnumAddressee.fromString(typeName);
|
||||
@@ -75,7 +69,6 @@ public class MailAddress implements INbtWritable, IMailAddress {
|
||||
this.gameProfile = gameProfile;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EnumAddressee getType() {
|
||||
return type;
|
||||
@@ -90,7 +83,7 @@ public class MailAddress implements INbtWritable, IMailAddress {
|
||||
public boolean isValid() {
|
||||
return gameProfile.getName() != null && !PlayerUtil.isSameGameProfile(gameProfile, invalidGameProfile);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GameProfile getPlayerProfile() {
|
||||
if (this.type != EnumAddressee.PLAYER) {
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -29,6 +32,7 @@ public class POBox extends WorldSavedData implements IInventory {
|
||||
public static final String SAVE_NAME = "POBox_";
|
||||
public static final short SLOT_SIZE = 84;
|
||||
|
||||
@Nullable
|
||||
private IMailAddress address;
|
||||
private final InventoryAdapter letters = new InventoryAdapter(SLOT_SIZE, "Letters").disableAutomation();
|
||||
|
||||
@@ -40,6 +44,7 @@ public class POBox extends WorldSavedData implements IInventory {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public POBox(String savename) {
|
||||
super(savename);
|
||||
}
|
||||
@@ -65,6 +70,7 @@ public class POBox extends WorldSavedData implements IInventory {
|
||||
|
||||
public boolean storeLetter(ItemStack letterstack) {
|
||||
ILetter letter = PostManager.postRegistry.getLetter(letterstack);
|
||||
Preconditions.checkNotNull(letter, "Letter stack must be a valid letter");
|
||||
|
||||
// Mark letter as processed
|
||||
letter.setProcessed(true);
|
||||
@@ -82,14 +88,17 @@ public class POBox extends WorldSavedData implements IInventory {
|
||||
int playerLetters = 0;
|
||||
int tradeLetters = 0;
|
||||
for (int i = 0; i < letters.getSizeInventory(); i++) {
|
||||
if (letters.getStackInSlot(i) == null) {
|
||||
if (letters.getStackInSlot(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
ILetter letter = new Letter(letters.getStackInSlot(i).getTagCompound());
|
||||
if (letter.getSender().getType() == EnumAddressee.PLAYER) {
|
||||
playerLetters++;
|
||||
} else {
|
||||
tradeLetters++;
|
||||
NBTTagCompound tagCompound = letters.getStackInSlot(i).getTagCompound();
|
||||
if (tagCompound != null) {
|
||||
ILetter letter = new Letter(tagCompound);
|
||||
if (letter.getSender().getType() == EnumAddressee.PLAYER) {
|
||||
playerLetters++;
|
||||
} else {
|
||||
tradeLetters++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +106,12 @@ public class POBox extends WorldSavedData implements IInventory {
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return letters.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
super.markDirty();
|
||||
@@ -140,8 +155,8 @@ public class POBox extends WorldSavedData implements IInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1) {
|
||||
return letters.isUseableByPlayer(var1);
|
||||
public boolean isUsableByPlayer(EntityPlayer var1) {
|
||||
return letters.isUsableByPlayer(var1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,13 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.api.circuits.ICircuit;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.PostManager;
|
||||
@@ -31,6 +27,7 @@ import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.items.EnumElectronTube;
|
||||
import forestry.core.items.ItemRegistryCore;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.OreDictUtil;
|
||||
@@ -42,10 +39,17 @@ import forestry.mail.network.PacketRegistryMail;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@ForestryPlugin(pluginID = ForestryPluginUids.MAIL, name = "Mail", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.mail.description")
|
||||
public class PluginMail extends BlankForestryPlugin {
|
||||
@Nullable
|
||||
public static ItemRegistryMail items;
|
||||
@Nullable
|
||||
public static BlockRegistryMail blocks;
|
||||
|
||||
@Override
|
||||
@@ -64,7 +68,7 @@ public class PluginMail extends BlankForestryPlugin {
|
||||
@Override
|
||||
public void preInit() {
|
||||
super.preInit();
|
||||
|
||||
|
||||
PluginCore.rootCommand.addChildCommand(new CommandMail());
|
||||
|
||||
if (Config.mailAlertEnabled) {
|
||||
@@ -81,6 +85,7 @@ public class PluginMail extends BlankForestryPlugin {
|
||||
@Override
|
||||
public void doInit() {
|
||||
super.doInit();
|
||||
Preconditions.checkState(blocks != null);
|
||||
|
||||
blocks.mailbox.init();
|
||||
blocks.tradeStation.init();
|
||||
@@ -94,6 +99,11 @@ public class PluginMail extends BlankForestryPlugin {
|
||||
|
||||
@Override
|
||||
public void registerRecipes() {
|
||||
ItemRegistryCore coreItems = PluginCore.items;
|
||||
Preconditions.checkState(coreItems != null);
|
||||
Preconditions.checkState(blocks != null);
|
||||
Preconditions.checkState(items != null);
|
||||
|
||||
Object stampGlue;
|
||||
Object letterGlue;
|
||||
|
||||
@@ -123,7 +133,7 @@ public class PluginMail extends BlankForestryPlugin {
|
||||
'X', stampDefinition.getCraftingIngredient(),
|
||||
'#', Items.PAPER,
|
||||
'Z', stampGlue);
|
||||
RecipeManagers.carpenterManager.addRecipe(10, Fluids.SEED_OIL.getFluid(300), null, stamps,
|
||||
RecipeManagers.carpenterManager.addRecipe(10, Fluids.SEED_OIL.getFluid(300), ItemStack.EMPTY, stamps,
|
||||
"XXX",
|
||||
"###",
|
||||
'X', stampDefinition.getCraftingIngredient(),
|
||||
@@ -135,7 +145,7 @@ public class PluginMail extends BlankForestryPlugin {
|
||||
RecipeUtil.addRecipe(new ItemStack(Items.PAPER), "###", '#', OreDictUtil.EMPTIED_LETTER_ORE_DICT);
|
||||
|
||||
// Carpenter
|
||||
RecipeManagers.carpenterManager.addRecipe(10, new FluidStack(FluidRegistry.WATER, 250), null, items.letters.getItemStack(), "###", "###", '#', PluginCore.items.woodPulp);
|
||||
RecipeManagers.carpenterManager.addRecipe(10, new FluidStack(FluidRegistry.WATER, 250), ItemStack.EMPTY, items.letters.getItemStack(), "###", "###", '#', coreItems.woodPulp);
|
||||
|
||||
RecipeUtil.addShapelessRecipe(items.catalogue.getItemStack(), items.stamps.getWildcard(), new ItemStack(Items.BOOK));
|
||||
|
||||
@@ -145,16 +155,16 @@ public class PluginMail extends BlankForestryPlugin {
|
||||
"XXX",
|
||||
'#', "ingotTin",
|
||||
'X', "chestWood",
|
||||
'Y', PluginCore.items.sturdyCasing);
|
||||
'Y', coreItems.sturdyCasing);
|
||||
|
||||
RecipeUtil.addRecipe(new ItemStack(blocks.tradeStation),
|
||||
"Z#Z",
|
||||
"#Y#",
|
||||
"XWX",
|
||||
'#', PluginCore.items.tubes.get(EnumElectronTube.BRONZE, 1),
|
||||
'#', coreItems.tubes.get(EnumElectronTube.BRONZE, 1),
|
||||
'X', "chestWood",
|
||||
'Y', PluginCore.items.sturdyCasing,
|
||||
'Z', PluginCore.items.tubes.get(EnumElectronTube.IRON, 1),
|
||||
'Y', coreItems.sturdyCasing,
|
||||
'Z', coreItems.tubes.get(EnumElectronTube.IRON, 1),
|
||||
'W', ItemCircuitBoard.createCircuitboard(EnumCircuitBoardType.REFINED, null, new ICircuit[]{}));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.LinkedHashMap;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSavedData;
|
||||
|
||||
@@ -34,12 +35,14 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
// / CONSTANTS
|
||||
public static final String SAVE_NAME = "ForestryMail";
|
||||
private final int[] collectedPostage = new int[EnumPostage.values().length];
|
||||
private LinkedHashMap<IMailAddress, ITradeStation> activeTradeStations = new LinkedHashMap<>();
|
||||
|
||||
// CONSTRUCTORS
|
||||
public PostOffice() {
|
||||
super(SAVE_NAME);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public PostOffice(String s) {
|
||||
super(s);
|
||||
}
|
||||
@@ -66,7 +69,6 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
}
|
||||
|
||||
/* TRADE STATION MANAGMENT */
|
||||
private LinkedHashMap<IMailAddress, ITradeStation> activeTradeStations;
|
||||
|
||||
@Override
|
||||
public LinkedHashMap<IMailAddress, ITradeStation> getActiveTradeStations(World world) {
|
||||
@@ -75,19 +77,18 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
|
||||
private void refreshActiveTradeStations(World world) {
|
||||
activeTradeStations = new LinkedHashMap<>();
|
||||
if (world == null || world.getSaveHandler() == null) {
|
||||
return;
|
||||
}
|
||||
File worldSave = world.getSaveHandler().getMapFileFromName("dummy");
|
||||
if (worldSave == null) {
|
||||
return;
|
||||
}
|
||||
File file = worldSave.getParentFile();
|
||||
if (!file.exists() || !file.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String str : file.list()) {
|
||||
String[] list = file.list();
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String str : list) {
|
||||
if (!str.startsWith(TradeStation.SAVE_NAME)) {
|
||||
continue;
|
||||
}
|
||||
@@ -140,13 +141,16 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
// / DELIVERY
|
||||
@Override
|
||||
public IPostalState lodgeLetter(World world, ItemStack itemstack, boolean doLodge) {
|
||||
ILetter letter = PostManager.postRegistry.getLetter(itemstack);
|
||||
if (letter == null) {
|
||||
return EnumDeliveryState.NOT_MAILABLE;
|
||||
}
|
||||
|
||||
if (letter.isProcessed()) {
|
||||
return EnumDeliveryState.ALREADY_MAILED;
|
||||
@@ -161,14 +165,11 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
}
|
||||
|
||||
IPostalState state = EnumDeliveryState.NOT_MAILABLE;
|
||||
for (IMailAddress address : letter.getRecipients()) {
|
||||
IMailAddress address = letter.getRecipient();
|
||||
if (address != null) {
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(address.getType());
|
||||
if (carrier == null) {
|
||||
continue;
|
||||
}
|
||||
state = carrier.deliverLetter(world, this, address, itemstack, doLodge);
|
||||
if (!state.isOk()) {
|
||||
break;
|
||||
if (carrier != null) {
|
||||
state = carrier.deliverLetter(world, this, address, itemstack, doLodge);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +185,7 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectPostage(ItemStack[] stamps) {
|
||||
public void collectPostage(NonNullList<ItemStack> stamps) {
|
||||
for (ItemStack stamp : stamps) {
|
||||
if (stamp == null) {
|
||||
continue;
|
||||
@@ -192,7 +193,7 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
|
||||
if (stamp.getItem() instanceof IStamps) {
|
||||
EnumPostage postage = ((IStamps) stamp.getItem()).getPostage(stamp);
|
||||
collectedPostage[postage.ordinal()] += stamp.stackSize;
|
||||
collectedPostage[postage.ordinal()] += stamp.getCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,19 +10,13 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
@@ -32,15 +26,22 @@ import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoResponse;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PostRegistry implements IPostRegistry {
|
||||
|
||||
@Nullable
|
||||
public static PostOffice cachedPostOffice;
|
||||
public static final Map<IMailAddress, POBox> cachedPOBoxes = new HashMap<>();
|
||||
public static final Map<IMailAddress, ITradeStation> cachedTradeStations = new HashMap<>();
|
||||
|
||||
private final Map<EnumAddressee, IPostalCarrier> carriers = new EnumMap<>(EnumAddressee.class);
|
||||
|
||||
/**
|
||||
* @param world the Minecraft world the PO box will be in
|
||||
* @param address the potential address of the PO box
|
||||
@@ -51,13 +52,14 @@ public class PostRegistry implements IPostRegistry {
|
||||
return address.getType() == EnumAddressee.PLAYER && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static POBox getPOBox(World world, IMailAddress address) {
|
||||
|
||||
if (cachedPOBoxes.containsKey(address)) {
|
||||
return cachedPOBoxes.get(address);
|
||||
}
|
||||
|
||||
POBox pobox = (POBox) world.loadItemData(POBox.class, POBox.SAVE_NAME + address);
|
||||
POBox pobox = (POBox) world.loadData(POBox.class, POBox.SAVE_NAME + address);
|
||||
if (pobox != null) {
|
||||
cachedPOBoxes.put(address, pobox);
|
||||
}
|
||||
@@ -69,13 +71,13 @@ public class PostRegistry implements IPostRegistry {
|
||||
|
||||
if (pobox == null) {
|
||||
pobox = new POBox(address);
|
||||
world.setItemData(POBox.SAVE_NAME + address, pobox);
|
||||
world.setData(POBox.SAVE_NAME + address, pobox);
|
||||
pobox.markDirty();
|
||||
cachedPOBoxes.put(address, pobox);
|
||||
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, address.getPlayerProfile());
|
||||
if (player != null) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoUpdate(pobox.getPOBoxInfo()), player);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +91,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidTradeAddress(World world, IMailAddress address) {
|
||||
return address != null && address.getType() == EnumAddressee.TRADER && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
return address.getType() == EnumAddressee.TRADER && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,20 +101,16 @@ public class PostRegistry implements IPostRegistry {
|
||||
*/
|
||||
@Override
|
||||
public boolean isAvailableTradeAddress(World world, IMailAddress address) {
|
||||
return address != null && getTradeStation(world, address) == null;
|
||||
return getTradeStation(world, address) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeStation getTradeStation(World world, IMailAddress address) {
|
||||
if (address == null || address.getName() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (cachedTradeStations.containsKey(address)) {
|
||||
return (TradeStation) cachedTradeStations.get(address);
|
||||
}
|
||||
|
||||
TradeStation trade = (TradeStation) world.loadItemData(TradeStation.class, TradeStation.SAVE_NAME + address);
|
||||
TradeStation trade = (TradeStation) world.loadData(TradeStation.class, TradeStation.SAVE_NAME + address);
|
||||
|
||||
// Only existing and valid mail orders are returned
|
||||
if (trade != null && trade.isValid()) {
|
||||
@@ -130,7 +128,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
|
||||
if (trade == null) {
|
||||
trade = new TradeStation(owner, address);
|
||||
world.setItemData(TradeStation.SAVE_NAME + address, trade);
|
||||
world.setData(TradeStation.SAVE_NAME + address, trade);
|
||||
trade.markDirty();
|
||||
cachedTradeStations.put(address, trade);
|
||||
getPostOffice(world).registerTradeStation(trade);
|
||||
@@ -151,7 +149,10 @@ public class PostRegistry implements IPostRegistry {
|
||||
cachedTradeStations.remove(address);
|
||||
getPostOffice(world).deregisterTradeStation(trade);
|
||||
File file = world.getSaveHandler().getMapFileFromName(trade.mapName);
|
||||
file.delete();
|
||||
boolean delete = file.delete();
|
||||
if (!delete) {
|
||||
Log.error("Failed to delete trade station file. {}", file);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,12 +161,12 @@ public class PostRegistry implements IPostRegistry {
|
||||
return cachedPostOffice;
|
||||
}
|
||||
|
||||
PostOffice office = (PostOffice) world.loadItemData(PostOffice.class, PostOffice.SAVE_NAME);
|
||||
PostOffice office = (PostOffice) world.loadData(PostOffice.class, PostOffice.SAVE_NAME);
|
||||
|
||||
// Create office if there is none yet
|
||||
if (office == null) {
|
||||
office = new PostOffice();
|
||||
world.setItemData(PostOffice.SAVE_NAME, office);
|
||||
world.setData(PostOffice.SAVE_NAME, office);
|
||||
}
|
||||
|
||||
office.setWorld(world);
|
||||
@@ -174,20 +175,18 @@ public class PostRegistry implements IPostRegistry {
|
||||
return office;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@Override
|
||||
public IMailAddress getMailAddress(@Nonnull GameProfile gameProfile) {
|
||||
public IMailAddress getMailAddress(GameProfile gameProfile) {
|
||||
return new MailAddress(gameProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMailAddress getMailAddress(@Nonnull String traderName) {
|
||||
public IMailAddress getMailAddress(String traderName) {
|
||||
return new MailAddress(traderName);
|
||||
}
|
||||
|
||||
/* CARRIER */
|
||||
private final Map<EnumAddressee, IPostalCarrier> carriers = new EnumMap<>(EnumAddressee.class);
|
||||
|
||||
@Override
|
||||
public Map<EnumAddressee, IPostalCarrier> getRegisteredCarriers() {
|
||||
return carriers;
|
||||
@@ -221,8 +220,9 @@ public class PostRegistry implements IPostRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ILetter getLetter(ItemStack itemstack) {
|
||||
if (itemstack == null) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -239,6 +239,6 @@ public class PostRegistry implements IPostRegistry {
|
||||
|
||||
@Override
|
||||
public boolean isLetter(ItemStack itemstack) {
|
||||
return itemstack != null && itemstack.getItem() == PluginMail.items.letters;
|
||||
return itemstack.getItem() == PluginMail.items.letters;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoResponse;
|
||||
|
||||
public class PostalCarrier implements IPostalCarrier {
|
||||
|
||||
@@ -88,7 +88,7 @@ public class PostalCarrier implements IPostalCarrier {
|
||||
} else {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, recipient.getPlayerProfile());
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoUpdate(pobox.getPOBoxInfo()), player);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package forestry.mail;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.mail.IPostalState;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
public class ResponseNotMailable implements IPostalState {
|
||||
@Nonnull
|
||||
private final IPostalState state;
|
||||
|
||||
public ResponseNotMailable(@Nonnull IPostalState state) {
|
||||
public ResponseNotMailable(IPostalState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSavedData;
|
||||
@@ -143,7 +142,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
@Override
|
||||
public TradeStationInfo getTradeInfo() {
|
||||
ItemStack[] condensedRequired = ItemStackUtil.condenseStacks(InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT));
|
||||
NonNullList<ItemStack> condensedRequired = ItemStackUtil.condenseStacks(InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT));
|
||||
|
||||
// Set current state
|
||||
EnumTradeStationState state = EnumTradeStationState.OK;
|
||||
@@ -172,7 +171,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
public IPostalState handleLetter(World world, IMailAddress recipient, ItemStack letterstack, boolean doLodge) {
|
||||
|
||||
boolean sendOwnerNotice = doLodge && owner != null;
|
||||
|
||||
|
||||
ILetter letter = PostManager.postRegistry.getLetter(letterstack);
|
||||
|
||||
if (!isVirtual() && !hasPaper(sendOwnerNotice ? 2 : 1)) {
|
||||
@@ -303,7 +302,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
/* TRADE LOGIC */
|
||||
private int countFillableOrders(int max, ItemStack tradegood) {
|
||||
|
||||
if (tradegood == null) {
|
||||
if (tradegood.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -312,7 +311,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
for (ItemStack stack : InventoryUtil.getStacks(inventory, SLOT_SEND_BUFFER, SLOT_SEND_BUFFER_COUNT)) {
|
||||
if (stack != null && stack.isItemEqual(tradegood) && ItemStack.areItemStackTagsEqual(stack, tradegood)) {
|
||||
orderCount += stack.stackSize / (float) tradegood.stackSize;
|
||||
orderCount += stack.getCount() / (float) tradegood.getCount();
|
||||
if (orderCount >= max) {
|
||||
return max;
|
||||
}
|
||||
@@ -324,12 +323,12 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
public boolean canReceivePayment() {
|
||||
InventoryAdapter test = inventory.copy();
|
||||
ItemStack[] payment = InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT);
|
||||
NonNullList<ItemStack> payment = InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT);
|
||||
|
||||
return InventoryUtil.tryAddStacksCopy(test, payment, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true);
|
||||
}
|
||||
|
||||
private int countStorablePayment(int max, ItemStack[] exchange) {
|
||||
private int countStorablePayment(int max, NonNullList<ItemStack> exchange) {
|
||||
|
||||
InventoryAdapter test = inventory.copy();
|
||||
int count = 0;
|
||||
@@ -348,26 +347,20 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
private void removeTradegood(int filled) {
|
||||
|
||||
for (int j = 0; j < filled; j++) {
|
||||
int toRemove = inventory.getStackInSlot(SLOT_TRADEGOOD).stackSize;
|
||||
int toRemove = inventory.getStackInSlot(SLOT_TRADEGOOD).getCount();
|
||||
for (int i = SLOT_SEND_BUFFER; i < SLOT_SEND_BUFFER + SLOT_SEND_BUFFER_COUNT; i++) {
|
||||
ItemStack buffer = inventory.getStackInSlot(i);
|
||||
if (buffer == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!buffer.isItemEqual(inventory.getStackInSlot(SLOT_TRADEGOOD))) {
|
||||
continue;
|
||||
}
|
||||
if (!buffer.isEmpty() &&
|
||||
buffer.isItemEqual(inventory.getStackInSlot(SLOT_TRADEGOOD)) &&
|
||||
ItemStack.areItemStackTagsEqual(buffer, inventory.getStackInSlot(SLOT_TRADEGOOD))) {
|
||||
|
||||
if (!ItemStack.areItemStackTagsEqual(buffer, inventory.getStackInSlot(SLOT_TRADEGOOD))) {
|
||||
continue;
|
||||
}
|
||||
ItemStack decrease = inventory.decrStackSize(i, toRemove);
|
||||
toRemove -= decrease.getCount();
|
||||
|
||||
ItemStack decrease = inventory.decrStackSize(i, toRemove);
|
||||
toRemove -= decrease.stackSize;
|
||||
|
||||
if (toRemove <= 0) {
|
||||
break;
|
||||
if (toRemove <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,7 +373,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
for (ItemStack stack : InventoryUtil.getStacks(inventory, SLOT_LETTERS_1, SLOT_LETTERS_COUNT)) {
|
||||
if (stack != null) {
|
||||
amountFound += stack.stackSize;
|
||||
amountFound += stack.getCount();
|
||||
}
|
||||
|
||||
if (amountFound >= amountRequired) {
|
||||
@@ -395,7 +388,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
private void removePaper() {
|
||||
for (int i = SLOT_LETTERS_1; i < SLOT_LETTERS_1 + SLOT_LETTERS_COUNT; i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if (stack != null && stack.getItem() == Items.PAPER && stack.stackSize > 0) {
|
||||
if (stack.getItem() == Items.PAPER) {
|
||||
inventory.decrStackSize(i, 1);
|
||||
break;
|
||||
}
|
||||
@@ -414,7 +407,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
continue;
|
||||
}
|
||||
|
||||
posted += ((IStamps) stamp.getItem()).getPostage(stamp).getValue() * stamp.stackSize;
|
||||
posted += ((IStamps) stamp.getItem()).getPostage(stamp).getValue() * stamp.getCount();
|
||||
|
||||
if (posted >= postage) {
|
||||
return true;
|
||||
@@ -480,7 +473,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
}
|
||||
|
||||
if (((IStamps) stamp.getItem()).getPostage(stamp) == postage) {
|
||||
count += stamp.stackSize;
|
||||
count += stamp.getCount();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -501,7 +494,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
}
|
||||
|
||||
ItemStack stamp = inventory.getStackInSlot(j);
|
||||
if (stamp == null) {
|
||||
if (stamp.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -511,43 +504,44 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
if (((IStamps) stamp.getItem()).getPostage(stamp) == EnumPostage.values()[i]) {
|
||||
ItemStack decrease = inventory.decrStackSize(j, stampCount[i]);
|
||||
stampCount[i] -= decrease.stackSize;
|
||||
stampCount[i] -= decrease.getCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack[] getSurplusAttachments(int filled, ItemStack[] attachments) {
|
||||
ArrayList<ItemStack> surplus = new ArrayList<>();
|
||||
private NonNullList<ItemStack> getSurplusAttachments(int filled, NonNullList<ItemStack> attachments) {
|
||||
NonNullList<ItemStack> surplus = NonNullList.create();
|
||||
|
||||
// Get a copy of the attachments to play with
|
||||
ItemStack[] pool = new ItemStack[attachments.length];
|
||||
for (int i = 0; i < attachments.length; i++) {
|
||||
if (attachments[i] != null) {
|
||||
pool[i] = attachments[i].copy();
|
||||
NonNullList<ItemStack> pool = NonNullList.withSize(attachments.size(), ItemStack.EMPTY);
|
||||
for (int i = 0; i < attachments.size(); i++) {
|
||||
ItemStack attachment = attachments.get(i);
|
||||
if (!attachment.isEmpty()) {
|
||||
pool.set(i, attachment.copy());
|
||||
}
|
||||
}
|
||||
|
||||
// Remove stuff until we are only left with the remnants
|
||||
for (int i = 0; i < filled; i++) {
|
||||
ItemStack[] required = InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT);
|
||||
ItemStack[] condensedRequired = ItemStackUtil.condenseStacks(required);
|
||||
NonNullList<ItemStack> required = InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT);
|
||||
NonNullList<ItemStack> condensedRequired = ItemStackUtil.condenseStacks(required);
|
||||
for (ItemStack req : condensedRequired) {
|
||||
for (int j = 0; j < pool.length; j++) {
|
||||
ItemStack pol = pool[j];
|
||||
if (pol == null) {
|
||||
for (int j = 0; j < pool.size(); j++) {
|
||||
ItemStack pol = pool.get(j);
|
||||
if (pol.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (!pol.isItemEqual(req)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (req.stackSize >= pol.stackSize) {
|
||||
req.stackSize -= pol.stackSize;
|
||||
pool[j] = null;
|
||||
if (req.getCount() >= pol.getCount()) {
|
||||
req.shrink(pol.getCount());
|
||||
pool.set(j, ItemStack.EMPTY);
|
||||
} else {
|
||||
pol.stackSize -= req.stackSize;
|
||||
req.stackSize = 0;
|
||||
pol.shrink(req.getCount());
|
||||
req.setCount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -559,10 +553,16 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
}
|
||||
}
|
||||
|
||||
return surplus.toArray(new ItemStack[surplus.size()]);
|
||||
return surplus;
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return inventory.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
super.markDirty();
|
||||
@@ -606,7 +606,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
public boolean isUsableByPlayer(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,15 +18,16 @@ import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.EnumTradeStationState;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.ITradeStationInfo;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public class TradeStationInfo implements ITradeStationInfo {
|
||||
private final IMailAddress address;
|
||||
private final GameProfile owner;
|
||||
private final ItemStack tradegood;
|
||||
private final ItemStack[] required;
|
||||
private final NonNullList<ItemStack> required;
|
||||
private final EnumTradeStationState state;
|
||||
|
||||
public TradeStationInfo(IMailAddress address, GameProfile owner, ItemStack tradegood, ItemStack[] required, EnumTradeStationState state) {
|
||||
public TradeStationInfo(IMailAddress address, GameProfile owner, ItemStack tradegood, NonNullList<ItemStack> required, EnumTradeStationState state) {
|
||||
if (address.getType() != EnumAddressee.TRADER) {
|
||||
throw new IllegalArgumentException("TradeStation address must be a trader");
|
||||
}
|
||||
@@ -53,7 +54,7 @@ public class TradeStationInfo implements ITradeStationInfo {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getRequired() {
|
||||
public NonNullList<ItemStack> getRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.blocks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.core.blocks.IBlockType;
|
||||
import forestry.core.blocks.IMachineProperties;
|
||||
import forestry.core.blocks.MachineProperties;
|
||||
@@ -27,14 +25,12 @@ public enum BlockTypeMail implements IBlockType {
|
||||
|
||||
public static final BlockTypeMail[] VALUES = values();
|
||||
|
||||
@Nonnull
|
||||
private final IMachineProperties machineProperties;
|
||||
|
||||
<T extends TileForestry> BlockTypeMail(@Nonnull Class<T> teClass, @Nonnull String name) {
|
||||
<T extends TileForestry> BlockTypeMail(Class<T> teClass, String name) {
|
||||
this.machineProperties = new MachineProperties<>(teClass, name);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IMachineProperties getMachineProperties() {
|
||||
return machineProperties;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail.blocks;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -53,7 +53,7 @@ public class CommandMail extends SubCommand {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
return;
|
||||
}
|
||||
for (ITradeStation trade : PostManager.postRegistry.getPostOffice(((EntityPlayer) sender).worldObj).getActiveTradeStations(((EntityPlayer) sender).worldObj).values()) {
|
||||
for (ITradeStation trade : PostManager.postRegistry.getPostOffice(((EntityPlayer) sender).world).getActiveTradeStations(((EntityPlayer) sender).world).values()) {
|
||||
CommandHelpers.sendChatMessage(sender, makeTradeListEntry(trade.getTradeInfo()));
|
||||
}
|
||||
}
|
||||
@@ -62,14 +62,14 @@ public class CommandMail extends SubCommand {
|
||||
TextFormatting formatting = info.getState().isOk() ? TextFormatting.GREEN : TextFormatting.RED;
|
||||
|
||||
String tradegood = "[ ? ]";
|
||||
if (info.getTradegood() != null) {
|
||||
tradegood = info.getTradegood().stackSize + "x" + info.getTradegood().getDisplayName();
|
||||
if (!info.getTradegood().isEmpty()) {
|
||||
tradegood = info.getTradegood().getCount() + "x" + info.getTradegood().getDisplayName();
|
||||
}
|
||||
String demand = "[ ? ]";
|
||||
if (info.getRequired().length > 0) {
|
||||
if (!info.getRequired().isEmpty()) {
|
||||
demand = "";
|
||||
for (ItemStack dmd : info.getRequired()) {
|
||||
demand = StringUtil.append(", ", demand, dmd.stackSize + "x" + dmd.getDisplayName());
|
||||
demand = StringUtil.append(", ", demand, dmd.getCount() + "x" + dmd.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail.commands;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -1,7 +1,5 @@
|
||||
package forestry.mail.compat;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.core.utils.JeiUtil;
|
||||
import forestry.mail.PluginMail;
|
||||
import forestry.mail.blocks.BlockRegistryMail;
|
||||
@@ -12,7 +10,7 @@ import mezz.jei.api.JEIPlugin;
|
||||
@JEIPlugin
|
||||
public class MailJeiPlugin extends BlankModPlugin {
|
||||
@Override
|
||||
public void register(@Nonnull IModRegistry registry) {
|
||||
public void register(IModRegistry registry) {
|
||||
BlockRegistryMail blocks = PluginMail.blocks;
|
||||
JeiUtil.addDescription(registry,
|
||||
blocks.mailbox,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail.compat;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
+59
-60
@@ -1,60 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui.widgets;
|
||||
|
||||
import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.mail.gui.ContainerLetter;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
|
||||
public class AddresseeSlot extends Widget {
|
||||
|
||||
private final ContainerLetter containerLetter;
|
||||
|
||||
public AddresseeSlot(WidgetManager widgetManager, int xPos, int yPos, ContainerLetter containerLetter) {
|
||||
super(widgetManager, xPos, yPos);
|
||||
this.containerLetter = containerLetter;
|
||||
this.width = 26;
|
||||
this.height = 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int startX, int startY) {
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(containerLetter.getCarrierType());
|
||||
if (carrier != null) {
|
||||
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0F);
|
||||
Proxies.render.bindTexture(TextureManager.getInstance().getGuiTextureMap());
|
||||
manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, carrier.getSprite(), 32, 32);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolTip getToolTip(int mouseX, int mouseY) {
|
||||
String tooltipString = Translator.translateToLocal("for.gui.addressee." + containerLetter.getCarrierType());
|
||||
ToolTip tooltip = new ToolTip();
|
||||
tooltip.add(tooltipString);
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
|
||||
if (!containerLetter.getLetter().isProcessed()) {
|
||||
containerLetter.advanceCarrierType();
|
||||
Proxies.common.playButtonClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui;
|
||||
|
||||
import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
|
||||
public class AddresseeSlot extends Widget {
|
||||
|
||||
private final ContainerLetter containerLetter;
|
||||
|
||||
public AddresseeSlot(WidgetManager widgetManager, int xPos, int yPos, ContainerLetter containerLetter) {
|
||||
super(widgetManager, xPos, yPos);
|
||||
this.containerLetter = containerLetter;
|
||||
this.width = 26;
|
||||
this.height = 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int startX, int startY) {
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(containerLetter.getCarrierType());
|
||||
if (carrier != null) {
|
||||
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0F);
|
||||
Proxies.render.bindTexture(TextureManager.getInstance().getGuiTextureMap());
|
||||
manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, carrier.getSprite(), 32, 32);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolTip getToolTip(int mouseX, int mouseY) {
|
||||
String tooltipString = Translator.translateToLocal("for.gui.addressee." + containerLetter.getCarrierType());
|
||||
ToolTip tooltip = new ToolTip();
|
||||
tooltip.add(tooltipString);
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
|
||||
if (!containerLetter.getLetter().isProcessed()) {
|
||||
containerLetter.advanceCarrierType();
|
||||
Proxies.common.playButtonClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
@@ -40,6 +41,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
private final EntityPlayer player;
|
||||
private final List<ITradeStation> stations = new ArrayList<>();
|
||||
|
||||
@Nullable
|
||||
private ITradeStationInfo currentTrade = null;
|
||||
|
||||
private int stationIndex = 0;
|
||||
@@ -67,7 +69,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
public ContainerCatalogue(EntityPlayer player) {
|
||||
this.player = player;
|
||||
|
||||
if (!player.worldObj.isRemote) {
|
||||
if (!player.world.isRemote) {
|
||||
rebuildStationsList();
|
||||
}
|
||||
}
|
||||
@@ -87,14 +89,14 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
private void rebuildStationsList() {
|
||||
stations.clear();
|
||||
|
||||
IPostOffice postOffice = PostManager.postRegistry.getPostOffice(player.worldObj);
|
||||
Map<IMailAddress, ITradeStation> tradeStations = postOffice.getActiveTradeStations(player.worldObj);
|
||||
IPostOffice postOffice = PostManager.postRegistry.getPostOffice(player.world);
|
||||
Map<IMailAddress, ITradeStation> tradeStations = postOffice.getActiveTradeStations(player.world);
|
||||
|
||||
for (ITradeStation station : tradeStations.values()) {
|
||||
ITradeStationInfo info = station.getTradeInfo();
|
||||
|
||||
// Filter out any trade stations which do not actually offer anything.
|
||||
if (info.getTradegood() != null && FILTERS.get(currentFilter).contains(info.getState())) {
|
||||
if (FILTERS.get(currentFilter).contains(info.getState())) {
|
||||
stations.add(station);
|
||||
}
|
||||
}
|
||||
@@ -104,7 +106,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
}
|
||||
|
||||
public void nextPage() {
|
||||
if (player.worldObj.isRemote) {
|
||||
if (player.world.isRemote) {
|
||||
sendSelection(true);
|
||||
return;
|
||||
}
|
||||
@@ -117,7 +119,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
}
|
||||
|
||||
public void previousPage() {
|
||||
if (player.worldObj.isRemote) {
|
||||
if (player.world.isRemote) {
|
||||
sendSelection(false);
|
||||
return;
|
||||
}
|
||||
@@ -130,7 +132,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
}
|
||||
|
||||
public void cycleFilter() {
|
||||
if (player.worldObj.isRemote) {
|
||||
if (player.world.isRemote) {
|
||||
Proxies.net.sendToServer(new PacketGuiSelectRequest(2, 0));
|
||||
return;
|
||||
}
|
||||
@@ -148,7 +150,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
/* Managing Trade info */
|
||||
private void updateTradeInfo() {
|
||||
// Updating is done by the server.
|
||||
if (player.worldObj.isRemote) {
|
||||
if (player.world.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -162,15 +164,16 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLetterInfoUpdate(PacketLetterInfoResponse packet) {
|
||||
setTradeInfo(packet.tradeInfo);
|
||||
public void handleLetterInfoUpdate(EnumAddressee type, @Nullable IMailAddress address, @Nullable ITradeStationInfo tradeInfo) {
|
||||
setTradeInfo(tradeInfo);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ITradeStationInfo getTradeInfo() {
|
||||
return currentTrade;
|
||||
}
|
||||
|
||||
private void setTradeInfo(ITradeStationInfo info) {
|
||||
private void setTradeInfo(@Nullable ITradeStationInfo info) {
|
||||
currentTrade = info;
|
||||
}
|
||||
|
||||
@@ -211,9 +214,9 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelectionRequest(EntityPlayerMP player, PacketGuiSelectRequest packet) {
|
||||
public void handleSelectionRequest(EntityPlayerMP player, int primary, int secondary) {
|
||||
|
||||
switch (packet.getPrimaryIndex()) {
|
||||
switch (primary) {
|
||||
case 0:
|
||||
nextPage();
|
||||
break;
|
||||
|
||||
@@ -13,6 +13,7 @@ package forestry.mail.gui;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
|
||||
import forestry.core.utils.Log;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
@@ -28,7 +29,6 @@ import forestry.api.mail.ITradeStationInfo;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.network.packets.PacketString;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.Letter;
|
||||
import forestry.mail.inventory.ItemInventoryLetter;
|
||||
@@ -38,6 +38,7 @@ import forestry.mail.network.packets.PacketLetterTextSet;
|
||||
public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter> implements ILetterInfoReceiver {
|
||||
|
||||
private EnumAddressee carrierType = EnumAddressee.PLAYER;
|
||||
@Nullable
|
||||
private ITradeStationInfo tradeInfo = null;
|
||||
|
||||
public ContainerLetter(EntityPlayer player, ItemInventoryLetter inventory) {
|
||||
@@ -58,7 +59,7 @@ public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter>
|
||||
}
|
||||
|
||||
// Rip open delivered mails
|
||||
if (!player.worldObj.isRemote) {
|
||||
if (!player.world.isRemote) {
|
||||
if (inventory.getLetter().isProcessed()) {
|
||||
inventory.onLetterOpened();
|
||||
}
|
||||
@@ -67,9 +68,9 @@ public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter>
|
||||
// Set recipient type
|
||||
ILetter letter = inventory.getLetter();
|
||||
if (letter != null) {
|
||||
IMailAddress[] recipients = letter.getRecipients();
|
||||
if (recipients != null && recipients.length > 0) {
|
||||
this.carrierType = recipients[0].getType();
|
||||
IMailAddress recipient = letter.getRecipient();
|
||||
if (recipient != null) {
|
||||
this.carrierType = recipient.getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,7 +78,7 @@ public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter>
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer entityplayer) {
|
||||
|
||||
if (!entityplayer.worldObj.isRemote) {
|
||||
if (!entityplayer.world.isRemote) {
|
||||
ILetter letter = inventory.getLetter();
|
||||
if (!letter.isProcessed()) {
|
||||
IMailAddress sender = PostManager.postRegistry.getMailAddress(entityplayer.getGameProfile());
|
||||
@@ -121,13 +122,18 @@ public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter>
|
||||
}
|
||||
|
||||
public void handleRequestLetterInfo(EntityPlayer player, String recipientName, EnumAddressee type) {
|
||||
IMailAddress recipient = getRecipient(player.getServer(), recipientName, type);
|
||||
MinecraftServer server = player.getServer();
|
||||
if (server == null) {
|
||||
Log.error("Could not get server");
|
||||
return;
|
||||
}
|
||||
IMailAddress recipient = getRecipient(server, recipientName, type);
|
||||
|
||||
getLetter().setRecipient(recipient);
|
||||
|
||||
// Update the trading info
|
||||
if (recipient == null || recipient.getType() == EnumAddressee.TRADER) {
|
||||
updateTradeInfo(player.worldObj, recipient);
|
||||
updateTradeInfo(player.world, recipient);
|
||||
}
|
||||
|
||||
// Update info on client
|
||||
@@ -152,12 +158,9 @@ public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter>
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IMailAddress getRecipient() {
|
||||
if (getLetter().getRecipients().length > 0) {
|
||||
return getLetter().getRecipients()[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return getLetter().getRecipient();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
@@ -170,13 +173,12 @@ public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter>
|
||||
Proxies.net.sendToServer(new PacketLetterTextSet(text));
|
||||
}
|
||||
|
||||
public void handleSetText(PacketString packet) {
|
||||
String text = packet.getString();
|
||||
public void handleSetText(String text) {
|
||||
getLetter().setText(text);
|
||||
}
|
||||
|
||||
/* Managing Trade info */
|
||||
private void updateTradeInfo(World world, IMailAddress address) {
|
||||
private void updateTradeInfo(World world, @Nullable IMailAddress address) {
|
||||
// Updating is done by the server.
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
@@ -197,20 +199,21 @@ public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLetterInfoUpdate(PacketLetterInfoResponse packet) {
|
||||
carrierType = packet.type;
|
||||
if (packet.type == EnumAddressee.PLAYER) {
|
||||
getLetter().setRecipient(packet.address);
|
||||
} else if (packet.type == EnumAddressee.TRADER) {
|
||||
this.setTradeInfo(packet.tradeInfo);
|
||||
public void handleLetterInfoUpdate(EnumAddressee type, @Nullable IMailAddress address, @Nullable ITradeStationInfo tradeInfo) {
|
||||
carrierType = type;
|
||||
if (type == EnumAddressee.PLAYER) {
|
||||
getLetter().setRecipient(address);
|
||||
} else if (type == EnumAddressee.TRADER) {
|
||||
this.setTradeInfo(tradeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ITradeStationInfo getTradeInfo() {
|
||||
return this.tradeInfo;
|
||||
}
|
||||
|
||||
private void setTradeInfo(ITradeStationInfo info) {
|
||||
private void setTradeInfo(@Nullable ITradeStationInfo info) {
|
||||
this.tradeInfo = info;
|
||||
if (tradeInfo == null) {
|
||||
getLetter().setRecipient(null);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ClickType;
|
||||
@@ -22,19 +24,19 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
import forestry.mail.POBox;
|
||||
import forestry.mail.POBoxInfo;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoResponse;
|
||||
import forestry.mail.tiles.TileMailbox;
|
||||
|
||||
public class ContainerMailbox extends ContainerTile<TileMailbox> {
|
||||
|
||||
public static final short SLOT_LETTERS = 0;
|
||||
public static final short SLOT_LETTERS_COUNT = 7 * 12;
|
||||
|
||||
@Nullable
|
||||
private final POBox mailInventory;
|
||||
|
||||
public ContainerMailbox(InventoryPlayer playerInventory, TileMailbox tile) {
|
||||
super(tile, playerInventory, 35, 145);
|
||||
IInventory inventory = tile.getOrCreateMailInventory(playerInventory.player.worldObj, playerInventory.player.getGameProfile());
|
||||
IInventory inventory = tile.getOrCreateMailInventory(playerInventory.player.world, playerInventory.player.getGameProfile());
|
||||
|
||||
if (inventory instanceof POBox) {
|
||||
this.mailInventory = (POBox) inventory;
|
||||
@@ -54,9 +56,9 @@ public class ContainerMailbox extends ContainerTile<TileMailbox> {
|
||||
ItemStack stack = super.slotClick(slotId, dragType_or_button, clickTypeIn, player);
|
||||
|
||||
if (SlotUtil.isSlotInRange(slotId, SLOT_LETTERS, SLOT_LETTERS_COUNT)) {
|
||||
if (!player.worldObj.isRemote && mailInventory != null) {
|
||||
if (!player.world.isRemote && mailInventory != null) {
|
||||
POBoxInfo info = mailInventory.getPOBoxInfo();
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoUpdate(info), player);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(info), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ public class GuiCatalogue extends GuiForestry<ContainerCatalogue, IInventory> {
|
||||
super(new ResourceLocation("textures/gui/book.png"), new ContainerCatalogue(player), null);
|
||||
this.xSize = 192;
|
||||
this.ySize = 192;
|
||||
|
||||
buttonFilter = new GuiButton(4, width / 2 - 44, guiTop + 150, 42, 20, Translator.translateToLocal("for.gui.mail.filter.all"));
|
||||
buttonUse = new GuiButton(5, width / 2, guiTop + 150, 42, 20, Translator.translateToLocal("for.gui.mail.address.copy"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,8 +107,8 @@ public class GuiCatalogue extends GuiForestry<ContainerCatalogue, IInventory> {
|
||||
|
||||
fontRendererObj.drawString(Translator.translateToLocal("for.gui.mail.tradefor"), x, y + 46, ColourProperties.INSTANCE.get("gui.book"));
|
||||
|
||||
for (int i = 0; i < tradeInfo.getRequired().length; i++) {
|
||||
ItemStack itemStack = tradeInfo.getRequired()[i];
|
||||
for (int i = 0; i < tradeInfo.getRequired().size(); i++) {
|
||||
ItemStack itemStack = tradeInfo.getRequired().get(i);
|
||||
addTradeInfoWidget(new ItemStackWidget(widgetManager, x - guiLeft + i * 18, y - guiTop + 56, itemStack));
|
||||
}
|
||||
|
||||
@@ -132,7 +135,7 @@ public class GuiCatalogue extends GuiForestry<ContainerCatalogue, IInventory> {
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
switch (button.id) {
|
||||
case 0:
|
||||
mc.thePlayer.closeScreen();
|
||||
mc.player.closeScreen();
|
||||
break;
|
||||
case 2:
|
||||
container.nextPage();
|
||||
@@ -149,7 +152,7 @@ public class GuiCatalogue extends GuiForestry<ContainerCatalogue, IInventory> {
|
||||
SessionVars.setStringVar("mail.letter.recipient", info.getAddress().getName());
|
||||
SessionVars.setStringVar("mail.letter.addressee", EnumAddressee.TRADER.toString());
|
||||
}
|
||||
mc.thePlayer.closeScreen();
|
||||
mc.player.closeScreen();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.ColourProperties;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.mail.gui.widgets.AddresseeSlot;
|
||||
import forestry.mail.inventory.ItemInventoryLetter;
|
||||
import forestry.mail.network.packets.PacketLetterInfoRequest;
|
||||
|
||||
@@ -56,6 +55,9 @@ public class GuiLetter extends GuiForestry<ContainerLetter, ItemInventoryLetter>
|
||||
this.isProcessedLetter = container.getLetter().isProcessed();
|
||||
this.widgetManager.add(new AddresseeSlot(widgetManager, 16, 12, container));
|
||||
this.tradeInfoWidgets = new ArrayList<>();
|
||||
|
||||
address = new GuiTextField(0, this.fontRendererObj, guiLeft + 46, guiTop + 13, 93, 13);
|
||||
text = new GuiTextBox(1, this.fontRendererObj, guiLeft + 17, guiTop + 31, 122, 57);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,7 +167,7 @@ public class GuiLetter extends GuiForestry<ContainerLetter, ItemInventoryLetter>
|
||||
String infoString = null;
|
||||
if (container.getTradeInfo() == null) {
|
||||
infoString = Translator.translateToLocal("for.gui.mail.no.trader");
|
||||
} else if (container.getTradeInfo().getTradegood() == null) {
|
||||
} else if (container.getTradeInfo().getTradegood().isEmpty()) {
|
||||
infoString = Translator.translateToLocal("for.gui.mail.nothing.to.trade");
|
||||
} else if (!container.getTradeInfo().getState().isOk()) {
|
||||
infoString = container.getTradeInfo().getState().getDescription();
|
||||
@@ -182,8 +184,8 @@ public class GuiLetter extends GuiForestry<ContainerLetter, ItemInventoryLetter>
|
||||
|
||||
fontRendererObj.drawString(Translator.translateToLocal("for.gui.mail.foreveryattached"), guiLeft + x, guiTop + y + 28, ColourProperties.INSTANCE.get("gui.mail.lettertext"));
|
||||
|
||||
for (int i = 0; i < container.getTradeInfo().getRequired().length; i++) {
|
||||
addTradeInfoWidget(new ItemStackWidget(widgetManager, x + i * 18, y + 38, container.getTradeInfo().getRequired()[i]));
|
||||
for (int i = 0; i < container.getTradeInfo().getRequired().size(); i++) {
|
||||
addTradeInfoWidget(new ItemStackWidget(widgetManager, x + i * 18, y + 38, container.getTradeInfo().getRequired().get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +231,7 @@ public class GuiLetter extends GuiForestry<ContainerLetter, ItemInventoryLetter>
|
||||
}
|
||||
|
||||
private void setRecipient(String recipientName, EnumAddressee type) {
|
||||
if (this.isProcessedLetter || StringUtils.isBlank(recipientName) || type == null) {
|
||||
if (this.isProcessedLetter || StringUtils.isBlank(recipientName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.proxy.Proxies;
|
||||
@@ -41,6 +43,7 @@ public class GuiMailboxInfo extends Gui {
|
||||
private static final int HEIGHT = 17;
|
||||
|
||||
private final FontRenderer fontRendererObj;
|
||||
@Nullable
|
||||
private POBoxInfo poInfo;
|
||||
// TODO: this texture is a terrible waste of space in graphics memory, find a better way to do it.
|
||||
private final ResourceLocation textureAlert = new ForestryResource(Constants.TEXTURE_PATH_GUI + "/mailalert.png");
|
||||
@@ -96,7 +99,7 @@ public class GuiMailboxInfo extends Gui {
|
||||
}
|
||||
|
||||
if (playJingle) {
|
||||
EntityPlayerSP thePlayer = Proxies.common.getClientInstance().thePlayer;
|
||||
EntityPlayerSP thePlayer = Proxies.common.getClientInstance().player;
|
||||
World world = Proxies.common.getRenderWorld();
|
||||
world.playSound(null, thePlayer.posX, thePlayer.posY, thePlayer.posZ, SoundEvents.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1.0f, 1.0F);
|
||||
}
|
||||
|
||||
@@ -12,12 +12,6 @@ package forestry.mail.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiForestry;
|
||||
import forestry.core.proxy.Proxies;
|
||||
@@ -25,15 +19,19 @@ import forestry.core.render.ColourProperties;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.mail.network.packets.PacketTraderAddressRequest;
|
||||
import forestry.mail.tiles.TileTrader;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class GuiTradeName extends GuiForestry<ContainerTradeName, TileTrader> {
|
||||
|
||||
private GuiTextField addressNameField;
|
||||
|
||||
public GuiTradeName(TileTrader tile) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/tradername.png", new ContainerTradeName(tile), tile);
|
||||
this.xSize = 176;
|
||||
this.ySize = 90;
|
||||
|
||||
addressNameField = new GuiTextField(0, this.fontRendererObj, guiLeft + 44, guiTop + 39, 90, 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,9 +39,7 @@ public class GuiTradeName extends GuiForestry<ContainerTradeName, TileTrader> {
|
||||
super.initGui();
|
||||
|
||||
addressNameField = new GuiTextField(0, this.fontRendererObj, guiLeft + 44, guiTop + 39, 90, 14);
|
||||
if (container.getAddress() != null) {
|
||||
addressNameField.setText(container.getAddress().getName());
|
||||
}
|
||||
addressNameField.setText(container.getAddress().getName());
|
||||
addressNameField.setFocused(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
@@ -28,6 +29,7 @@ public class GuiTrader extends GuiForestry<ContainerTrader, TileTrader> {
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
Preconditions.checkState(inventory != null);
|
||||
String name = Translator.translateToLocal(inventory.getUnlocalizedTitle());
|
||||
this.fontRendererObj.drawString(name, textLayout.getCenteredOffset(name), 6, ColourProperties.INSTANCE.get("gui.mail.text"));
|
||||
|
||||
|
||||
@@ -10,8 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui;
|
||||
|
||||
import forestry.mail.network.packets.PacketLetterInfoResponse;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.ITradeStationInfo;
|
||||
|
||||
public interface ILetterInfoReceiver {
|
||||
void handleLetterInfoUpdate(PacketLetterInfoResponse packet);
|
||||
void handleLetterInfoUpdate(EnumAddressee type, @Nullable IMailAddress address, @Nullable ITradeStationInfo tradeInfo);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail.gui;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -11,27 +11,27 @@
|
||||
package forestry.mail.inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.api.mail.IStamps;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
import forestry.mail.TradeStation;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class InventoryTradeStation extends InventoryAdapter {
|
||||
|
||||
public InventoryTradeStation() {
|
||||
super(TradeStation.SLOT_SIZE, "INV");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getSlotsForFace(EnumFacing side) {
|
||||
ArrayList<Integer> slots = new ArrayList<>();
|
||||
List<Integer> slots = new ArrayList<>();
|
||||
|
||||
for (int i = TradeStation.SLOT_LETTERS_1; i < TradeStation.SLOT_LETTERS_1 + TradeStation.SLOT_LETTERS_COUNT; i++) {
|
||||
slots.add(i);
|
||||
|
||||
@@ -10,15 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.inventory;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import forestry.api.core.IErrorSource;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.api.mail.ILetter;
|
||||
@@ -31,12 +26,19 @@ import forestry.core.utils.SlotUtil;
|
||||
import forestry.mail.Letter;
|
||||
import forestry.mail.LetterProperties;
|
||||
import forestry.mail.items.ItemStamps;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ItemInventoryLetter extends ItemInventory implements IErrorSource, IHintSource {
|
||||
private ILetter letter;
|
||||
private final ILetter letter;
|
||||
|
||||
public ItemInventoryLetter(EntityPlayer player,ItemStack itemstack) {
|
||||
public ItemInventoryLetter(EntityPlayer player, ItemStack itemstack) {
|
||||
super(player, 0, itemstack);
|
||||
NBTTagCompound tagCompound = itemstack.getTagCompound();
|
||||
Preconditions.checkNotNull(tagCompound);
|
||||
letter = new Letter(tagCompound);
|
||||
}
|
||||
|
||||
public ILetter getLetter() {
|
||||
@@ -45,42 +47,29 @@ public class ItemInventoryLetter extends ItemInventory implements IErrorSource,
|
||||
|
||||
public void onLetterClosed() {
|
||||
ItemStack parent = getParent();
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LetterProperties.closeLetter(parent, letter);
|
||||
}
|
||||
|
||||
public void onLetterOpened() {
|
||||
ItemStack parent = getParent();
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LetterProperties.openLetter(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
if (nbttagcompound == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
letter = new Letter(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
ItemStack result = letter.decrStackSize(i, j);
|
||||
letter.writeToNBT(getParent().getTagCompound());
|
||||
public ItemStack decrStackSize(int index, int count) {
|
||||
ItemStack result = letter.decrStackSize(index, count);
|
||||
NBTTagCompound tagCompound = getParent().getTagCompound();
|
||||
Preconditions.checkNotNull(tagCompound);
|
||||
letter.writeToNBT(tagCompound);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
letter.setInventorySlotContents(i, itemstack);
|
||||
letter.writeToNBT(getParent().getTagCompound());
|
||||
public void setInventorySlotContents(int index, ItemStack itemstack) {
|
||||
letter.setInventorySlotContents(index, itemstack);
|
||||
NBTTagCompound tagCompound = getParent().getTagCompound();
|
||||
Preconditions.checkNotNull(tagCompound);
|
||||
letter.writeToNBT(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,10 +93,10 @@ public class ItemInventoryLetter extends ItemInventory implements IErrorSource,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return letter.isUseableByPlayer(entityplayer);
|
||||
public boolean isUsableByPlayer(EntityPlayer entityplayer) {
|
||||
return letter.isUsableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot) {
|
||||
return letter.removeStackFromSlot(slot);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail.inventory;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -29,6 +29,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -40,12 +41,13 @@ public class ItemLetter extends ItemWithGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
|
||||
if (itemStackIn.stackSize == 1) {
|
||||
return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand);
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
|
||||
ItemStack heldItem = playerIn.getHeldItem(handIn);
|
||||
if (heldItem.getCount() == 1) {
|
||||
return super.onItemRightClick(worldIn, playerIn, handIn);
|
||||
} else {
|
||||
playerIn.addChatMessage(new TextComponentTranslation("for.chat.mail.wrongstacksize"));
|
||||
return ActionResult.newResult(EnumActionResult.FAIL, itemStackIn);
|
||||
playerIn.sendMessage(new TextComponentTranslation("for.chat.mail.wrongstacksize"));
|
||||
return ActionResult.newResult(EnumActionResult.FAIL, heldItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +76,10 @@ public class ItemLetter extends ItemWithGui {
|
||||
ILetter letter = new Letter(nbttagcompound);
|
||||
letter.addTooltip(list);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> list) {
|
||||
LetterProperties.getSubItems(item, tab, list);
|
||||
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> subItems) {
|
||||
LetterProperties.getSubItems(item, tab, subItems);
|
||||
}
|
||||
|
||||
public List<ItemStack> getEmptiedLetters() {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail.items;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -10,23 +10,25 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.network;
|
||||
|
||||
import forestry.core.network.PacketRegistry;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.mail.network.packets.PacketLetterInfoRequest;
|
||||
import forestry.mail.network.packets.PacketLetterInfoResponse;
|
||||
import forestry.mail.network.packets.PacketLetterTextSet;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoResponse;
|
||||
import forestry.mail.network.packets.PacketTraderAddressRequest;
|
||||
import forestry.mail.network.packets.PacketTraderAddressResponse;
|
||||
|
||||
public class PacketRegistryMail extends PacketRegistry {
|
||||
public class PacketRegistryMail implements IPacketRegistry {
|
||||
@Override
|
||||
public void registerPackets() {
|
||||
registerServerPacket(new PacketLetterInfoRequest());
|
||||
registerServerPacket(new PacketTraderAddressRequest());
|
||||
registerServerPacket(new PacketLetterTextSet());
|
||||
|
||||
registerClientPacket(new PacketLetterInfoResponse());
|
||||
registerClientPacket(new PacketTraderAddressResponse());
|
||||
registerClientPacket(new PacketPOBoxInfoUpdate());
|
||||
PacketIdClient.LETTER_INFO_RESPONSE.setPacketHandler(new PacketLetterInfoResponse.Handler());
|
||||
PacketIdClient.TRADING_ADDRESS_RESPONSE.setPacketHandler(new PacketTraderAddressResponse.Handler());
|
||||
PacketIdClient.POBOX_INFO_RESPONSE.setPacketHandler(new PacketPOBoxInfoResponse.Handler());
|
||||
|
||||
PacketIdServer.LETTER_INFO_REQUEST.setPacketHandler(new PacketLetterInfoRequest.Handler());
|
||||
PacketIdServer.TRADING_ADDRESS_REQUEST.setPacketHandler(new PacketTraderAddressRequest.Handler());
|
||||
PacketIdServer.LETTER_TEXT_SET.setPacketHandler(new PacketLetterTextSet.Handler());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail.network;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -12,54 +12,46 @@ package forestry.mail.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketHandlerServer;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.mail.gui.ContainerLetter;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
public class PacketLetterInfoRequest extends ForestryPacket implements IForestryPacketServer {
|
||||
|
||||
private String recipientName;
|
||||
private EnumAddressee addressType;
|
||||
|
||||
public PacketLetterInfoRequest() {
|
||||
}
|
||||
private final String recipientName;
|
||||
private final EnumAddressee addressType;
|
||||
|
||||
public PacketLetterInfoRequest(String recipientName, EnumAddressee addressType) {
|
||||
this.recipientName = recipientName;
|
||||
this.addressType = addressType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeUTF(recipientName);
|
||||
data.writeByte(addressType.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
recipientName = data.readUTF();
|
||||
addressType = EnumAddressee.values()[data.readByte()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
if (!(player.openContainer instanceof ContainerLetter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
((ContainerLetter) player.openContainer).handleRequestLetterInfo(player, recipientName, addressType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.LETTER_INFO_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(PacketBufferForestry data) throws IOException {
|
||||
data.writeString(recipientName);
|
||||
data.writeEnum(addressType, EnumAddressee.values());
|
||||
}
|
||||
|
||||
public static class Handler implements IForestryPacketHandlerServer {
|
||||
|
||||
@Override
|
||||
public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException {
|
||||
String recipientName = data.readString();
|
||||
EnumAddressee addressType = data.readEnum(EnumAddressee.values());
|
||||
|
||||
if (player.openContainer instanceof ContainerLetter) {
|
||||
ContainerLetter containerLetter = (ContainerLetter) player.openContainer;
|
||||
containerLetter.handleRequestLetterInfo(player, recipientName, addressType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,43 +10,46 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.network.packets;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.EnumTradeStationState;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.ITradeStationInfo;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.IForestryPacketHandlerClient;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.mail.TradeStationInfo;
|
||||
import forestry.mail.gui.ILetterInfoReceiver;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
// TODO: split this into two different packets
|
||||
public class PacketLetterInfoResponse extends ForestryPacket implements IForestryPacketClient {
|
||||
public final EnumAddressee type;
|
||||
public final ITradeStationInfo tradeInfo;
|
||||
@Nullable
|
||||
public final IMailAddress address;
|
||||
|
||||
public EnumAddressee type;
|
||||
public ITradeStationInfo tradeInfo;
|
||||
public IMailAddress address;
|
||||
|
||||
public PacketLetterInfoResponse() {
|
||||
}
|
||||
|
||||
public PacketLetterInfoResponse(EnumAddressee type, ITradeStationInfo info, IMailAddress address) {
|
||||
public PacketLetterInfoResponse(EnumAddressee type, ITradeStationInfo info, @Nullable IMailAddress address) {
|
||||
this.type = type;
|
||||
if (type == EnumAddressee.TRADER) {
|
||||
this.tradeInfo = info;
|
||||
this.address = null;
|
||||
} else if (type == EnumAddressee.PLAYER) {
|
||||
this.tradeInfo = info;
|
||||
this.address = address;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown addressee type: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,91 +59,55 @@ public class PacketLetterInfoResponse extends ForestryPacket implements IForestr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
|
||||
if (type == null) {
|
||||
data.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
data.writeShort(0);
|
||||
|
||||
data.writeUTF(type.toString());
|
||||
public void writeData(PacketBufferForestry data) {
|
||||
data.writeEnum(type, EnumAddressee.values());
|
||||
|
||||
if (type == EnumAddressee.PLAYER) {
|
||||
|
||||
if (address == null) {
|
||||
data.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
data.writeShort(0);
|
||||
|
||||
Preconditions.checkNotNull(address);
|
||||
GameProfile profile = address.getPlayerProfile();
|
||||
|
||||
data.writeLong(profile.getId().getMostSignificantBits());
|
||||
data.writeLong(profile.getId().getLeastSignificantBits());
|
||||
data.writeUTF(profile.getName());
|
||||
data.writeString(profile.getName());
|
||||
|
||||
} else if (type == EnumAddressee.TRADER) {
|
||||
|
||||
if (tradeInfo == null) {
|
||||
data.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
data.writeShort(0);
|
||||
|
||||
data.writeUTF(tradeInfo.getAddress().getName());
|
||||
data.writeString(tradeInfo.getAddress().getName());
|
||||
|
||||
data.writeLong(tradeInfo.getOwner().getId().getMostSignificantBits());
|
||||
data.writeLong(tradeInfo.getOwner().getId().getLeastSignificantBits());
|
||||
data.writeUTF(tradeInfo.getOwner().getName());
|
||||
data.writeString(tradeInfo.getOwner().getName());
|
||||
|
||||
data.writeItemStack(tradeInfo.getTradegood());
|
||||
data.writeItemStacks(tradeInfo.getRequired());
|
||||
|
||||
data.writeShort(tradeInfo.getState().ordinal());
|
||||
data.writeEnum(tradeInfo.getState(), EnumTradeStationState.values());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
public static class Handler implements IForestryPacketHandlerClient {
|
||||
@Override
|
||||
public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException {
|
||||
Container container = player.openContainer;
|
||||
if (container instanceof ILetterInfoReceiver) {
|
||||
EnumAddressee type = data.readEnum(EnumAddressee.values());
|
||||
ITradeStationInfo tradeInfo = null;
|
||||
IMailAddress address = null;
|
||||
|
||||
if (data.readShort() < 0) {
|
||||
return;
|
||||
}
|
||||
if (type == EnumAddressee.PLAYER) {
|
||||
GameProfile profile = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readString());
|
||||
address = PostManager.postRegistry.getMailAddress(profile);
|
||||
} else if (type == EnumAddressee.TRADER) {
|
||||
address = PostManager.postRegistry.getMailAddress(data.readString());
|
||||
GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readString());
|
||||
|
||||
type = EnumAddressee.fromString(data.readUTF());
|
||||
tradeInfo = null;
|
||||
address = null;
|
||||
ItemStack tradegood = data.readItemStack();
|
||||
NonNullList<ItemStack> required = data.readItemStacks();
|
||||
|
||||
if (type == EnumAddressee.PLAYER) {
|
||||
if (data.readShort() < 0) {
|
||||
return;
|
||||
EnumTradeStationState state = data.readEnum(EnumTradeStationState.values());
|
||||
tradeInfo = new TradeStationInfo(address, owner, tradegood, required, state);
|
||||
}
|
||||
((ILetterInfoReceiver) container).handleLetterInfoUpdate(type, address, tradeInfo);
|
||||
}
|
||||
GameProfile player = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
this.address = PostManager.postRegistry.getMailAddress(player);
|
||||
|
||||
} else if (type == EnumAddressee.TRADER) {
|
||||
if (data.readShort() < 0) {
|
||||
return;
|
||||
}
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(data.readUTF());
|
||||
GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
ItemStack tradegood;
|
||||
ItemStack[] required;
|
||||
|
||||
tradegood = data.readItemStack();
|
||||
required = data.readItemStacks();
|
||||
|
||||
this.tradeInfo = new TradeStationInfo(address, owner, tradegood, required, EnumTradeStationState.values()[data.readShort()]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException {
|
||||
Container container = player.openContainer;
|
||||
if (container instanceof ILetterInfoReceiver) {
|
||||
((ILetterInfoReceiver) container).handleLetterInfoUpdate(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,21 +12,19 @@ package forestry.mail.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketHandlerServer;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.mail.gui.ContainerLetter;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.core.network.packets.PacketString;
|
||||
import forestry.mail.gui.ContainerLetter;
|
||||
|
||||
public class PacketLetterTextSet extends PacketString implements IForestryPacketServer {
|
||||
|
||||
public PacketLetterTextSet() {
|
||||
}
|
||||
public class PacketLetterTextSet extends ForestryPacket implements IForestryPacketServer {
|
||||
private final String string;
|
||||
|
||||
public PacketLetterTextSet(String string) {
|
||||
super(string);
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,11 +33,18 @@ public class PacketLetterTextSet extends PacketString implements IForestryPacket
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
if (!(player.openContainer instanceof ContainerLetter)) {
|
||||
return;
|
||||
}
|
||||
protected void writeData(PacketBufferForestry data) throws IOException {
|
||||
data.writeString(string);
|
||||
}
|
||||
|
||||
((ContainerLetter) player.openContainer).handleSetText(this);
|
||||
public static class Handler implements IForestryPacketHandlerServer {
|
||||
|
||||
@Override
|
||||
public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException {
|
||||
if (player.openContainer instanceof ContainerLetter) {
|
||||
String string = data.readString();
|
||||
((ContainerLetter) player.openContainer).handleSetText(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-31
@@ -12,24 +12,19 @@ package forestry.mail.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.IForestryPacketHandlerClient;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.mail.POBoxInfo;
|
||||
import forestry.mail.gui.GuiMailboxInfo;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class PacketPOBoxInfoUpdate extends ForestryPacket implements IForestryPacketClient {
|
||||
public class PacketPOBoxInfoResponse extends ForestryPacket implements IForestryPacketClient {
|
||||
public final POBoxInfo poboxInfo;
|
||||
|
||||
public POBoxInfo poboxInfo;
|
||||
|
||||
public PacketPOBoxInfoUpdate() {
|
||||
}
|
||||
|
||||
public PacketPOBoxInfoUpdate(POBoxInfo info) {
|
||||
public PacketPOBoxInfoResponse(POBoxInfo info) {
|
||||
this.poboxInfo = info;
|
||||
}
|
||||
|
||||
@@ -39,30 +34,17 @@ public class PacketPOBoxInfoUpdate extends ForestryPacket implements IForestryPa
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
if (poboxInfo == null) {
|
||||
data.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
data.writeShort(0);
|
||||
protected void writeData(PacketBufferForestry data) throws IOException {
|
||||
data.writeInt(poboxInfo.playerLetters);
|
||||
data.writeInt(poboxInfo.tradeLetters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
short isNotNull = data.readShort();
|
||||
if (isNotNull < 0) {
|
||||
return;
|
||||
public static class Handler implements IForestryPacketHandlerClient {
|
||||
|
||||
@Override
|
||||
public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException {
|
||||
POBoxInfo poboxInfo = new POBoxInfo(data.readInt(), data.readInt());
|
||||
GuiMailboxInfo.instance.setPOBoxInfo(poboxInfo);
|
||||
}
|
||||
|
||||
this.poboxInfo = new POBoxInfo(data.readInt(), data.readInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException {
|
||||
GuiMailboxInfo.instance.setPOBoxInfo(poboxInfo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,25 +12,22 @@ package forestry.mail.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketHandlerServer;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.mail.tiles.TileTrader;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.core.network.packets.PacketCoordinates;
|
||||
import forestry.mail.tiles.TileTrader;
|
||||
|
||||
public class PacketTraderAddressRequest extends PacketCoordinates implements IForestryPacketServer {
|
||||
|
||||
private String addressName;
|
||||
|
||||
public PacketTraderAddressRequest() {
|
||||
}
|
||||
public class PacketTraderAddressRequest extends ForestryPacket implements IForestryPacketServer {
|
||||
private final BlockPos pos;
|
||||
private final String addressName;
|
||||
|
||||
public PacketTraderAddressRequest(TileTrader tile, String addressName) {
|
||||
super(tile);
|
||||
this.pos = tile.getPos();
|
||||
this.addressName = addressName;
|
||||
}
|
||||
|
||||
@@ -40,22 +37,22 @@ public class PacketTraderAddressRequest extends PacketCoordinates implements IFo
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeUTF(addressName);
|
||||
protected void writeData(PacketBufferForestry data) throws IOException {
|
||||
data.writeBlockPos(pos);
|
||||
data.writeString(addressName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
addressName = data.readUTF();
|
||||
}
|
||||
public static class Handler implements IForestryPacketHandlerServer {
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
TileEntity tile = getTarget(player.worldObj);
|
||||
if (tile instanceof TileTrader) {
|
||||
((TileTrader) tile).handleSetAddressRequest(addressName);
|
||||
@Override
|
||||
public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException {
|
||||
BlockPos pos = data.readBlockPos();
|
||||
String addressName = data.readString();
|
||||
|
||||
TileEntity tile = player.world.getTileEntity(pos);
|
||||
if (tile instanceof TileTrader) {
|
||||
((TileTrader) tile).handleSetAddressRequest(addressName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,25 +12,22 @@ package forestry.mail.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.IForestryPacketHandlerClient;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.mail.tiles.TileTrader;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.network.packets.PacketCoordinates;
|
||||
import forestry.mail.tiles.TileTrader;
|
||||
|
||||
public class PacketTraderAddressResponse extends PacketCoordinates implements IForestryPacketClient {
|
||||
|
||||
private String addressName;
|
||||
|
||||
public PacketTraderAddressResponse() {
|
||||
}
|
||||
public class PacketTraderAddressResponse extends ForestryPacket implements IForestryPacketClient {
|
||||
private final BlockPos pos;
|
||||
private final String addressName;
|
||||
|
||||
public PacketTraderAddressResponse(TileTrader tile, String addressName) {
|
||||
super(tile);
|
||||
this.pos = tile.getPos();
|
||||
this.addressName = addressName;
|
||||
}
|
||||
|
||||
@@ -40,23 +37,22 @@ public class PacketTraderAddressResponse extends PacketCoordinates implements IF
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeUTF(addressName);
|
||||
protected void writeData(PacketBufferForestry data) throws IOException {
|
||||
data.writeBlockPos(pos);
|
||||
data.writeString(addressName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
addressName = data.readUTF();
|
||||
}
|
||||
public static class Handler implements IForestryPacketHandlerClient {
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException {
|
||||
TileEntity tile = getTarget(player.worldObj);
|
||||
if (tile instanceof TileTrader) {
|
||||
((TileTrader) tile).handleSetAddressResponse(addressName);
|
||||
@Override
|
||||
public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException {
|
||||
BlockPos pos = data.readBlockPos();
|
||||
String addressName = data.readString();
|
||||
|
||||
TileEntity tile = player.world.getTileEntity(pos);
|
||||
if (tile instanceof TileTrader) {
|
||||
((TileTrader) tile).handleSetAddressResponse(addressName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail.network.packets;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -10,16 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.IPostalState;
|
||||
@@ -31,6 +22,11 @@ import forestry.mail.POBox;
|
||||
import forestry.mail.PostRegistry;
|
||||
import forestry.mail.gui.ContainerMailbox;
|
||||
import forestry.mail.gui.GuiMailbox;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileMailbox extends TileBase {
|
||||
|
||||
@@ -42,7 +38,7 @@ public class TileMailbox extends TileBase {
|
||||
/* GUI */
|
||||
@Override
|
||||
public void openGui(EntityPlayer player, ItemStack heldItem) {
|
||||
if (worldObj.isRemote) {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -50,9 +46,9 @@ public class TileMailbox extends TileBase {
|
||||
if (PostManager.postRegistry.isLetter(heldItem)) {
|
||||
IPostalState result = this.tryDispatchLetter(heldItem);
|
||||
if (!result.isOk()) {
|
||||
player.addChatMessage(new TextComponentString(result.getDescription()));
|
||||
player.sendMessage(new TextComponentString(result.getDescription()));
|
||||
} else {
|
||||
heldItem.stackSize--;
|
||||
heldItem.shrink(1);
|
||||
}
|
||||
} else {
|
||||
super.openGui(player, heldItem);
|
||||
@@ -60,13 +56,13 @@ public class TileMailbox extends TileBase {
|
||||
}
|
||||
|
||||
/* MAIL HANDLING */
|
||||
public IInventory getOrCreateMailInventory(World world, @Nonnull GameProfile playerProfile) {
|
||||
public IInventory getOrCreateMailInventory(World world, GameProfile playerProfile) {
|
||||
if (world.isRemote) {
|
||||
return getInternalInventory();
|
||||
}
|
||||
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(playerProfile);
|
||||
return PostRegistry.getOrCreatePOBox(worldObj, address);
|
||||
return PostRegistry.getOrCreatePOBox(world, address);
|
||||
}
|
||||
|
||||
private IPostalState tryDispatchLetter(ItemStack letterStack) {
|
||||
@@ -74,7 +70,7 @@ public class TileMailbox extends TileBase {
|
||||
IPostalState result;
|
||||
|
||||
if (letter != null) {
|
||||
result = PostManager.postRegistry.getPostOffice(worldObj).lodgeLetter(worldObj, letterStack, true);
|
||||
result = PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, letterStack, true);
|
||||
} else {
|
||||
result = EnumDeliveryState.NOT_MAILABLE;
|
||||
}
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.tiles;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.mail.IStamps;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
@@ -22,6 +18,9 @@ import forestry.core.utils.InventoryUtil;
|
||||
import forestry.mail.gui.ContainerStampCollector;
|
||||
import forestry.mail.gui.GuiStampCollector;
|
||||
import forestry.mail.inventory.InventoryStampCollector;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class TileStampCollector extends TileBase implements IInventory {
|
||||
public TileStampCollector() {
|
||||
@@ -38,12 +37,12 @@ public class TileStampCollector extends TileBase implements IInventory {
|
||||
ItemStack stamp = null;
|
||||
|
||||
IInventoryAdapter inventory = getInternalInventory();
|
||||
if (inventory.getStackInSlot(InventoryStampCollector.SLOT_FILTER) == null) {
|
||||
stamp = PostManager.postRegistry.getPostOffice(worldObj).getAnyStamp(1);
|
||||
if (inventory.getStackInSlot(InventoryStampCollector.SLOT_FILTER).isEmpty()) {
|
||||
stamp = PostManager.postRegistry.getPostOffice(world).getAnyStamp(1);
|
||||
} else {
|
||||
ItemStack filter = inventory.getStackInSlot(InventoryStampCollector.SLOT_FILTER);
|
||||
if (filter.getItem() instanceof IStamps) {
|
||||
stamp = PostManager.postRegistry.getPostOffice(worldObj).getAnyStamp(((IStamps) filter.getItem()).getPostage(filter), 1);
|
||||
stamp = PostManager.postRegistry.getPostOffice(world).getAnyStamp(((IStamps) filter.getItem()).getPostage(filter), 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,15 +13,7 @@ package forestry.mail.tiles;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import forestry.core.owner.OwnerHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.IStamps;
|
||||
@@ -29,8 +21,10 @@ import forestry.api.mail.PostManager;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.gui.GuiHandler;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import forestry.core.owner.OwnerHandler;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.TileBase;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
@@ -42,6 +36,11 @@ import forestry.mail.gui.GuiTradeName;
|
||||
import forestry.mail.gui.GuiTrader;
|
||||
import forestry.mail.inventory.InventoryTradeStation;
|
||||
import forestry.mail.network.packets.PacketTraderAddressResponse;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class TileTrader extends TileBase implements IOwnedTile {
|
||||
private final OwnerHandler ownerHandler = new OwnerHandler();
|
||||
@@ -67,7 +66,7 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
@Override
|
||||
public void onRemoval() {
|
||||
if (isLinked()) {
|
||||
PostManager.postRegistry.deleteTradeStation(worldObj, address);
|
||||
PostManager.postRegistry.deleteTradeStation(world, address);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,11 +76,10 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound = super.writeToNBT(nbttagcompound);
|
||||
|
||||
if (address != null) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
address.writeToNBT(nbt);
|
||||
nbttagcompound.setTag("address", nbt);
|
||||
}
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
address.writeToNBT(nbt);
|
||||
nbttagcompound.setTag("address", nbt);
|
||||
|
||||
ownerHandler.writeToNBT(nbttagcompound);
|
||||
return nbttagcompound;
|
||||
}
|
||||
@@ -99,24 +97,18 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
/* NETWORK */
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
public void writeData(PacketBufferForestry data) {
|
||||
super.writeData(data);
|
||||
ownerHandler.writeData(data);
|
||||
String addressName = null;
|
||||
if (address != null) {
|
||||
addressName = address.getName();
|
||||
}
|
||||
if (addressName == null) {
|
||||
addressName = "";
|
||||
}
|
||||
data.writeUTF(addressName);
|
||||
String addressName = address.getName();
|
||||
data.writeString(addressName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
ownerHandler.readData(data);
|
||||
String addressName = data.readUTF();
|
||||
String addressName = data.readString();
|
||||
if (!addressName.isEmpty()) {
|
||||
address = PostManager.postRegistry.getMailAddress(addressName);
|
||||
}
|
||||
@@ -142,13 +134,13 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
|
||||
IInventory inventory = getInternalInventory();
|
||||
ItemStack tradeGood = inventory.getStackInSlot(TradeStation.SLOT_TRADEGOOD);
|
||||
errorLogic.setCondition(tradeGood == null, EnumErrorCode.NO_TRADE);
|
||||
errorLogic.setCondition(tradeGood.isEmpty(), EnumErrorCode.NO_TRADE);
|
||||
|
||||
boolean hasRequest = hasItemCount(TradeStation.SLOT_EXCHANGE_1, TradeStation.SLOT_EXCHANGE_COUNT, null, 1);
|
||||
boolean hasRequest = hasItemCount(TradeStation.SLOT_EXCHANGE_1, TradeStation.SLOT_EXCHANGE_COUNT, ItemStack.EMPTY, 1);
|
||||
errorLogic.setCondition(!hasRequest, EnumErrorCode.NO_TRADE);
|
||||
|
||||
if (tradeGood != null) {
|
||||
boolean hasSupplies = hasItemCount(TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT, tradeGood, tradeGood.stackSize);
|
||||
if (!tradeGood.isEmpty()) {
|
||||
boolean hasSupplies = hasItemCount(TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT, tradeGood, tradeGood.getCount());
|
||||
errorLogic.setCondition(!hasSupplies, EnumErrorCode.NO_SUPPLIES);
|
||||
}
|
||||
|
||||
@@ -160,7 +152,7 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
|
||||
/* STATE INFORMATION */
|
||||
public boolean isLinked() {
|
||||
if (address == null || !address.isValid()) {
|
||||
if (!address.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -179,11 +171,11 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
IInventory tradeInventory = this.getInternalInventory();
|
||||
for (int i = startSlot; i < startSlot + countSlots; i++) {
|
||||
ItemStack itemInSlot = tradeInventory.getStackInSlot(i);
|
||||
if (itemInSlot == null) {
|
||||
if (itemInSlot.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (item == null || ItemStackUtil.isIdenticalItem(itemInSlot, item)) {
|
||||
count += itemInSlot.stackSize;
|
||||
if (item.isEmpty() || ItemStackUtil.isIdenticalItem(itemInSlot, item)) {
|
||||
count += itemInSlot.getCount();
|
||||
}
|
||||
if (count >= itemCount) {
|
||||
return true;
|
||||
@@ -204,12 +196,12 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
IInventory tradeInventory = this.getInternalInventory();
|
||||
for (int i = startSlot; i < startSlot + countSlots; i++) {
|
||||
ItemStack itemInSlot = tradeInventory.getStackInSlot(i);
|
||||
if (itemInSlot == null) {
|
||||
total += 64;
|
||||
if (itemInSlot.isEmpty()) {
|
||||
total += tradeInventory.getInventoryStackLimit();
|
||||
} else {
|
||||
total += itemInSlot.getMaxStackSize();
|
||||
if (item == null || ItemStackUtil.isIdenticalItem(itemInSlot, item)) {
|
||||
count += itemInSlot.stackSize;
|
||||
if (item.isEmpty() || ItemStackUtil.isIdenticalItem(itemInSlot, item)) {
|
||||
count += itemInSlot.getCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,14 +216,14 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
public boolean hasInputBufMin(float percentage) {
|
||||
IInventory inventory = getInternalInventory();
|
||||
ItemStack tradeGood = inventory.getStackInSlot(TradeStation.SLOT_TRADEGOOD);
|
||||
if (tradeGood == null) {
|
||||
if (tradeGood.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return percentOccupied(TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT, tradeGood) > percentage;
|
||||
}
|
||||
|
||||
public boolean hasOutputBufMin(float percentage) {
|
||||
return percentOccupied(TradeStation.SLOT_RECEIVE_BUFFER, TradeStation.SLOT_RECEIVE_BUFFER_COUNT, null) > percentage;
|
||||
return percentOccupied(TradeStation.SLOT_RECEIVE_BUFFER, TradeStation.SLOT_RECEIVE_BUFFER_COUNT, ItemStack.EMPTY) > percentage;
|
||||
}
|
||||
|
||||
public boolean hasPostageMin(int postage) {
|
||||
@@ -241,16 +233,13 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
IInventory tradeInventory = this.getInternalInventory();
|
||||
for (int i = TradeStation.SLOT_STAMPS_1; i < TradeStation.SLOT_STAMPS_1 + TradeStation.SLOT_STAMPS_COUNT; i++) {
|
||||
ItemStack stamp = tradeInventory.getStackInSlot(i);
|
||||
if (stamp == null) {
|
||||
continue;
|
||||
}
|
||||
if (!(stamp.getItem() instanceof IStamps)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
posted += ((IStamps) stamp.getItem()).getPostage(stamp).getValue() * stamp.stackSize;
|
||||
if (posted >= postage) {
|
||||
return true;
|
||||
if (!stamp.isEmpty()) {
|
||||
if (stamp.getItem() instanceof IStamps) {
|
||||
posted += ((IStamps) stamp.getItem()).getPostage(stamp).getValue() * stamp.getCount();
|
||||
if (posted >= postage) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,12 +256,10 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
setAddress(address);
|
||||
|
||||
IMailAddress newAddress = getAddress();
|
||||
if (newAddress != null) {
|
||||
String newAddressName = newAddress.getName();
|
||||
if (newAddressName != null && newAddressName.equals(addressName)) {
|
||||
PacketTraderAddressResponse packetResponse = new PacketTraderAddressResponse(this, addressName);
|
||||
Proxies.net.sendNetworkPacket(packetResponse, worldObj);
|
||||
}
|
||||
String newAddressName = newAddress.getName();
|
||||
if (newAddressName.equals(addressName)) {
|
||||
PacketTraderAddressResponse packetResponse = new PacketTraderAddressResponse(this, addressName);
|
||||
Proxies.net.sendNetworkPacket(packetResponse, pos, world);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,26 +269,24 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
}
|
||||
|
||||
private void setAddress(IMailAddress address) {
|
||||
if (address == null) {
|
||||
throw new NullPointerException("address must not be null");
|
||||
}
|
||||
Preconditions.checkNotNull(address, "address must not be null");
|
||||
|
||||
if (this.address != null && this.address.isValid() && this.address.equals(address)) {
|
||||
if (this.address.isValid() && this.address.equals(address)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
if (!world.isRemote) {
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
|
||||
boolean hasValidTradeAddress = PostManager.postRegistry.isValidTradeAddress(worldObj, address);
|
||||
boolean hasValidTradeAddress = PostManager.postRegistry.isValidTradeAddress(world, address);
|
||||
errorLogic.setCondition(!hasValidTradeAddress, EnumErrorCode.NOT_ALPHANUMERIC);
|
||||
|
||||
boolean hasUniqueTradeAddress = PostManager.postRegistry.isAvailableTradeAddress(worldObj, address);
|
||||
boolean hasUniqueTradeAddress = PostManager.postRegistry.isAvailableTradeAddress(world, address);
|
||||
errorLogic.setCondition(!hasUniqueTradeAddress, EnumErrorCode.NOT_UNIQUE);
|
||||
|
||||
if (hasValidTradeAddress & hasUniqueTradeAddress) {
|
||||
this.address = address;
|
||||
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerHandler().getOwner(), address);
|
||||
PostManager.postRegistry.getOrCreateTradeStation(world, getOwnerHandler().getOwner(), address);
|
||||
}
|
||||
} else {
|
||||
this.address = address;
|
||||
@@ -311,11 +296,11 @@ public class TileTrader extends TileBase implements IOwnedTile {
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
// Handle client side
|
||||
if (worldObj.isRemote || !address.isValid()) {
|
||||
if (world.isRemote || !address.isValid()) {
|
||||
return super.getInternalInventory();
|
||||
}
|
||||
|
||||
return (TradeStation) PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerHandler().getOwner(), address);
|
||||
return (TradeStation) PostManager.postRegistry.getOrCreateTradeStation(world, getOwnerHandler().getOwner(), address);
|
||||
}
|
||||
|
||||
// TODO: Buildcraft for 1.9
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail.tiles;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.mail.triggers;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
Reference in new issue
Block a user