mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 23:13:21 +00:00
Merge branch 'master' of https://github.com/SleepyTrousers/EnderIO.git
This commit is contained in:
commit
068339925f
5 files changed
+56
-66
No files matched your search
@@ -14,7 +14,6 @@ import crazypants.enderio.conduit.item.NetworkedInventory.Target;
|
||||
import crazypants.enderio.conduit.item.filter.IItemFilter;
|
||||
import crazypants.enderio.machine.invpanel.server.InventoryDatabaseServer;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IItemConduit> {
|
||||
|
||||
@@ -180,7 +179,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
for (Target t : source.sendPriority) {
|
||||
IItemFilter f = t.inv.con.getOutputFilter(t.inv.conDir);
|
||||
if(input == null || f == null || f.doesItemPassFilter(t.inv, input)) {
|
||||
String s = Lang.localize(t.inv.getInventory().getInventoryName(), false) + " " + t.inv.location.chatString() + " Distance [" + t.distance + "] ";
|
||||
String s = t.inv.getLocalizedInventoryName() + " " + t.inv.location.chatString() + " Distance [" + t.distance + "] ";
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
@@ -197,7 +196,7 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IIt
|
||||
if(inv.hasTarget(con, dir)) {
|
||||
IItemFilter f = inv.con.getInputFilter(inv.conDir);
|
||||
if(input == null || f == null || f.doesItemPassFilter(inv, input)) {
|
||||
result.add(Lang.localize(inv.getInventory().getInventoryName(), false) + " " + inv.location.chatString());
|
||||
result.add(inv.getLocalizedInventoryName() + " " + inv.location.chatString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.conduit.ConnectionMode;
|
||||
@@ -391,6 +392,17 @@ public class NetworkedInventory {
|
||||
this.inventorySide = inventorySide;
|
||||
}
|
||||
|
||||
public String getLocalizedInventoryName() {
|
||||
String inventoryName = getInventory().getInventoryName();
|
||||
if(inventoryName == null) {
|
||||
return "null";
|
||||
} else {
|
||||
// don't use Lang.localize as that passes the localized string to
|
||||
// String.format which might crash when it contains formatting specifiers
|
||||
return StatCollector.translateToLocal(inventoryName);
|
||||
}
|
||||
}
|
||||
|
||||
static class Target implements Comparable<Target> {
|
||||
NetworkedInventory inv;
|
||||
int distance;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ContainerCrafter extends AbstractMachineContainer {
|
||||
if(refStack == null || itemStack == null) {
|
||||
return false;
|
||||
}
|
||||
return refStack.isItemEqual(itemStack);
|
||||
return TileCrafter.compareDamageable(itemStack, refStack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package crazypants.enderio.machine.crafter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -20,17 +18,6 @@ public class DummyCraftingGrid implements IInventory {
|
||||
return inv[9];
|
||||
}
|
||||
|
||||
public void copyRequiredInputs(List<ItemStack> required) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack is = inv[i];
|
||||
if(is != null) {
|
||||
ItemStack copy = is.copy();
|
||||
copy.stackSize = 1;
|
||||
required.add(copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inv.length;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
|
||||
|
||||
DummyCraftingGrid craftingGrid = new DummyCraftingGrid();
|
||||
|
||||
private List<ItemStack> containerItems;
|
||||
private final List<ItemStack> containerItems;
|
||||
|
||||
private boolean bufferStacks = true;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
|
||||
if(!slotDefinition.isInputSlot(slot)) {
|
||||
return false;
|
||||
}
|
||||
return craftingGrid.inv[slot] != null && craftingGrid.inv[slot].isItemEqual(itemstack);
|
||||
return craftingGrid.inv[slot] != null && compareDamageable(itemstack, craftingGrid.inv[slot]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,10 +99,7 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
|
||||
return false;
|
||||
}
|
||||
|
||||
List<ItemStack> required = new ArrayList<ItemStack>();
|
||||
craftingGrid.copyRequiredInputs(required);
|
||||
if(hasRequiredInput(required)) {
|
||||
craftRecipe();
|
||||
if(craftRecipe()) {
|
||||
int used = Math.min(getEnergyStored(), Config.crafterRfPerCraft);
|
||||
setEnergyStored(getEnergyStored() - used);
|
||||
}
|
||||
@@ -133,10 +130,20 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
|
||||
}
|
||||
}
|
||||
|
||||
static boolean compareDamageable(ItemStack stack, ItemStack req) {
|
||||
if(stack.isItemEqual(req)) {
|
||||
return true;
|
||||
}
|
||||
if(stack.isItemStackDamageable() && stack.getItem() == req.getItem()) {
|
||||
return stack.getItemDamage() < stack.getMaxDamage();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final UUID uuid = UUID.fromString("9b381cae-3c95-4a64-b958-1e25b0a4c790");
|
||||
private static final GameProfile DUMMY_PROFILE = new GameProfile(uuid, "[EioCrafter]");
|
||||
|
||||
private void craftRecipe() {
|
||||
private boolean craftRecipe() {
|
||||
|
||||
// (1) Find the items to craft with and put a copy into a temp crafting grid;
|
||||
// also record what was used to destroy it later
|
||||
@@ -147,27 +154,30 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
|
||||
}
|
||||
}, 3, 3);
|
||||
|
||||
ItemStack[] shadowInventory = new ItemStack[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
shadowInventory[i] = inventory[i] == null ? null : inventory[i].copy();
|
||||
}
|
||||
int[] usedItems = new int[9];
|
||||
|
||||
for (int j = 0; j < 9; j++) {
|
||||
ItemStack req = craftingGrid.getStackInSlot(j);
|
||||
for (int i = 0; i < 9 && req != null; i++) {
|
||||
if (shadowInventory[i] != null && shadowInventory[i].stackSize > 0 && shadowInventory[i].isItemEqual(req)) {
|
||||
req = null;
|
||||
shadowInventory[i].stackSize--;
|
||||
ItemStack craftingItem = shadowInventory[i].copy();
|
||||
craftingItem.stackSize = 1;
|
||||
inv.setInventorySlotContents(j, craftingItem);
|
||||
if (req != null) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (inventory[i] != null && inventory[i].stackSize > usedItems[i] && compareDamageable(inventory[i], req)) {
|
||||
req = null;
|
||||
usedItems[i]++;
|
||||
ItemStack craftingItem = inventory[i].copy();
|
||||
craftingItem.stackSize = 1;
|
||||
inv.setInventorySlotContents(j, craftingItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (req != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// (2) Try to craft with the temp grid
|
||||
ItemStack output = CraftingManager.getInstance().findMatchingRecipe(inv, worldObj);
|
||||
|
||||
|
||||
// (3) If we got a result, ...
|
||||
if (output != null) {
|
||||
if (playerInst == null) {
|
||||
@@ -177,7 +187,7 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
|
||||
|
||||
// (3a) ... remove the used up items and ...
|
||||
for (int i = 0; i < 9; i++) {
|
||||
while (shadowInventory[i] != null && inventory[i] != null && shadowInventory[i].stackSize < inventory[i].stackSize) {
|
||||
for (int j = 0; j < usedItems[i] && inventory[i] != null; j++) {
|
||||
setInventorySlotContents(i, eatOneItemForCrafting(inventory[i].copy()));
|
||||
}
|
||||
}
|
||||
@@ -205,14 +215,20 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
|
||||
// Crafting failed. This is not supposed to happen, but if a recipe is nbt-sensitive, it can.
|
||||
// To avoid being stuck in a dead loop, we flush the non-working input items.
|
||||
for (int j = 0; j < 9; j++) {
|
||||
if (shadowInventory[j] != null) {
|
||||
setInventorySlotContents(j, shadowInventory[j].stackSize > 0 ? shadowInventory[j] : null);
|
||||
}
|
||||
if (craftingGrid.getStackInSlot(j) != null) {
|
||||
containerItems.add(craftingGrid.getStackInSlot(j));
|
||||
if (usedItems[j] > 0 && inventory[j] != null) {
|
||||
ItemStack rejected = inventory[j].copy();
|
||||
rejected.stackSize = Math.min(inventory[j].stackSize, usedItems[j]);
|
||||
containerItems.add(rejected);
|
||||
if (inventory[j].stackSize <= usedItems[j]) {
|
||||
inventory[j] = null;
|
||||
} else {
|
||||
inventory[j].stackSize -= usedItems[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private ItemStack eatOneItemForCrafting(ItemStack avail) {
|
||||
@@ -269,30 +285,6 @@ public class TileCrafter extends AbstractPowerConsumerEntity implements IItemBuf
|
||||
return output.getMaxStackSize() >= (inventory[9].stackSize + output.stackSize);
|
||||
}
|
||||
|
||||
private boolean hasRequiredInput(List<ItemStack> required) {
|
||||
List<ItemStack> available = new ArrayList<ItemStack>();
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack is = inventory[i];
|
||||
if(is != null) {
|
||||
available.add(is.copy());
|
||||
}
|
||||
}
|
||||
for (ItemStack req : required) {
|
||||
boolean foundReq = false;
|
||||
for (ItemStack avail : available) {
|
||||
if(req.isItemEqual(avail) && avail.stackSize > 0) {
|
||||
avail.stackSize--;
|
||||
foundReq = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!foundReq) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return bufferStacks ? 64 : 1;
|
||||
|
||||
Reference in new issue
Block a user