mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 04:22:32 +00:00
1 parent
1d1959b535
commit
92460d1d4a
20 files changed
+274
-155
No files matched your search
@@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.mail;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public enum EnumTradeStationState implements IPostalState {
|
||||
OK("for.chat.mail.ok"),
|
||||
INSUFFICIENT_OFFER("for.chat.mail.insufficient.offer"),
|
||||
INSUFFICIENT_TRADE_GOOD("for.chat.mail.insufficient.trade.good"),
|
||||
INSUFFICIENT_BUFFER("for.chat.mail.insufficient.buffer"),
|
||||
INSUFFICIENT_PAPER("for.chat.mail.insufficient.paper"),
|
||||
INSUFFICIENT_STAMPS("for.chat.mail.insufficient.stamps");
|
||||
|
||||
private final String unlocalizedDescription;
|
||||
|
||||
EnumTradeStationState(@Nonnull String unlocalizedDescription) {
|
||||
this.unlocalizedDescription = unlocalizedDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOk() {
|
||||
return this == OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return StatCollector.translateToLocal(unlocalizedDescription);
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,9 @@
|
||||
package forestry.api.mail;
|
||||
|
||||
public interface IPostalState {
|
||||
/** Normal states are OK, error states are not OK */
|
||||
boolean isOk();
|
||||
|
||||
String getIdentifier();
|
||||
|
||||
int ordinal();
|
||||
/** Localized description of the postal state */
|
||||
String getDescription();
|
||||
}
|
||||
@@ -19,6 +19,6 @@ public interface ITradeStation extends ILetterHandler, IInventory {
|
||||
|
||||
boolean isVirtual();
|
||||
|
||||
TradeStationInfo getTradeInfo();
|
||||
ITradeStationInfo getTradeInfo();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.mail;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
public interface ITradeStationInfo {
|
||||
IMailAddress getAddress();
|
||||
|
||||
GameProfile getOwner();
|
||||
|
||||
ItemStack getTradegood();
|
||||
|
||||
ItemStack[] getRequired();
|
||||
|
||||
EnumTradeStationState getState();
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.mail;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
public class TradeStationInfo {
|
||||
public final IMailAddress address;
|
||||
public final GameProfile owner;
|
||||
public final ItemStack tradegood;
|
||||
public final ItemStack[] required;
|
||||
public final IPostalState state;
|
||||
|
||||
public TradeStationInfo(IMailAddress address, GameProfile owner, ItemStack tradegood, ItemStack[] required, IPostalState state) {
|
||||
if (!address.isTrader()) {
|
||||
throw new IllegalArgumentException("TradeStation address must be a trader");
|
||||
}
|
||||
this.address = address;
|
||||
this.owner = owner;
|
||||
this.tradegood = tradegood;
|
||||
this.required = required;
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,24 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import java.util.Locale;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.mail.IPostalState;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
public enum EnumDeliveryState implements IPostalState {
|
||||
OK, NO_MAILBOX, NOT_MAILABLE, ALREADY_MAILED, NOT_POSTPAID, MAILBOX_FULL, RESPONSE_NOT_MAILABLE;
|
||||
OK("for.chat.mail.ok"),
|
||||
NO_MAILBOX("for.chat.mail.no.mailbox"),
|
||||
NOT_MAILABLE("for.chat.mail.not.mailable"),
|
||||
ALREADY_MAILED("for.chat.mail.already.mailed"),
|
||||
NOT_POSTPAID("for.chat.mail.not.postpaid"),
|
||||
MAILBOX_FULL("for.chat.mail.mailbox.full");
|
||||
|
||||
private final String unlocalizedDescription;
|
||||
|
||||
EnumDeliveryState(@Nonnull String unlocalizedDescription) {
|
||||
this.unlocalizedDescription = unlocalizedDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOk() {
|
||||
@@ -23,7 +35,7 @@ public enum EnumDeliveryState implements IPostalState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.toString().toLowerCase(Locale.ENGLISH);
|
||||
public String getDescription() {
|
||||
return Translator.translateToLocal(unlocalizedDescription);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import forestry.api.mail.IPostalState;
|
||||
|
||||
public enum EnumStationState implements IPostalState {
|
||||
OK, INSUFFICIENT_OFFER, INSUFFICIENT_TRADE_GOOD, INSUFFICIENT_BUFFER, INSUFFICIENT_PAPER, INSUFFICIENT_STAMPS;
|
||||
|
||||
@Override
|
||||
public boolean isOk() {
|
||||
return this == OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return this.toString().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ package forestry.mail;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -28,6 +29,7 @@ import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
public class Letter implements ILetter {
|
||||
private static final Random rand = new Random();
|
||||
public static final short SLOT_ATTACHMENT_1 = 0;
|
||||
public static final short SLOT_ATTACHMENT_COUNT = 18;
|
||||
public static final short SLOT_POSTAGE_1 = 18;
|
||||
@@ -40,10 +42,12 @@ public class Letter implements ILetter {
|
||||
|
||||
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.uid = String.valueOf(rand.nextInt());
|
||||
}
|
||||
|
||||
public Letter(@Nonnull NBTTagCompound nbttagcompound) {
|
||||
@@ -57,7 +61,7 @@ public class Letter implements ILetter {
|
||||
}
|
||||
|
||||
this.text = nbttagcompound.getString("TXT");
|
||||
|
||||
this.uid = nbttagcompound.getString("UID");
|
||||
this.inventory.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -78,7 +82,7 @@ public class Letter implements ILetter {
|
||||
}
|
||||
|
||||
nbttagcompound.setString("TXT", this.text);
|
||||
|
||||
nbttagcompound.setString("UID", this.uid);
|
||||
inventory.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
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) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOk() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return Translator.translateToLocalFormatted("for.chat.mail.response.not.mailable.format", state.getDescription());
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,13 @@ import net.minecraft.world.WorldSavedData;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.EnumPostage;
|
||||
import forestry.api.mail.EnumTradeStationState;
|
||||
import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.IPostalState;
|
||||
import forestry.api.mail.IStamps;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
@@ -144,21 +144,21 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
ItemStack[] condensedRequired = ItemStackUtil.condenseStacks(InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT));
|
||||
|
||||
// Set current state
|
||||
EnumStationState state = EnumStationState.OK;
|
||||
EnumTradeStationState state = EnumTradeStationState.OK;
|
||||
|
||||
// Virtual trade stations are always ready for service.
|
||||
if (!isVirtual()) {
|
||||
// Will assume that the owner should get a notice.
|
||||
if (!hasPaper(2)) {
|
||||
state = EnumStationState.INSUFFICIENT_PAPER;
|
||||
state = EnumTradeStationState.INSUFFICIENT_PAPER;
|
||||
}
|
||||
|
||||
if (!canPayPostage(3)) {
|
||||
state = EnumStationState.INSUFFICIENT_STAMPS;
|
||||
state = EnumTradeStationState.INSUFFICIENT_STAMPS;
|
||||
}
|
||||
|
||||
if (countFillableOrders(1, inventory.getStackInSlot(SLOT_TRADEGOOD)) <= 0) {
|
||||
state = EnumStationState.INSUFFICIENT_TRADE_GOOD;
|
||||
state = EnumTradeStationState.INSUFFICIENT_TRADE_GOOD;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,14 +174,14 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
ILetter letter = PostManager.postRegistry.getLetter(letterstack);
|
||||
|
||||
if (!isVirtual() && !hasPaper(sendOwnerNotice ? 2 : 1)) {
|
||||
return EnumStationState.INSUFFICIENT_PAPER;
|
||||
return EnumTradeStationState.INSUFFICIENT_PAPER;
|
||||
}
|
||||
|
||||
int ordersToFillCount = ItemStackUtil.containsSets(InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT), letter.getAttachments());
|
||||
|
||||
// Not a single match.
|
||||
if (ordersToFillCount <= 0) {
|
||||
return EnumStationState.INSUFFICIENT_OFFER;
|
||||
return EnumTradeStationState.INSUFFICIENT_OFFER;
|
||||
}
|
||||
|
||||
if (!isVirtual()) {
|
||||
@@ -189,7 +189,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
// Nothing can be filled.
|
||||
if (fillable <= 0) {
|
||||
return EnumStationState.INSUFFICIENT_TRADE_GOOD;
|
||||
return EnumTradeStationState.INSUFFICIENT_TRADE_GOOD;
|
||||
}
|
||||
|
||||
if (fillable < ordersToFillCount) {
|
||||
@@ -200,7 +200,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
int storable = countStorablePayment(ordersToFillCount, InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT));
|
||||
|
||||
if (storable <= 0) {
|
||||
return EnumStationState.INSUFFICIENT_BUFFER;
|
||||
return EnumTradeStationState.INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
if (storable < ordersToFillCount) {
|
||||
@@ -220,7 +220,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
int requiredPostage = mail.requiredPostage();
|
||||
if (!isVirtual()) {
|
||||
if (!canPayPostage(requiredPostage + (sendOwnerNotice ? 1 : 0))) {
|
||||
return EnumStationState.INSUFFICIENT_STAMPS;
|
||||
return EnumTradeStationState.INSUFFICIENT_STAMPS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
IPostalState responseState = PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, mailstack, doLodge);
|
||||
|
||||
if (!responseState.isOk()) {
|
||||
return EnumDeliveryState.RESPONSE_NOT_MAILABLE;
|
||||
return new ResponseNotMailable(responseState);
|
||||
}
|
||||
|
||||
// Store received items
|
||||
@@ -422,31 +422,46 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
return false;
|
||||
}
|
||||
|
||||
private int[] getPostage(int postage, boolean virtual) {
|
||||
private int[] getPostage(final int postageRequired, boolean virtual) {
|
||||
int[] stamps = new int[EnumPostage.values().length];
|
||||
int postageRemaining = postageRequired;
|
||||
|
||||
for (int i = EnumPostage.values().length - 1; i > 0; i--) {
|
||||
if (postage <= 0) {
|
||||
if (postageRemaining <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
EnumPostage postValue = EnumPostage.values()[i];
|
||||
|
||||
if (postValue.getValue() > postage) {
|
||||
if (postValue.getValue() > postageRemaining) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int num = 99;
|
||||
if (!virtual) {
|
||||
num = getNumStamps(postValue);
|
||||
}
|
||||
int max = (int) Math.floor(postage / postValue.getValue());
|
||||
int num = virtual ? 99 : getNumStamps(postValue);
|
||||
int max = (int) Math.floor(postageRemaining / postValue.getValue());
|
||||
if (max < num) {
|
||||
num = max;
|
||||
}
|
||||
|
||||
stamps[i] = num;
|
||||
postage -= num * postValue.getValue();
|
||||
postageRemaining -= num * postValue.getValue();
|
||||
}
|
||||
|
||||
// use larger stamps if exact change isn't available
|
||||
if (postageRemaining > 0) {
|
||||
for (int i = 0; i < EnumPostage.values().length; i++) {
|
||||
EnumPostage postValue = EnumPostage.values()[i];
|
||||
|
||||
if (postValue.getValue() >= postageRequired) {
|
||||
stamps = new int[EnumPostage.values().length];
|
||||
|
||||
int num = virtual ? 99 : getNumStamps(postValue);
|
||||
if (num > 0) {
|
||||
stamps[i] = 1;
|
||||
return stamps;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stamps;
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.EnumTradeStationState;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.ITradeStationInfo;
|
||||
|
||||
public class TradeStationInfo implements ITradeStationInfo {
|
||||
private final IMailAddress address;
|
||||
private final GameProfile owner;
|
||||
private final ItemStack tradegood;
|
||||
private final ItemStack[] required;
|
||||
private final EnumTradeStationState state;
|
||||
|
||||
public TradeStationInfo(IMailAddress address, GameProfile owner, ItemStack tradegood, ItemStack[] required, EnumTradeStationState state) {
|
||||
if (!address.isTrader()) {
|
||||
throw new IllegalArgumentException("TradeStation address must be a trader");
|
||||
}
|
||||
this.address = address;
|
||||
this.owner = owner;
|
||||
this.tradegood = tradegood;
|
||||
this.required = required;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMailAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getTradegood() {
|
||||
return tradegood;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumTradeStationState getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.ITradeStationInfo;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.core.commands.CommandHelpers;
|
||||
import forestry.core.commands.SubCommand;
|
||||
import forestry.core.utils.StringUtil;
|
||||
@@ -57,22 +57,22 @@ public class CommandMail extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private static String makeTradeListEntry(TradeStationInfo info) {
|
||||
EnumChatFormatting formatting = info.state.isOk() ? EnumChatFormatting.GREEN : EnumChatFormatting.RED;
|
||||
private static String makeTradeListEntry(ITradeStationInfo info) {
|
||||
EnumChatFormatting formatting = info.getState().isOk() ? EnumChatFormatting.GREEN : EnumChatFormatting.RED;
|
||||
|
||||
String tradegood = "[ ? ]";
|
||||
if (info.tradegood != null) {
|
||||
tradegood = info.tradegood.stackSize + "x" + info.tradegood.getDisplayName();
|
||||
if (info.getTradegood() != null) {
|
||||
tradegood = info.getTradegood().stackSize + "x" + info.getTradegood().getDisplayName();
|
||||
}
|
||||
String demand = "[ ? ]";
|
||||
if (info.required.length > 0) {
|
||||
if (info.getRequired().length > 0) {
|
||||
demand = "";
|
||||
for (ItemStack dmd : info.required) {
|
||||
for (ItemStack dmd : info.getRequired()) {
|
||||
demand = StringUtil.append(", ", demand, dmd.stackSize + "x" + dmd.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
return String.format("%s%-12s | %-20s | %s", formatting, info.address.getName(), tradegood, demand);
|
||||
return String.format("%s%-12s | %-20s | %s", formatting, info.getAddress().getName(), tradegood, demand);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,16 +23,16 @@ import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.EnumTradeStationState;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.IPostOffice;
|
||||
import forestry.api.mail.IPostalState;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.ITradeStationInfo;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.core.gui.IGuiSelectable;
|
||||
import forestry.core.network.packets.PacketGuiSelectRequest;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.EnumStationState;
|
||||
import forestry.mail.network.packets.PacketLetterInfoResponse;
|
||||
|
||||
public class ContainerCatalogue extends Container implements IGuiSelectable, ILetterInfoReceiver {
|
||||
@@ -40,7 +40,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
private final EntityPlayer player;
|
||||
private final List<ITradeStation> stations = new ArrayList<>();
|
||||
|
||||
private TradeStationInfo currentTrade = null;
|
||||
private ITradeStationInfo currentTrade = null;
|
||||
|
||||
private int stationIndex = 0;
|
||||
|
||||
@@ -54,14 +54,14 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
private static final List<Set<IPostalState>> FILTERS = new ArrayList<>();
|
||||
|
||||
static {
|
||||
EnumSet<EnumStationState> all = EnumSet.allOf(EnumStationState.class);
|
||||
EnumSet<EnumStationState> online = EnumSet.of(EnumStationState.OK);
|
||||
EnumSet<EnumStationState> offline = EnumSet.copyOf(all);
|
||||
EnumSet<EnumTradeStationState> all = EnumSet.allOf(EnumTradeStationState.class);
|
||||
EnumSet<EnumTradeStationState> online = EnumSet.of(EnumTradeStationState.OK);
|
||||
EnumSet<EnumTradeStationState> offline = EnumSet.copyOf(all);
|
||||
offline.removeAll(online);
|
||||
|
||||
FILTERS.add(Collections.<IPostalState>unmodifiableSet(all));
|
||||
FILTERS.add(Collections.<IPostalState>unmodifiableSet(online));
|
||||
FILTERS.add(Collections.<IPostalState>unmodifiableSet(offline));
|
||||
FILTERS.add(Collections.unmodifiableSet(all));
|
||||
FILTERS.add(Collections.unmodifiableSet(online));
|
||||
FILTERS.add(Collections.unmodifiableSet(offline));
|
||||
}
|
||||
|
||||
public ContainerCatalogue(EntityPlayer player) {
|
||||
@@ -91,10 +91,10 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
Map<IMailAddress, ITradeStation> tradeStations = postOffice.getActiveTradeStations(player.worldObj);
|
||||
|
||||
for (ITradeStation station : tradeStations.values()) {
|
||||
TradeStationInfo info = station.getTradeInfo();
|
||||
ITradeStationInfo info = station.getTradeInfo();
|
||||
|
||||
// Filter out any trade stations which do not actually offer anything.
|
||||
if (info.tradegood != null && FILTERS.get(currentFilter).contains(info.state)) {
|
||||
if (info.getTradegood() != null && FILTERS.get(currentFilter).contains(info.getState())) {
|
||||
stations.add(station);
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
return;
|
||||
}
|
||||
|
||||
if (stations.size() == 0) {
|
||||
if (stations.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
stationIndex = (stationIndex + 1) % stations.size();
|
||||
@@ -122,7 +122,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
return;
|
||||
}
|
||||
|
||||
if (stations.size() == 0) {
|
||||
if (stations.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
stationIndex = (stationIndex - 1 + stations.size()) % stations.size();
|
||||
@@ -166,11 +166,11 @@ public class ContainerCatalogue extends Container implements IGuiSelectable, ILe
|
||||
setTradeInfo(packet.tradeInfo);
|
||||
}
|
||||
|
||||
public TradeStationInfo getTradeInfo() {
|
||||
public ITradeStationInfo getTradeInfo() {
|
||||
return currentTrade;
|
||||
}
|
||||
|
||||
private void setTradeInfo(TradeStationInfo info) {
|
||||
private void setTradeInfo(ITradeStationInfo info) {
|
||||
currentTrade = info;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.ITradeStationInfo;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.network.packets.PacketString;
|
||||
@@ -38,7 +38,7 @@ import forestry.mail.network.packets.PacketLetterTextSet;
|
||||
public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter> implements ILetterInfoReceiver {
|
||||
|
||||
private EnumAddressee carrierType = EnumAddressee.PLAYER;
|
||||
private TradeStationInfo tradeInfo = null;
|
||||
private ITradeStationInfo tradeInfo = null;
|
||||
|
||||
public ContainerLetter(EntityPlayer player, ItemInventoryLetter inventory) {
|
||||
super(inventory, player.inventory, 17, 145);
|
||||
@@ -205,16 +205,16 @@ public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter>
|
||||
}
|
||||
}
|
||||
|
||||
public TradeStationInfo getTradeInfo() {
|
||||
public ITradeStationInfo getTradeInfo() {
|
||||
return this.tradeInfo;
|
||||
}
|
||||
|
||||
private void setTradeInfo(TradeStationInfo info) {
|
||||
private void setTradeInfo(ITradeStationInfo info) {
|
||||
this.tradeInfo = info;
|
||||
if (tradeInfo == null) {
|
||||
getLetter().setRecipient(null);
|
||||
} else {
|
||||
getLetter().setRecipient(tradeInfo.address);
|
||||
getLetter().setRecipient(tradeInfo.getAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.api.mail.ITradeStationInfo;
|
||||
import forestry.core.config.SessionVars;
|
||||
import forestry.core.gui.GuiForestry;
|
||||
import forestry.core.gui.widgets.ItemStackWidget;
|
||||
@@ -76,11 +76,11 @@ public class GuiCatalogue extends GuiForestry<ContainerCatalogue, IInventory> {
|
||||
|
||||
clearTradeInfoWidgets();
|
||||
|
||||
TradeStationInfo tradeInfo = container.getTradeInfo();
|
||||
ITradeStationInfo tradeInfo = container.getTradeInfo();
|
||||
|
||||
if (tradeInfo != null) {
|
||||
drawTradePreview(tradeInfo, guiLeft + 38, guiTop + 30);
|
||||
buttonUse.enabled = tradeInfo.state.isOk();
|
||||
buttonUse.enabled = tradeInfo.getState().isOk();
|
||||
} else {
|
||||
drawNoTrade(guiLeft + 38, guiTop + 30);
|
||||
buttonUse.enabled = false;
|
||||
@@ -93,25 +93,25 @@ public class GuiCatalogue extends GuiForestry<ContainerCatalogue, IInventory> {
|
||||
fontRendererObj.drawSplitString(Translator.translateToLocal("for.gui.mail.notrades"), x, y + 18, 119, fontColor.get("gui.book"));
|
||||
}
|
||||
|
||||
private void drawTradePreview(TradeStationInfo tradeInfo, int x, int y) {
|
||||
private void drawTradePreview(ITradeStationInfo tradeInfo, int x, int y) {
|
||||
|
||||
fontRendererObj.drawString(boldUnderline + tradeInfo.address.getName(), x, y, fontColor.get("gui.book"));
|
||||
fontRendererObj.drawString(boldUnderline + tradeInfo.getAddress().getName(), x, y, fontColor.get("gui.book"));
|
||||
|
||||
fontRendererObj.drawString(String.format(Translator.translateToLocal("for.gui.mail.willtrade"), tradeInfo.owner.getName()), x, y + 18, fontColor.get("gui.book"));
|
||||
fontRendererObj.drawString(String.format(Translator.translateToLocal("for.gui.mail.willtrade"), tradeInfo.getOwner().getName()), x, y + 18, fontColor.get("gui.book"));
|
||||
|
||||
addTradeInfoWidget(new ItemStackWidget(widgetManager, x - guiLeft, y - guiTop + 28, tradeInfo.tradegood));
|
||||
addTradeInfoWidget(new ItemStackWidget(widgetManager, x - guiLeft, y - guiTop + 28, tradeInfo.getTradegood()));
|
||||
|
||||
fontRendererObj.drawString(Translator.translateToLocal("for.gui.mail.tradefor"), x, y + 46, fontColor.get("gui.book"));
|
||||
|
||||
for (int i = 0; i < tradeInfo.required.length; i++) {
|
||||
ItemStack itemStack = tradeInfo.required[i];
|
||||
for (int i = 0; i < tradeInfo.getRequired().length; i++) {
|
||||
ItemStack itemStack = tradeInfo.getRequired()[i];
|
||||
addTradeInfoWidget(new ItemStackWidget(widgetManager, x - guiLeft + i * 18, y - guiTop + 56, itemStack));
|
||||
}
|
||||
|
||||
if (tradeInfo.state.isOk()) {
|
||||
fontRendererObj.drawSplitString(EnumChatFormatting.DARK_GREEN + Translator.translateToLocal("for.chat.mail." + tradeInfo.state.getIdentifier()), x, y + 82, 119, fontColor.get("gui.book"));
|
||||
if (tradeInfo.getState().isOk()) {
|
||||
fontRendererObj.drawSplitString(EnumChatFormatting.DARK_GREEN + tradeInfo.getState().getDescription(), x, y + 82, 119, fontColor.get("gui.book"));
|
||||
} else {
|
||||
fontRendererObj.drawSplitString(EnumChatFormatting.DARK_RED + Translator.translateToLocal("for.chat.mail." + tradeInfo.state.getIdentifier()), x, y + 82, 119, fontColor.get("gui.book"));
|
||||
fontRendererObj.drawSplitString(EnumChatFormatting.DARK_RED + tradeInfo.getState().getDescription(), x, y + 82, 119, fontColor.get("gui.book"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,9 +143,9 @@ public class GuiCatalogue extends GuiForestry<ContainerCatalogue, IInventory> {
|
||||
container.cycleFilter();
|
||||
break;
|
||||
case 5:
|
||||
TradeStationInfo info = container.getTradeInfo();
|
||||
ITradeStationInfo info = container.getTradeInfo();
|
||||
if (info != null) {
|
||||
SessionVars.setStringVar("mail.letter.recipient", info.address.getName());
|
||||
SessionVars.setStringVar("mail.letter.recipient", info.getAddress().getName());
|
||||
SessionVars.setStringVar("mail.letter.addressee", EnumAddressee.TRADER.toString());
|
||||
}
|
||||
mc.thePlayer.closeScreen();
|
||||
|
||||
@@ -163,26 +163,26 @@ public class GuiLetter extends GuiForestry<ContainerLetter, ItemInventoryLetter>
|
||||
|
||||
String infoString = null;
|
||||
if (container.getTradeInfo() == null) {
|
||||
infoString = "for.gui.mail.notrader";
|
||||
} else if (container.getTradeInfo().tradegood == null) {
|
||||
infoString = "for.gui.mail.nothingtotrade";
|
||||
} else if (!container.getTradeInfo().state.isOk()) {
|
||||
infoString = "for.chat.mail." + container.getTradeInfo().state.getIdentifier();
|
||||
infoString = Translator.translateToLocal("for.gui.mail.no.trader");
|
||||
} else if (container.getTradeInfo().getTradegood() == null) {
|
||||
infoString = Translator.translateToLocal("for.gui.mail.nothing.to.trade");
|
||||
} else if (!container.getTradeInfo().getState().isOk()) {
|
||||
infoString = container.getTradeInfo().getState().getDescription();
|
||||
}
|
||||
|
||||
if (infoString != null) {
|
||||
fontRendererObj.drawSplitString(Translator.translateToLocal(infoString), guiLeft + x, guiTop + y, 119, fontColor.get("gui.mail.lettertext"));
|
||||
fontRendererObj.drawSplitString(infoString, guiLeft + x, guiTop + y, 119, fontColor.get("gui.mail.lettertext"));
|
||||
return;
|
||||
}
|
||||
|
||||
fontRendererObj.drawString(Translator.translateToLocal("for.gui.mail.pleasesend"), guiLeft + x, guiTop + y, fontColor.get("gui.mail.lettertext"));
|
||||
|
||||
addTradeInfoWidget(new ItemStackWidget(widgetManager, x, y + 10, container.getTradeInfo().tradegood));
|
||||
addTradeInfoWidget(new ItemStackWidget(widgetManager, x, y + 10, container.getTradeInfo().getTradegood()));
|
||||
|
||||
fontRendererObj.drawString(Translator.translateToLocal("for.gui.mail.foreveryattached"), guiLeft + x, guiTop + y + 28, fontColor.get("gui.mail.lettertext"));
|
||||
|
||||
for (int i = 0; i < container.getTradeInfo().required.length; i++) {
|
||||
addTradeInfoWidget(new ItemStackWidget(widgetManager, x + i * 18, y + 38, container.getTradeInfo().required[i]));
|
||||
for (int i = 0; i < container.getTradeInfo().getRequired().length; i++) {
|
||||
addTradeInfoWidget(new ItemStackWidget(widgetManager, x + i * 18, y + 38, container.getTradeInfo().getRequired()[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,27 +20,28 @@ import net.minecraft.item.ItemStack;
|
||||
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.api.mail.TradeStationInfo;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.mail.EnumStationState;
|
||||
import forestry.mail.TradeStationInfo;
|
||||
import forestry.mail.gui.ILetterInfoReceiver;
|
||||
|
||||
public class PacketLetterInfoResponse extends ForestryPacket implements IForestryPacketClient {
|
||||
|
||||
public EnumAddressee type;
|
||||
public TradeStationInfo tradeInfo;
|
||||
public ITradeStationInfo tradeInfo;
|
||||
public IMailAddress address;
|
||||
|
||||
public PacketLetterInfoResponse() {
|
||||
}
|
||||
|
||||
public PacketLetterInfoResponse(EnumAddressee type, TradeStationInfo info, IMailAddress address) {
|
||||
public PacketLetterInfoResponse(EnumAddressee type, ITradeStationInfo info, IMailAddress address) {
|
||||
this.type = type;
|
||||
if (type == EnumAddressee.TRADER) {
|
||||
this.tradeInfo = info;
|
||||
@@ -88,16 +89,16 @@ public class PacketLetterInfoResponse extends ForestryPacket implements IForestr
|
||||
|
||||
data.writeShort(0);
|
||||
|
||||
data.writeUTF(tradeInfo.address.getName());
|
||||
data.writeUTF(tradeInfo.getAddress().getName());
|
||||
|
||||
data.writeLong(tradeInfo.owner.getId().getMostSignificantBits());
|
||||
data.writeLong(tradeInfo.owner.getId().getLeastSignificantBits());
|
||||
data.writeUTF(tradeInfo.owner.getName());
|
||||
data.writeLong(tradeInfo.getOwner().getId().getMostSignificantBits());
|
||||
data.writeLong(tradeInfo.getOwner().getId().getLeastSignificantBits());
|
||||
data.writeUTF(tradeInfo.getOwner().getName());
|
||||
|
||||
data.writeItemStack(tradeInfo.tradegood);
|
||||
data.writeItemStacks(tradeInfo.required);
|
||||
data.writeItemStack(tradeInfo.getTradegood());
|
||||
data.writeItemStacks(tradeInfo.getRequired());
|
||||
|
||||
data.writeShort(tradeInfo.state.ordinal());
|
||||
data.writeShort(tradeInfo.getState().ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +130,7 @@ public class PacketLetterInfoResponse extends ForestryPacket implements IForestr
|
||||
tradegood = data.readItemStack();
|
||||
required = data.readItemStacks();
|
||||
|
||||
this.tradeInfo = new TradeStationInfo(address, owner, tradegood, required, EnumStationState.values()[data.readShort()]);
|
||||
this.tradeInfo = new TradeStationInfo(address, owner, tradegood, required, EnumTradeStationState.values()[data.readShort()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class TileMailbox extends TileBase implements IMailContainer {
|
||||
if (PostManager.postRegistry.isLetter(held)) {
|
||||
IPostalState result = this.tryDispatchLetter(held);
|
||||
if (!result.isOk()) {
|
||||
player.addChatMessage(new ChatComponentTranslation("for.chat.mail." + result.getIdentifier()));
|
||||
player.addChatMessage(new ChatComponentText(result.getDescription()));
|
||||
} else {
|
||||
held.stackSize--;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class TileTrader extends TileBase {
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
String address = data.readUTF();
|
||||
if (address.length() > 0) {
|
||||
if (!address.isEmpty()) {
|
||||
this.address = PostManager.postRegistry.getMailAddress(address);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user