mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-26 06:43:05 +00:00
Close #477 Auto-Format code with new formatting settings
This commit is contained in:
1 parent
8e92d16320
commit
5b8b0c78b0
763 files changed
+13174
-8868
No files matched your search
@@ -4,7 +4,7 @@
|
||||
* 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
|
||||
******************************************************************************/
|
||||
@@ -53,16 +53,20 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
ArrayList<Integer> slots = new ArrayList<Integer>();
|
||||
|
||||
for (int i = SLOT_LETTERS_1; i < SLOT_LETTERS_1 + SLOT_LETTERS_COUNT; i++)
|
||||
for (int i = SLOT_LETTERS_1; i < SLOT_LETTERS_1 + SLOT_LETTERS_COUNT; i++) {
|
||||
slots.add(i);
|
||||
for (int i = SLOT_STAMPS_1; i < SLOT_STAMPS_1 + SLOT_STAMPS_COUNT; i++)
|
||||
}
|
||||
for (int i = SLOT_STAMPS_1; i < SLOT_STAMPS_1 + SLOT_STAMPS_COUNT; i++) {
|
||||
slots.add(i);
|
||||
for (int i = SLOT_SEND_BUFFER; i < SLOT_SEND_BUFFER + SLOT_SEND_BUFFER_COUNT; i++)
|
||||
}
|
||||
for (int i = SLOT_SEND_BUFFER; i < SLOT_SEND_BUFFER + SLOT_SEND_BUFFER_COUNT; i++) {
|
||||
slots.add(i);
|
||||
}
|
||||
|
||||
int[] slotsInt = new int[slots.size()];
|
||||
for (int i = 0; i < slots.size(); i++)
|
||||
for (int i = 0; i < slots.size(); i++) {
|
||||
slotsInt[i] = slots.get(i);
|
||||
}
|
||||
|
||||
return slotsInt;
|
||||
}
|
||||
@@ -77,8 +81,9 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
if (GuiUtil.isIndexInRange(slotIndex, SLOT_SEND_BUFFER, SLOT_SEND_BUFFER_COUNT)) {
|
||||
for (int i = 0; i < SLOT_TRADEGOOD_COUNT; i++) {
|
||||
ItemStack tradeGood = getStackInSlot(SLOT_TRADEGOOD + i);
|
||||
if (StackUtils.isIdenticalItem(tradeGood, itemStack))
|
||||
if (StackUtils.isIdenticalItem(tradeGood, itemStack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else if (GuiUtil.isIndexInRange(slotIndex, SLOT_LETTERS_1, SLOT_LETTERS_COUNT)) {
|
||||
@@ -203,14 +208,17 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
// Virtual trade stations are always ready for service.
|
||||
if (!isVirtual()) {
|
||||
// Will assume that the owner should get a notice.
|
||||
if (!hasPaper(2))
|
||||
if (!hasPaper(2)) {
|
||||
state = EnumStationState.INSUFFICIENT_PAPER;
|
||||
|
||||
if (!canPayPostage(3))
|
||||
}
|
||||
|
||||
if (!canPayPostage(3)) {
|
||||
state = EnumStationState.INSUFFICIENT_STAMPS;
|
||||
|
||||
if (countFillableOrders(1, inventory.getStackInSlot(SLOT_TRADEGOOD)) <= 0)
|
||||
}
|
||||
|
||||
if (countFillableOrders(1, inventory.getStackInSlot(SLOT_TRADEGOOD)) <= 0) {
|
||||
state = EnumStationState.INSUFFICIENT_TRADE_GOOD;
|
||||
}
|
||||
}
|
||||
|
||||
return new TradeStationInfo(address, owner, inventory.getStackInSlot(SLOT_TRADEGOOD), condensedRequired, state);
|
||||
@@ -224,33 +232,39 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
ILetter letter = PostManager.postRegistry.getLetter(letterstack);
|
||||
|
||||
if (!isVirtual() && !hasPaper(sendOwnerNotice ? 2 : 1))
|
||||
if (!isVirtual() && !hasPaper(sendOwnerNotice ? 2 : 1)) {
|
||||
return EnumStationState.INSUFFICIENT_PAPER;
|
||||
}
|
||||
|
||||
int ordersToFill = StackUtils.containsSets(InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT), letter.getAttachments());
|
||||
|
||||
// Not a single match.
|
||||
if (ordersToFill <= 0)
|
||||
if (ordersToFill <= 0) {
|
||||
return EnumStationState.INSUFFICIENT_OFFER;
|
||||
}
|
||||
|
||||
if (!isVirtual()) {
|
||||
int fillable = countFillableOrders(ordersToFill, inventory.getStackInSlot(SLOT_TRADEGOOD));
|
||||
|
||||
// Nothing can be filled.
|
||||
if (fillable <= 0)
|
||||
if (fillable <= 0) {
|
||||
return EnumStationState.INSUFFICIENT_TRADE_GOOD;
|
||||
}
|
||||
|
||||
if (fillable < ordersToFill)
|
||||
if (fillable < ordersToFill) {
|
||||
ordersToFill = fillable;
|
||||
}
|
||||
|
||||
// Check for sufficient output buffer
|
||||
int storable = countStorablePayment(ordersToFill, InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT));
|
||||
|
||||
if (storable <= 0)
|
||||
if (storable <= 0) {
|
||||
return EnumStationState.INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
if (storable < ordersToFill)
|
||||
if (storable < ordersToFill) {
|
||||
ordersToFill = storable;
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare the letter
|
||||
@@ -263,15 +277,18 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
// Check for necessary postage
|
||||
int requiredPostage = mail.requiredPostage();
|
||||
if (!isVirtual())
|
||||
if (!canPayPostage(requiredPostage + (sendOwnerNotice ? 1 : 0)))
|
||||
if (!isVirtual()) {
|
||||
if (!canPayPostage(requiredPostage + (sendOwnerNotice ? 1 : 0))) {
|
||||
return EnumStationState.INSUFFICIENT_STAMPS;
|
||||
}
|
||||
}
|
||||
|
||||
// Attach necessary postage
|
||||
int[] stampCount = getPostage(requiredPostage, isVirtual());
|
||||
for (int i = 0; i < stampCount.length; i++) {
|
||||
if (stampCount[i] > 0)
|
||||
if (stampCount[i] > 0) {
|
||||
mail.addStamps(ForestryItem.stamps.getItemStack(stampCount[i], EnumPostage.values()[i].ordinal() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Send the letter
|
||||
@@ -290,8 +307,9 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
// Store received items
|
||||
for (int i = 0; i < ordersToFill; i++) {
|
||||
for (ItemStack stack : InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)) {
|
||||
if (stack == null)
|
||||
if (stack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
InvTools.tryAddStack(inventory, stack.copy(), SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, false);
|
||||
}
|
||||
@@ -310,14 +328,14 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
confirm.setText(ordersToFill + " order(s) from " + letter.getSender().getName() + " were filled.");
|
||||
confirm.addStamps(ForestryItem.stamps.getItemStack(1, EnumPostage.P_1.ordinal() - 1));
|
||||
confirm.writeToNBT(nbttagcompound);
|
||||
|
||||
|
||||
ItemStack confirmstack = ForestryItem.letters.getItemStack(1, ItemLetter.encodeMeta(1, ItemLetter.getType(confirm)));
|
||||
confirmstack.setTagCompound(nbttagcompound);
|
||||
|
||||
PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, confirmstack, doLodge);
|
||||
|
||||
removePaper();
|
||||
removeStamps(new int[]{0,1});
|
||||
removeStamps(new int[]{0, 1});
|
||||
}
|
||||
|
||||
markDirty();
|
||||
@@ -328,15 +346,17 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
/* TRADE LOGIC */
|
||||
private int countFillableOrders(int max, ItemStack tradegood) {
|
||||
|
||||
if (tradegood == null)
|
||||
if (tradegood == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// How many orders are fillable?
|
||||
int itemCount = 0;
|
||||
|
||||
for (ItemStack stack : InvTools.getStacks(inventory, SLOT_SEND_BUFFER, SLOT_SEND_BUFFER_COUNT)) {
|
||||
if (stack != null && stack.isItemEqual(tradegood) && ItemStack.areItemStackTagsEqual(stack, tradegood))
|
||||
if (stack != null && stack.isItemEqual(tradegood) && ItemStack.areItemStackTagsEqual(stack, tradegood)) {
|
||||
itemCount += stack.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) Math.floor(itemCount / tradegood.stackSize);
|
||||
@@ -344,7 +364,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
public boolean canReceivePayment() {
|
||||
InventoryAdapter test = inventory.copy();
|
||||
ItemStack [] payment = InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT);
|
||||
ItemStack[] payment = InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT);
|
||||
|
||||
return InvTools.tryAddStacksCopy(test, payment, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true);
|
||||
}
|
||||
@@ -355,10 +375,11 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < max; i++) {
|
||||
if (InvTools.tryAddStacksCopy(test, exchange, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true))
|
||||
if (InvTools.tryAddStacksCopy(test, exchange, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true)) {
|
||||
count++;
|
||||
else
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
@@ -370,20 +391,24 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
int toRemove = inventory.getStackInSlot(SLOT_TRADEGOOD).stackSize;
|
||||
for (int i = SLOT_SEND_BUFFER; i < SLOT_SEND_BUFFER + SLOT_SEND_BUFFER_COUNT; i++) {
|
||||
ItemStack buffer = inventory.getStackInSlot(i);
|
||||
if (buffer == null)
|
||||
if (buffer == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!buffer.isItemEqual(inventory.getStackInSlot(SLOT_TRADEGOOD)))
|
||||
if (!buffer.isItemEqual(inventory.getStackInSlot(SLOT_TRADEGOOD))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ItemStack.areItemStackTagsEqual(buffer, inventory.getStackInSlot(SLOT_TRADEGOOD)))
|
||||
if (!ItemStack.areItemStackTagsEqual(buffer, inventory.getStackInSlot(SLOT_TRADEGOOD))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack decrease = inventory.decrStackSize(i, toRemove);
|
||||
toRemove -= decrease.stackSize;
|
||||
|
||||
if (toRemove <= 0)
|
||||
if (toRemove <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -394,11 +419,13 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
int amountFound = 0;
|
||||
|
||||
for (ItemStack stack : InvTools.getStacks(inventory, SLOT_LETTERS_1, SLOT_LETTERS_COUNT)) {
|
||||
if (stack != null)
|
||||
if (stack != null) {
|
||||
amountFound += stack.stackSize;
|
||||
|
||||
if (amountFound >= amountRequired)
|
||||
}
|
||||
|
||||
if (amountFound >= amountRequired) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -419,16 +446,19 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
int posted = 0;
|
||||
|
||||
for (ItemStack stamp : InvTools.getStacks(inventory, SLOT_STAMPS_1, SLOT_STAMPS_COUNT)) {
|
||||
if (stamp == null)
|
||||
continue;
|
||||
|
||||
if (!(stamp.getItem() instanceof IStamps))
|
||||
if (stamp == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
posted += ((IStamps)stamp.getItem()).getPostage(stamp).getValue() * stamp.stackSize;
|
||||
|
||||
if (posted >= postage)
|
||||
if (!(stamp.getItem() instanceof IStamps)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
posted += ((IStamps) stamp.getItem()).getPostage(stamp).getValue() * stamp.stackSize;
|
||||
|
||||
if (posted >= postage) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -438,20 +468,24 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
int[] stamps = new int[EnumPostage.values().length];
|
||||
|
||||
for (int i = EnumPostage.values().length - 1; i > 0; i--) {
|
||||
if (postage <= 0)
|
||||
if (postage <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
EnumPostage postValue = EnumPostage.values()[i];
|
||||
|
||||
if (postValue.getValue() > postage)
|
||||
if (postValue.getValue() > postage) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int num = 99;
|
||||
if (!virtual)
|
||||
if (!virtual) {
|
||||
num = getNumStamps(postValue);
|
||||
}
|
||||
int max = (int) Math.floor(postage / postValue.getValue());
|
||||
if (max < num)
|
||||
if (max < num) {
|
||||
num = max;
|
||||
}
|
||||
|
||||
stamps[i] = num;
|
||||
postage -= num * postValue.getValue();
|
||||
@@ -463,13 +497,16 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
private int getNumStamps(EnumPostage postage) {
|
||||
int count = 0;
|
||||
for (ItemStack stamp : InvTools.getStacks(inventory, SLOT_STAMPS_1, SLOT_STAMPS_COUNT)) {
|
||||
if (stamp == null)
|
||||
if (stamp == null) {
|
||||
continue;
|
||||
if (!(stamp.getItem() instanceof IStamps))
|
||||
}
|
||||
if (!(stamp.getItem() instanceof IStamps)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (((IStamps) stamp.getItem()).getPostage(stamp) == postage)
|
||||
if (((IStamps) stamp.getItem()).getPostage(stamp) == postage) {
|
||||
count += stamp.stackSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -479,19 +516,23 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
private void removeStamps(int[] stampCount) {
|
||||
for (int i = 1; i < stampCount.length; i++) {
|
||||
|
||||
if (stampCount[i] <= 0)
|
||||
if (stampCount[i] <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = SLOT_STAMPS_1; j < SLOT_STAMPS_1 + SLOT_STAMPS_COUNT; j++) {
|
||||
if (stampCount[i] <= 0)
|
||||
if (stampCount[i] <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack stamp = inventory.getStackInSlot(j);
|
||||
if (stamp == null)
|
||||
if (stamp == null) {
|
||||
continue;
|
||||
|
||||
if (!(stamp.getItem() instanceof IStamps))
|
||||
}
|
||||
|
||||
if (!(stamp.getItem() instanceof IStamps)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (((IStamps) stamp.getItem()).getPostage(stamp) == EnumPostage.values()[i]) {
|
||||
ItemStack decrease = inventory.decrStackSize(j, stampCount[i]);
|
||||
@@ -507,8 +548,9 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
// 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)
|
||||
if (attachments[i] != null) {
|
||||
pool[i] = attachments[i].copy();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove stuff until we are only left with the remnants
|
||||
@@ -518,10 +560,12 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
for (ItemStack req : condensedRequired) {
|
||||
for (int j = 0; j < pool.length; j++) {
|
||||
ItemStack pol = pool[j];
|
||||
if (pol == null)
|
||||
if (pol == null) {
|
||||
continue;
|
||||
if (!pol.isItemEqual(req))
|
||||
}
|
||||
if (!pol.isItemEqual(req)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (req.stackSize >= pol.stackSize) {
|
||||
req.stackSize -= pol.stackSize;
|
||||
@@ -535,8 +579,9 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
}
|
||||
|
||||
for (ItemStack stack : pool) {
|
||||
if (stack != null)
|
||||
if (stack != null) {
|
||||
surplus.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
return surplus.toArray(new ItemStack[surplus.size()]);
|
||||
|
||||
Reference in new issue
Block a user