mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-15 01:24:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccebafc4b5 | ||
|
|
4708ba94a8 | ||
|
|
141a1493a8 | ||
|
|
b6c93ef188 | ||
|
|
e0fc9cbb64 | ||
|
|
e9e48cea77 | ||
|
|
27b9b7bc57 | ||
|
|
06b1f9fabf | ||
|
|
b00f92ab76 | ||
|
|
83a41d41d3 | ||
|
|
a47fab4579 | ||
|
|
07389fe1dc | ||
|
|
b276c5bb38 | ||
|
|
b630540a26 | ||
|
|
340ba2dc7c | ||
|
|
3e6c8407ff | ||
|
|
87908d2a35 | ||
|
|
a137cf8f12 | ||
|
|
70f710231d | ||
|
|
7a68e04053 | ||
|
|
3c37a81617 |
No files matched your search
@@ -2,4 +2,4 @@ mcversion=1.7.10
|
||||
forgeversion=10.13.3.1370-1.7.10
|
||||
version_major=3
|
||||
version_minor=6
|
||||
version_patch=3
|
||||
version_patch=12
|
||||
@@ -46,6 +46,7 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
private int breedingTime;
|
||||
private int queenWorkCycleThrottle;
|
||||
private IEffectData effectData[] = new IEffectData[2];
|
||||
private ItemStack queenStack;
|
||||
private IBee queen;
|
||||
private IIndividual pollen;
|
||||
private int attemptedPollinations = 0;
|
||||
@@ -309,6 +310,11 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
|
||||
ItemStack queenStack = housing.getQueen();
|
||||
|
||||
if (!ItemStack.areItemStacksEqual(this.queenStack, queenStack)) {
|
||||
this.queen = BeeManager.beeRoot.getMember(queenStack);
|
||||
this.queenStack = queenStack;
|
||||
}
|
||||
|
||||
if (queenStack == null || !ForestryItem.beeQueenGE.isItemEqual(queenStack)) {
|
||||
housingErrorState = EnumErrorCode.NOQUEEN;
|
||||
hasQueen = false;
|
||||
|
||||
@@ -141,10 +141,12 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
|
||||
this.active = active;
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
} else {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
|
||||
if (worldObj != null) {
|
||||
if (worldObj.isRemote) {
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
} else {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
}
|
||||
this.active = active;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
if (worldObj != null && !worldObj.isRemote) {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory,
|
||||
|
||||
this.active = active;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
if (worldObj != null && !worldObj.isRemote) {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised,
|
||||
}
|
||||
this.active = active;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
if (worldObj != null && !worldObj.isRemote) {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,10 @@ public class BeeGenome extends Genome implements IBeeGenome {
|
||||
|
||||
// NBT RETRIEVAL
|
||||
public static IAlleleBeeSpecies getSpecies(ItemStack itemStack) {
|
||||
if (!BeeManager.beeRoot.isMember(itemStack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IAlleleSpecies species = getSpeciesDirectly(itemStack);
|
||||
if (species instanceof IAlleleBeeSpecies) {
|
||||
return (IAlleleBeeSpecies) species;
|
||||
|
||||
@@ -122,7 +122,7 @@ public class BlockArbStairs extends BlockStairs {
|
||||
TileStairs stairs = getStairTile(world, x, y, z);
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
if (stairs == null || stairs.getWoodType() == null) {
|
||||
if (stairs == null) {
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class BlockArbStairs extends BlockStairs {
|
||||
@Override
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
||||
TileStairs stairs = getStairTile(world, x, y, z);
|
||||
if (stairs != null && stairs.getWoodType() != null) {
|
||||
if (stairs != null) {
|
||||
return stairs.getWoodType().getPlankIcon();
|
||||
} else {
|
||||
return WoodType.LARCH.getPlankIcon();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.gadgets;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -25,13 +26,15 @@ import forestry.core.proxy.Proxies;
|
||||
|
||||
public class TileStairs extends TileEntity implements IStreamable {
|
||||
|
||||
private WoodType woodType;
|
||||
@Nonnull
|
||||
private WoodType woodType = WoodType.LARCH;
|
||||
|
||||
@Nonnull
|
||||
public WoodType getWoodType() {
|
||||
return this.woodType;
|
||||
}
|
||||
|
||||
public void setWoodType(WoodType woodType) {
|
||||
public void setWoodType(@Nonnull WoodType woodType) {
|
||||
this.woodType = woodType;
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
@@ -49,10 +52,7 @@ public class TileStairs extends TileEntity implements IStreamable {
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
if (woodType != null) {
|
||||
nbttagcompound.setShort("WT", (short) woodType.ordinal());
|
||||
}
|
||||
nbttagcompound.setShort("WT", (short) woodType.ordinal());
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
|
||||
@@ -46,6 +46,10 @@ public class TreeGenome extends Genome implements ITreeGenome {
|
||||
|
||||
// NBT RETRIEVAL
|
||||
public static IAlleleTreeSpecies getSpecies(ItemStack itemStack) {
|
||||
if (!PluginArboriculture.treeInterface.isMember(itemStack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IAlleleSpecies species = getSpeciesDirectly(itemStack);
|
||||
if (species instanceof IAlleleTreeSpecies) {
|
||||
return (IAlleleTreeSpecies) species;
|
||||
|
||||
@@ -29,7 +29,7 @@ import net.minecraftforge.fluids.IFluidBlock;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.utils.StackUtils;
|
||||
|
||||
@@ -103,36 +103,6 @@ public final class FluidHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void processContainers(StandardTank tank, IInventory inv, int inputSlot, int outputSlot) {
|
||||
processContainers(tank, inv, inputSlot, outputSlot, tank.getFluidType(), true, true);
|
||||
}
|
||||
|
||||
public static void processContainers(StandardTank tank, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, boolean processFilled, boolean processEmpty) {
|
||||
TankManager tankManger = new TankManager();
|
||||
tankManger.add(tank);
|
||||
processContainers(tankManger, inv, inputSlot, outputSlot, fluidToFill, processFilled, processEmpty);
|
||||
}
|
||||
|
||||
public static void processContainers(TankManager tank, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
|
||||
processContainers(tank, inv, inputSlot, outputSlot, fluidToFill, true, true);
|
||||
}
|
||||
|
||||
public static void processContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, boolean processFilled, boolean processEmpty) {
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
|
||||
if (input == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (processFilled && drainContainers(fluidHandler, inv, inputSlot, outputSlot)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (processEmpty && fluidToFill != null) {
|
||||
fillContainers(fluidHandler, inv, inputSlot, outputSlot, fluidToFill);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
|
||||
return fillContainers(fluidHandler, inv, inputSlot, outputSlot, fluidToFill, true);
|
||||
}
|
||||
@@ -161,10 +131,10 @@ public final class FluidHelper {
|
||||
}
|
||||
|
||||
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int slot) {
|
||||
return drainContainers(fluidHandler, inv, slot, slot);
|
||||
return drainContainers(fluidHandler, inv, slot, slot, Defaults.BUCKET_VOLUME);
|
||||
}
|
||||
|
||||
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot) {
|
||||
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, int maxAmount) {
|
||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||
|
||||
@@ -176,36 +146,39 @@ public final class FluidHelper {
|
||||
if (fluidInContainer == null) {
|
||||
return false;
|
||||
}
|
||||
if (fluidInContainer.amount > maxAmount) {
|
||||
fluidInContainer.amount = maxAmount;
|
||||
}
|
||||
|
||||
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
||||
if (used < fluidInContainer.amount) {
|
||||
|
||||
ItemStack drainedItem = getDrainedContainer(input, used);
|
||||
if (ItemStack.areItemStacksEqual(input, drainedItem)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack emptyItem = getEmptyContainer(input);
|
||||
|
||||
if (output != null && emptyItem != null) {
|
||||
if (output != null && drainedItem != null) {
|
||||
if (outputSlot == inputSlot) {
|
||||
if (input.stackSize > 1) {
|
||||
return false;
|
||||
}
|
||||
} else if (!StackUtils.isIdenticalItem(output, emptyItem)) {
|
||||
} else if (!StackUtils.isIdenticalItem(output, drainedItem)) {
|
||||
return false;
|
||||
} else if (output.stackSize + emptyItem.stackSize > output.getMaxStackSize()) {
|
||||
} else if (output.stackSize + drainedItem.stackSize > output.getMaxStackSize()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true);
|
||||
|
||||
if (emptyItem != null) {
|
||||
if (drainedItem != null) {
|
||||
if (outputSlot == inputSlot) {
|
||||
inv.setInventorySlotContents(outputSlot, emptyItem);
|
||||
inv.setInventorySlotContents(outputSlot, drainedItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (output == null) {
|
||||
inv.setInventorySlotContents(outputSlot, emptyItem);
|
||||
inv.setInventorySlotContents(outputSlot, drainedItem);
|
||||
} else {
|
||||
output.stackSize++;
|
||||
}
|
||||
@@ -269,15 +242,6 @@ public final class FluidHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ItemStack getEmptyContainer(ItemStack container) {
|
||||
Item item = container.getItem();
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return item.getContainerItem(container);
|
||||
}
|
||||
|
||||
public static ItemStack getDrainedContainer(ItemStack container, int drainAmount) {
|
||||
if (container == null) {
|
||||
return null;
|
||||
@@ -288,15 +252,20 @@ public final class FluidHelper {
|
||||
}
|
||||
|
||||
Item item = container.getItem();
|
||||
if (item instanceof IFluidContainerItem) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
} else if (item instanceof IFluidContainerItem) {
|
||||
ItemStack drained = container.copy();
|
||||
drained.stackSize = 1;
|
||||
IFluidContainerItem containerItem = (IFluidContainerItem) item;
|
||||
containerItem.drain(drained, drainAmount, true);
|
||||
return drained;
|
||||
} else {
|
||||
if (drainAmount < Defaults.BUCKET_VOLUME) {
|
||||
return container;
|
||||
}
|
||||
return item.getContainerItem(container);
|
||||
}
|
||||
|
||||
return getEmptyContainer(container);
|
||||
}
|
||||
|
||||
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) {
|
||||
|
||||
@@ -172,7 +172,7 @@ public abstract class Engine extends TileBase implements IEnergyConnection, IAct
|
||||
}
|
||||
this.active = active;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
if (worldObj != null && !worldObj.isRemote) {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+14
-4
@@ -51,6 +51,8 @@ import forestry.core.network.PacketItemStackDisplay;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.core.utils.GuiUtil;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
import forestry.plugins.PluginManager;
|
||||
|
||||
public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiquidTankContainer, IItemStackDisplay {
|
||||
|
||||
@@ -159,7 +161,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
}
|
||||
}
|
||||
|
||||
// Look for bees in input slots.
|
||||
// Look for specimens in input slots.
|
||||
IInvSlot slot = getInputSlot();
|
||||
|
||||
boolean noInput = (slot == null);
|
||||
@@ -169,11 +171,19 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
}
|
||||
|
||||
ItemStack inputStack = slot.getStackInSlot();
|
||||
ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(inputStack);
|
||||
if (ersatz != null) {
|
||||
inputStack = ersatz;
|
||||
|
||||
if (PluginManager.Module.ARBORICULTURE.isEnabled() && !PluginArboriculture.treeInterface.isMember(inputStack)) {
|
||||
ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(inputStack);
|
||||
if (ersatz != null) {
|
||||
inputStack = ersatz;
|
||||
}
|
||||
}
|
||||
|
||||
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(inputStack);
|
||||
if (individual == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!individual.isAnalyzed()) {
|
||||
boolean hasHoney = resourceTank.getFluidAmount() >= HONEY_REQUIRED;
|
||||
setErrorCondition(!hasHoney, EnumErrorCode.NORESOURCE);
|
||||
|
||||
@@ -17,22 +17,17 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
import forestry.core.interfaces.ICrafter;
|
||||
import forestry.core.interfaces.ICrafterWorktable;
|
||||
|
||||
public class SlotCrafter extends SlotCrafting {
|
||||
|
||||
private final ICrafter crafter;
|
||||
private final IInventory craftMatrix;
|
||||
private final ICrafterWorktable crafter;
|
||||
|
||||
public SlotCrafter(EntityPlayer player, IInventory craftMatrix, ICrafter crafter, int slot, int xPos, int yPos) {
|
||||
public SlotCrafter(EntityPlayer player, IInventory craftMatrix, ICrafterWorktable crafter, int slot, int xPos, int yPos) {
|
||||
super(player, craftMatrix, craftMatrix, slot, xPos, yPos);
|
||||
this.crafter = crafter;
|
||||
this.craftMatrix = craftMatrix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack par1ItemStack) {
|
||||
return false;
|
||||
this.crafter = crafter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,18 +46,23 @@ public class SlotCrafter extends SlotCrafting {
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return this.crafter.getResult();
|
||||
return crafter.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasStack() {
|
||||
return this.getStack() != null && crafter.canTakeStack(getSlotIndex());
|
||||
return getStack() != null && crafter.canTakeStack(getSlotIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer player, ItemStack itemStack) {
|
||||
if (!crafter.onCraftingStart(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
FMLCommonHandler.instance().firePlayerCraftingEvent(player, itemStack, craftMatrix);
|
||||
this.onCrafting(itemStack, itemStack.stackSize); // handles crafting achievements, maps, and statistics
|
||||
crafter.takenFromSlot(getSlotIndex(), player);
|
||||
this.onCrafting(itemStack); // handles crafting achievements, maps, and statistics
|
||||
|
||||
crafter.onCraftingComplete(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package forestry.core.interfaces;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface ICrafterWorktable {
|
||||
ItemStack getResult();
|
||||
|
||||
boolean canTakeStack(int slotIndex);
|
||||
|
||||
boolean onCraftingStart(EntityPlayer player);
|
||||
|
||||
void onCraftingComplete(EntityPlayer player);
|
||||
}
|
||||
Executable → Regular
+34
-18
@@ -927,33 +927,46 @@ public abstract class InvTools {
|
||||
* If the inventory doesn't have all the required items, returns false without removing anything.
|
||||
* If stowContainer is true, items with containers will have their container stowed.
|
||||
*/
|
||||
public static boolean removeSets(IInventory inventory, int count, ItemStack[] set, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
public static boolean removeSets(IInventory inventory, int count, ItemStack[] set, EntityPlayer player, boolean stowContainer, boolean oreDictionary) {
|
||||
return removeSets(inventory, count, set, 0, inventory.getSizeInventory(), player, stowContainer, oreDictionary, false) != null;
|
||||
}
|
||||
|
||||
ItemStack[] condensedSet = StackUtils.condenseStacks(set, -1, false);
|
||||
public static boolean removeSets(IInventory inventory, int count, ItemStack[] set, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary) {
|
||||
return removeSets(inventory, count, set, firstSlotIndex, slotCount, player, stowContainer, oreDictionary, false) != null;
|
||||
}
|
||||
|
||||
public static ItemStack[] removeSets(IInventory inventory, int count, ItemStack[] set, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
|
||||
ItemStack[] removed = new ItemStack[set.length];
|
||||
ItemStack[] stock = getStacks(inventory, firstSlotIndex, slotCount);
|
||||
if (StackUtils.containsSets(condensedSet, stock, oreDictionary, craftingTools) < count) {
|
||||
return false;
|
||||
|
||||
if (StackUtils.containsSets(set, stock, oreDictionary, craftingTools) < count) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (ItemStack stackToRemove : condensedSet) {
|
||||
for (int i = 0; i < set.length; i++) {
|
||||
if (set[i] == null) {
|
||||
continue;
|
||||
}
|
||||
ItemStack stackToRemove = set[i].copy();
|
||||
stackToRemove.stackSize *= count;
|
||||
|
||||
// try to remove the exact stack first
|
||||
removeStack(inventory, stackToRemove, firstSlotIndex, slotCount, player, stowContainer, false, false);
|
||||
|
||||
// remove crafting equivalents next
|
||||
if (stackToRemove.stackSize > 0) {
|
||||
removeStack(inventory, stackToRemove, firstSlotIndex, slotCount, player, stowContainer, oreDictionary, craftingTools);
|
||||
ItemStack removedStack = removeStack(inventory, stackToRemove, firstSlotIndex, slotCount, player, stowContainer, false, false);
|
||||
if (removedStack == null) {
|
||||
// remove crafting equivalents next
|
||||
removedStack = removeStack(inventory, stackToRemove, firstSlotIndex, slotCount, player, stowContainer, oreDictionary, craftingTools);
|
||||
}
|
||||
|
||||
removed[i] = removedStack;
|
||||
}
|
||||
return true;
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private Helper for removeSetsFromInventory. Assumes removal is possible.
|
||||
*/
|
||||
private static void removeStack(IInventory inventory, ItemStack stackToRemove, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
private static ItemStack removeStack(IInventory inventory, ItemStack stackToRemove, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
for (int j = firstSlotIndex; j < firstSlotIndex + slotCount; j++) {
|
||||
ItemStack stackInSlot = inventory.getStackInSlot(j);
|
||||
if (stackInSlot == null) {
|
||||
@@ -972,9 +985,10 @@ public abstract class InvTools {
|
||||
}
|
||||
|
||||
if (stackToRemove.stackSize == 0) {
|
||||
return;
|
||||
return removed;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* CONTAINS */
|
||||
@@ -1088,12 +1102,14 @@ public abstract class InvTools {
|
||||
}
|
||||
|
||||
public static boolean tryAddStack(IInventory inventory, ItemStack stack, int startSlot, int slots, boolean all, boolean doAdd) {
|
||||
int added = addStack(inventory, stack, startSlot, slots, doAdd);
|
||||
if (all) {
|
||||
return added == stack.stackSize;
|
||||
} else {
|
||||
return added > 0;
|
||||
int added = addStack(inventory, stack, startSlot, slots, false);
|
||||
boolean success = all ? (added == stack.stackSize) : (added > 0);
|
||||
|
||||
if (success && doAdd) {
|
||||
addStack(inventory, stack, startSlot, slots, true);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public static int addStack(IInventory inventory, ItemStack stack, boolean doAdd) {
|
||||
|
||||
@@ -90,11 +90,7 @@ public class SlotHelper {
|
||||
return shiftToHotbar(inventorySlots, stackInSlot);
|
||||
}
|
||||
} else {
|
||||
boolean shifted = shiftToHotbar(inventorySlots, stackInSlot);
|
||||
if (!shifted) {
|
||||
shifted = shiftToPlayerInventoryNoHotbar(inventorySlots, stackInSlot);
|
||||
}
|
||||
return shifted;
|
||||
return shiftToPlayerInventory(inventorySlots, stackInSlot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,38 +140,31 @@ public class SlotHelper {
|
||||
}
|
||||
|
||||
private static boolean shiftItemStackToRange(List inventorySlots, ItemStack stackToShift, int start, int count) {
|
||||
boolean changed = false;
|
||||
if (stackToShift.isStackable()) {
|
||||
for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < start + count; slotIndex++) {
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
if (stackInSlot != null && StackUtils.isIdenticalItem(stackInSlot, stackToShift)) {
|
||||
int resultingStackSize = stackInSlot.stackSize + stackToShift.stackSize;
|
||||
int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
if (resultingStackSize <= max) {
|
||||
stackToShift.stackSize = 0;
|
||||
stackInSlot.stackSize = resultingStackSize;
|
||||
slot.onSlotChanged();
|
||||
changed = true;
|
||||
} else if (stackInSlot.stackSize < max) {
|
||||
stackToShift.stackSize -= max - stackInSlot.stackSize;
|
||||
stackInSlot.stackSize = max;
|
||||
slot.onSlotChanged();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean changed = shiftItemStackToRangeMerge(inventorySlots, stackToShift, start, count);
|
||||
changed |= shiftItemStackToRangeOpenSlots(inventorySlots, stackToShift, start, count);
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static boolean shiftItemStackToRangeMerge(List inventorySlots, ItemStack stackToShift, int start, int count) {
|
||||
if (stackToShift == null || !stackToShift.isStackable() || stackToShift.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (stackToShift.stackSize > 0) {
|
||||
for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < start + count; slotIndex++) {
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
if (stackInSlot == null) {
|
||||
int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
stackInSlot = stackToShift.copy();
|
||||
stackInSlot.stackSize = Math.min(stackToShift.stackSize, max);
|
||||
stackToShift.stackSize -= stackInSlot.stackSize;
|
||||
slot.putStack(stackInSlot);
|
||||
|
||||
boolean changed = false;
|
||||
for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < start + count; slotIndex++) {
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
if (stackInSlot != null && StackUtils.isIdenticalItem(stackInSlot, stackToShift)) {
|
||||
int resultingStackSize = stackInSlot.stackSize + stackToShift.stackSize;
|
||||
int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
if (resultingStackSize <= max) {
|
||||
stackToShift.stackSize = 0;
|
||||
stackInSlot.stackSize = resultingStackSize;
|
||||
slot.onSlotChanged();
|
||||
changed = true;
|
||||
} else if (stackInSlot.stackSize < max) {
|
||||
stackToShift.stackSize -= max - stackInSlot.stackSize;
|
||||
stackInSlot.stackSize = max;
|
||||
slot.onSlotChanged();
|
||||
changed = true;
|
||||
}
|
||||
@@ -184,6 +173,28 @@ public class SlotHelper {
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static boolean shiftItemStackToRangeOpenSlots(List inventorySlots, ItemStack stackToShift, int start, int count) {
|
||||
if (stackToShift == null || stackToShift.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < start + count; slotIndex++) {
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
if (stackInSlot == null) {
|
||||
int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
stackInSlot = stackToShift.copy();
|
||||
stackInSlot.stackSize = Math.min(stackToShift.stackSize, max);
|
||||
stackToShift.stackSize -= stackInSlot.stackSize;
|
||||
slot.putStack(stackInSlot);
|
||||
slot.onSlotChanged();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static final int playerInventorySize = 9 * 4;
|
||||
private static final int playerHotbarSize = 9;
|
||||
|
||||
@@ -195,6 +206,19 @@ public class SlotHelper {
|
||||
return GuiUtil.isIndexInRange(slotIndex, playerInventorySize - playerHotbarSize, playerInventorySize);
|
||||
}
|
||||
|
||||
private static boolean shiftToPlayerInventory(List inventorySlots, ItemStack stackInSlot) {
|
||||
int playerHotbarStart = playerInventorySize - playerHotbarSize;
|
||||
|
||||
// try to merge with existing stacks, hotbar first
|
||||
boolean shifted = shiftItemStackToRangeMerge(inventorySlots, stackInSlot, playerHotbarStart, playerHotbarSize);
|
||||
shifted |= shiftItemStackToRangeMerge(inventorySlots, stackInSlot, 0, playerHotbarStart);
|
||||
|
||||
// shift to open slots, hotbar first
|
||||
shifted |= shiftItemStackToRangeOpenSlots(inventorySlots, stackInSlot, playerHotbarStart, playerHotbarSize);
|
||||
shifted |= shiftItemStackToRangeOpenSlots(inventorySlots, stackInSlot, 0, playerHotbarStart);
|
||||
return shifted;
|
||||
}
|
||||
|
||||
private static boolean shiftToPlayerInventoryNoHotbar(List inventorySlots, ItemStack stackInSlot) {
|
||||
int playerHotbarStart = playerInventorySize - playerHotbarSize;
|
||||
return shiftItemStackToRange(inventorySlots, stackInSlot, 0, playerHotbarStart);
|
||||
|
||||
@@ -116,54 +116,6 @@ public class StackUtils {
|
||||
}
|
||||
|
||||
return added;
|
||||
|
||||
}
|
||||
|
||||
public static int addToInventory(ItemStack itemstack, IInventory inventory, boolean doAdd, int slot1, int count) {
|
||||
|
||||
int added = 0;
|
||||
|
||||
for (int i = slot1; i < slot1 + count; i++) {
|
||||
ItemStack inventoryStack = inventory.getStackInSlot(i);
|
||||
|
||||
// Grab those free slots
|
||||
if (inventoryStack == null) {
|
||||
if (doAdd) {
|
||||
inventory.setInventorySlotContents(i, itemstack.copy());
|
||||
}
|
||||
return itemstack.stackSize;
|
||||
}
|
||||
|
||||
// Already full
|
||||
if (inventoryStack.stackSize >= inventoryStack.getMaxStackSize()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Not same type
|
||||
if (!inventoryStack.isItemEqual(itemstack)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int space = inventoryStack.getMaxStackSize() - inventoryStack.stackSize;
|
||||
|
||||
// Enough space to add all
|
||||
if (space > itemstack.stackSize - added) {
|
||||
if (doAdd) {
|
||||
inventoryStack.stackSize += itemstack.stackSize;
|
||||
}
|
||||
return itemstack.stackSize;
|
||||
// Only part can be added
|
||||
} else {
|
||||
if (doAdd) {
|
||||
inventoryStack.stackSize = inventoryStack.getMaxStackSize();
|
||||
}
|
||||
added += space;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return added;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,18 +141,6 @@ public class StackUtils {
|
||||
temp.stackSize = 0;
|
||||
}
|
||||
|
||||
public static boolean freeSpaceInStack(ItemStack stack, int maxSize) {
|
||||
if (stack == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stack.stackSize >= maxSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a split stack of the specified amount, preserving NBT data,
|
||||
* without decreasing the source stack.
|
||||
@@ -215,14 +155,7 @@ public class StackUtils {
|
||||
}
|
||||
|
||||
public static ItemStack[] condenseStacks(ItemStack[] stacks) {
|
||||
return condenseStacks(stacks, -1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxCountedPerStack The maximum stacksize counted in a single stack. -1 for unlimited.
|
||||
*/
|
||||
public static ItemStack[] condenseStacks(ItemStack[] stacks, int maxCountedPerStack, boolean craftingEquivalency) {
|
||||
ArrayList<ItemStack> condensed = new ArrayList<ItemStack>();
|
||||
List<ItemStack> condensed = new ArrayList<ItemStack>();
|
||||
|
||||
for (ItemStack stack : stacks) {
|
||||
if (stack == null) {
|
||||
@@ -234,17 +167,14 @@ public class StackUtils {
|
||||
|
||||
boolean matched = false;
|
||||
for (ItemStack cached : condensed) {
|
||||
if ((cached.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(cached, stack)) || (craftingEquivalency && isCraftingEquivalent(cached, stack, true, false))) {
|
||||
cached.stackSize += maxCountedPerStack > 0 && stack.stackSize > maxCountedPerStack ? maxCountedPerStack : stack.stackSize;
|
||||
if ((cached.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(cached, stack))) {
|
||||
cached.stackSize += stack.stackSize;
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matched) {
|
||||
ItemStack cached = stack.copy();
|
||||
if (maxCountedPerStack > 0) {
|
||||
cached.stackSize = maxCountedPerStack;
|
||||
}
|
||||
condensed.add(cached);
|
||||
}
|
||||
|
||||
@@ -273,34 +203,31 @@ public class StackUtils {
|
||||
* Counts how many full sets are contained in the passed stock
|
||||
*/
|
||||
public static int containsSets(ItemStack[] set, ItemStack[] stock, boolean oreDictionary, boolean craftingTools) {
|
||||
int count = 0;
|
||||
int totalSets = 0;
|
||||
|
||||
ItemStack[] condensedRequired = StackUtils.condenseStacks(set, -1, oreDictionary);
|
||||
ItemStack[] condensedOffered = StackUtils.condenseStacks(stock, -1, oreDictionary);
|
||||
ItemStack[] condensedRequired = StackUtils.condenseStacks(set);
|
||||
ItemStack[] condensedOffered = StackUtils.condenseStacks(stock);
|
||||
|
||||
for (ItemStack req : condensedRequired) {
|
||||
|
||||
boolean matched = false;
|
||||
int reqCount = 0;
|
||||
for (ItemStack offer : condensedOffered) {
|
||||
|
||||
if (isCraftingEquivalent(req, offer, oreDictionary, craftingTools)) {
|
||||
|
||||
int stackCount = (int) Math.floor(offer.stackSize / req.stackSize);
|
||||
matched |= (stackCount > 0);
|
||||
|
||||
if (count == 0) {
|
||||
count = stackCount;
|
||||
} else if (count > stackCount) {
|
||||
count = stackCount;
|
||||
}
|
||||
reqCount = Math.max(reqCount, stackCount);
|
||||
}
|
||||
}
|
||||
if (!matched) {
|
||||
|
||||
if (reqCount == 0) {
|
||||
return 0;
|
||||
} else if (totalSets == 0) {
|
||||
totalSets = reqCount;
|
||||
} else if (totalSets > reqCount) {
|
||||
totalSets = reqCount;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
return totalSets;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,6 +268,10 @@ public class StackUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (craftingTools && isCraftingTool(base) && base.getItem() == comparison.getItem()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base.hasTagCompound() && !base.stackTagCompound.hasNoTags()) {
|
||||
if (!ItemStack.areItemStacksEqual(base, comparison)) {
|
||||
return false;
|
||||
@@ -367,21 +298,22 @@ public class StackUtils {
|
||||
}
|
||||
}
|
||||
|
||||
if (craftingTools) {
|
||||
return isThisCraftingTool(base, comparison);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isCraftingTool(ItemStack itemstack) {
|
||||
return itemstack.getItem().hasContainerItem(itemstack)
|
||||
&& itemstack.getItem().isDamageable()
|
||||
&& !itemstack.getItem().doesContainerItemLeaveCraftingGrid(itemstack);
|
||||
}
|
||||
Item item = itemstack.getItem();
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isThisCraftingTool(ItemStack phantom, ItemStack actual) {
|
||||
return isCraftingTool(phantom) && phantom.getItem() == actual.getItem();
|
||||
if (item.hasContainerItem(itemstack)) {
|
||||
if (item.isDamageable() || itemstack.hasTagCompound()) {
|
||||
return !item.doesContainerItemLeaveCraftingGrid(itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void stowContainerItem(ItemStack itemstack, IInventory stowing, int slotIndex, EntityPlayer player) {
|
||||
@@ -439,20 +371,6 @@ public class StackUtils {
|
||||
return created;
|
||||
}
|
||||
|
||||
public static ItemStack consumeItem(ItemStack stack) {
|
||||
if (stack.stackSize == 1) {
|
||||
if (stack.getItem().hasContainerItem(stack)) {
|
||||
return stack.getItem().getContainerItem(stack);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
stack.splitStack(1);
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
public static Block getBlock(ItemStack stack) {
|
||||
Item item = stack.getItem();
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank
|
||||
setInternalInventory(new EngineBronzeInventoryAdapter(this));
|
||||
|
||||
fuelTank = new FilteredTank(Defaults.ENGINE_TANK_CAPACITY, FuelManager.bronzeEngineFuel.keySet());
|
||||
fuelTank.tankMode = StandardTank.TankMode.INPUT;
|
||||
fuelTank.tankMode = StandardTank.TankMode.DEFAULT;
|
||||
heatingTank = new FilteredTank(Defaults.ENGINE_TANK_CAPACITY, FluidRegistry.LAVA);
|
||||
heatingTank.tankMode = StandardTank.TankMode.INPUT;
|
||||
this.tankManager = new TankManager(fuelTank, heatingTank);
|
||||
|
||||
@@ -297,7 +297,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
|
||||
private boolean removeSets(int count, ItemStack[] set) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwner());
|
||||
return InvTools.removeSets(getInternalInventory(), count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true);
|
||||
return InvTools.removeSets(getInternalInventory(), count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true);
|
||||
}
|
||||
|
||||
private boolean tryAddPending() {
|
||||
|
||||
@@ -439,7 +439,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT
|
||||
private boolean removeFromInventory(ItemStack[] set, EntityPlayer player, boolean doRemove) {
|
||||
IInventoryAdapter inventory = getInternalInventory();
|
||||
if (doRemove) {
|
||||
return InvTools.removeSets(inventory, 1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true);
|
||||
return InvTools.removeSets(inventory, 1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true);
|
||||
} else {
|
||||
ItemStack[] stock = InvTools.getStacks(inventory, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
|
||||
return StackUtils.containsSets(set, stock) >= 1;
|
||||
|
||||
Executable → Regular
+13
-5
@@ -76,8 +76,8 @@ public class MachineSqueezer extends TilePowered implements ISidedInventory, ILi
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack[] res) {
|
||||
return StackUtils.containsSets(resources, res, true, true) > 0;
|
||||
public boolean matches(ItemStack[] res, boolean oreDict) {
|
||||
return StackUtils.containsSets(resources, res, oreDict, true) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,8 +104,16 @@ public class MachineSqueezer extends TilePowered implements ISidedInventory, ILi
|
||||
}
|
||||
|
||||
public static Recipe findMatchingRecipe(ItemStack[] items) {
|
||||
// First try to match a specific recipe (without OD)
|
||||
for (Recipe recipe : recipes) {
|
||||
if (recipe.matches(items)) {
|
||||
if (recipe.matches(items, false)) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
// If that fails - try again with oredict support enabled
|
||||
for (Recipe recipe : recipes) {
|
||||
if (recipe.matches(items, true)) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
@@ -118,7 +126,7 @@ public class MachineSqueezer extends TilePowered implements ISidedInventory, ILi
|
||||
return true;
|
||||
}
|
||||
for (ItemStack recipeInput : recipeInputs) {
|
||||
if (StackUtils.isCraftingEquivalent(recipeInput, itemStack)) {
|
||||
if (StackUtils.isCraftingEquivalent(recipeInput, itemStack, true, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -283,7 +291,7 @@ public class MachineSqueezer extends TilePowered implements ISidedInventory, ILi
|
||||
|
||||
private boolean removeResources(ItemStack[] stacks) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwner());
|
||||
return InvTools.removeSets(getInternalInventory(), 1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true, true);
|
||||
return InvTools.removeSets(getInternalInventory(), 1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,12 +19,15 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.interfaces.ICrafter;
|
||||
import forestry.core.interfaces.ICrafterWorktable;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.GuiId;
|
||||
@@ -33,7 +36,7 @@ import forestry.core.utils.GuiUtil;
|
||||
import forestry.core.utils.RecipeUtil;
|
||||
import forestry.factory.recipes.RecipeMemory;
|
||||
|
||||
public class TileWorktable extends TileBase implements ICrafter {
|
||||
public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
|
||||
/* CONSTANTS */
|
||||
public final static int SLOT_CRAFTING_1 = 0;
|
||||
@@ -161,11 +164,6 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
return RecipeUtil.canCraftRecipe(worldObj, recipeItems, recipeOutput, inventory);
|
||||
}
|
||||
|
||||
private boolean removeResources(EntityPlayer player) {
|
||||
ItemStack[] set = InvTools.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
|
||||
return InvTools.removeSets(getInternalInventory(), 1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(int slotIndex) {
|
||||
if (slotIndex == SLOT_CRAFTING_RESULT) {
|
||||
@@ -175,17 +173,50 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack takenFromSlot(int slotIndex, EntityPlayer player) {
|
||||
if (!removeResources(player)) {
|
||||
return null;
|
||||
public boolean onCraftingStart(EntityPlayer player) {
|
||||
ItemStack[] set = InvTools.getStacks(currentRecipe.getMatrix(), SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
|
||||
ItemStack[] removed = InvTools.removeSets(this, 1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, false, true, true);
|
||||
|
||||
if (removed == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < removed.length; i++) {
|
||||
craftingInventory.setInventorySlotContents(i, removed[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftingComplete(EntityPlayer player) {
|
||||
IInventory craftingInventory = getCraftingInventory();
|
||||
for (int i = 0; i < craftingInventory.getSizeInventory(); ++i) {
|
||||
ItemStack itemStack = craftingInventory.getStackInSlot(i);
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!itemStack.getItem().hasContainerItem(itemStack)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack container = itemStack.getItem().getContainerItem(itemStack);
|
||||
|
||||
if (container != null && container.isItemStackDamageable() && container.getItemDamage() > container.getMaxDamage()) {
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, container));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!InvTools.tryAddStack(this, container, true)) {
|
||||
player.dropPlayerItemWithRandomChoice(container, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (Proxies.common.isSimulating(worldObj)) {
|
||||
memorized.memorizeRecipe(worldObj, currentRecipe, currentCrafting);
|
||||
}
|
||||
|
||||
updateCraftResult();
|
||||
return currentRecipe.getRecipeOutput(worldObj).copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,8 +234,8 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
/**
|
||||
* @return Inaccessible crafting inventory for the craft grid.
|
||||
*/
|
||||
public InventoryAdapter getCraftingInventory() {
|
||||
return craftingInventory;
|
||||
public IInventory getCraftingInventory() {
|
||||
return new InventoryMapper(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
|
||||
}
|
||||
|
||||
private static class WorktableInventoryAdapter extends TileInventoryAdapter<TileWorktable> {
|
||||
|
||||
@@ -36,115 +36,7 @@ import forestry.core.utils.PlainInventory;
|
||||
|
||||
public class RecipeMemory implements INBTTagable, IStreamable {
|
||||
|
||||
public static final class Recipe implements INBTTagable, IStreamable {
|
||||
|
||||
private InventoryAdapter matrix;
|
||||
private long lastUsed;
|
||||
private boolean locked;
|
||||
private ItemStack cachedRecipeOutput;
|
||||
|
||||
public Recipe() {
|
||||
}
|
||||
|
||||
public Recipe(InventoryCrafting crafting) {
|
||||
this.matrix = new InventoryAdapter(new PlainInventory(crafting));
|
||||
}
|
||||
|
||||
public Recipe(NBTTagCompound nbttagcompound) {
|
||||
readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
public void updateLastUse(long lastUsed) {
|
||||
this.lastUsed = lastUsed;
|
||||
}
|
||||
|
||||
public void toggleLock() {
|
||||
locked = !locked;
|
||||
}
|
||||
|
||||
public InventoryAdapter getMatrix() {
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput(World world) {
|
||||
if (cachedRecipeOutput == null) {
|
||||
InventoryCrafting crafting = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
|
||||
for (int i = 0; i < crafting.getSizeInventory(); i++) {
|
||||
crafting.setInventorySlotContents(i, matrix.getStackInSlot(i));
|
||||
}
|
||||
|
||||
cachedRecipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, world);
|
||||
}
|
||||
return cachedRecipeOutput;
|
||||
}
|
||||
|
||||
public long getLastUsed() {
|
||||
return this.lastUsed;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return this.locked;
|
||||
}
|
||||
|
||||
public boolean hasSameOutput(InventoryCrafting crafting, World world) {
|
||||
ItemStack recipeOutput = getRecipeOutput(world);
|
||||
if (recipeOutput == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack matchingRecipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, world);
|
||||
return ItemStack.areItemStacksEqual(recipeOutput, matchingRecipeOutput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
matrix = new InventoryAdapter(new InventoryCrafting(DUMMY_CONTAINER, 3, 3));
|
||||
matrix.readFromNBT(nbttagcompound);
|
||||
sanitizeMatrix();
|
||||
lastUsed = nbttagcompound.getLong("LastUsed");
|
||||
locked = nbttagcompound.getBoolean("Locked");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
sanitizeMatrix();
|
||||
matrix.writeToNBT(nbttagcompound);
|
||||
nbttagcompound.setLong("LastUsed", lastUsed);
|
||||
nbttagcompound.setBoolean("Locked", locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
sanitizeMatrix();
|
||||
matrix.writeData(data);
|
||||
data.writeLong(lastUsed);
|
||||
data.writeBoolean(locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
matrix = new InventoryAdapter(new InventoryCrafting(DUMMY_CONTAINER, 3, 3));
|
||||
matrix.readData(data);
|
||||
sanitizeMatrix();
|
||||
lastUsed = data.readLong();
|
||||
locked = data.readBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a nasty hack to hide a bug where the recipe stacks somehow
|
||||
* get the stackSize set to -1. Which makes the recipe no longer work,
|
||||
* ever. I've seen the bug, even inspected the NBT data of an afflicted
|
||||
* worktable, but can't duplicate it, and can't trace it. -CovertJaguar
|
||||
*/
|
||||
private void sanitizeMatrix() {
|
||||
for (int slot = 0; slot < matrix.getSizeInventory(); slot++) {
|
||||
ItemStack stack = matrix.getStackInSlot(slot);
|
||||
if (stack != null) {
|
||||
stack.stackSize = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static final int capacity = 9;
|
||||
|
||||
private static final Container DUMMY_CONTAINER = new ContainerDummy();
|
||||
private static final List<Class<? extends Item>> memoryBlacklist = new ArrayList<Class<? extends Item>>();
|
||||
@@ -155,7 +47,6 @@ public class RecipeMemory implements INBTTagable, IStreamable {
|
||||
|
||||
private LinkedList<Recipe> recipes = new LinkedList<Recipe>();
|
||||
private long lastUpdate;
|
||||
public final int capacity = 9;
|
||||
|
||||
private static boolean isValid(World world, Recipe recipe) {
|
||||
if (recipe == null) {
|
||||
@@ -310,4 +201,116 @@ public class RecipeMemory implements INBTTagable, IStreamable {
|
||||
List<Recipe> newRecipes = data.readStreamables(Recipe.class);
|
||||
recipes.addAll(newRecipes);
|
||||
}
|
||||
|
||||
public static final class Recipe implements INBTTagable, IStreamable {
|
||||
|
||||
private InventoryAdapter matrix;
|
||||
private long lastUsed;
|
||||
private boolean locked;
|
||||
private ItemStack cachedRecipeOutput;
|
||||
|
||||
public Recipe() {
|
||||
// required for serialization
|
||||
}
|
||||
|
||||
public Recipe(InventoryCrafting crafting) {
|
||||
this.matrix = new InventoryAdapter(new PlainInventory(crafting));
|
||||
}
|
||||
|
||||
public Recipe(NBTTagCompound nbttagcompound) {
|
||||
readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
public void updateLastUse(long lastUsed) {
|
||||
this.lastUsed = lastUsed;
|
||||
}
|
||||
|
||||
public void toggleLock() {
|
||||
locked = !locked;
|
||||
}
|
||||
|
||||
public InventoryAdapter getMatrix() {
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput(World world) {
|
||||
if (cachedRecipeOutput == null) {
|
||||
InventoryCrafting crafting = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
|
||||
for (int i = 0; i < crafting.getSizeInventory(); i++) {
|
||||
crafting.setInventorySlotContents(i, matrix.getStackInSlot(i));
|
||||
}
|
||||
|
||||
cachedRecipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, world);
|
||||
}
|
||||
return cachedRecipeOutput;
|
||||
}
|
||||
|
||||
public long getLastUsed() {
|
||||
return this.lastUsed;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return this.locked;
|
||||
}
|
||||
|
||||
public boolean hasSameOutput(InventoryCrafting crafting, World world) {
|
||||
ItemStack recipeOutput = getRecipeOutput(world);
|
||||
if (recipeOutput == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack matchingRecipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, world);
|
||||
return ItemStack.areItemStacksEqual(recipeOutput, matchingRecipeOutput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
matrix = new InventoryAdapter(new InventoryCrafting(DUMMY_CONTAINER, 3, 3));
|
||||
matrix.readFromNBT(nbttagcompound);
|
||||
sanitizeMatrix();
|
||||
lastUsed = nbttagcompound.getLong("LastUsed");
|
||||
locked = nbttagcompound.getBoolean("Locked");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
sanitizeMatrix();
|
||||
matrix.writeToNBT(nbttagcompound);
|
||||
nbttagcompound.setLong("LastUsed", lastUsed);
|
||||
nbttagcompound.setBoolean("Locked", locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
sanitizeMatrix();
|
||||
matrix.writeData(data);
|
||||
data.writeLong(lastUsed);
|
||||
data.writeBoolean(locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
matrix = new InventoryAdapter(new InventoryCrafting(DUMMY_CONTAINER, 3, 3));
|
||||
matrix.readData(data);
|
||||
sanitizeMatrix();
|
||||
lastUsed = data.readLong();
|
||||
locked = data.readBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a nasty hack to hide a bug where the recipe stacks somehow
|
||||
* get the stackSize set to -1. Which makes the recipe no longer work,
|
||||
* ever. I've seen the bug, even inspected the NBT data of an afflicted
|
||||
* worktable, but can't duplicate it, and can't trace it. -CovertJaguar
|
||||
*/
|
||||
private void sanitizeMatrix() {
|
||||
for (int slot = 0; slot < matrix.getSizeInventory(); slot++) {
|
||||
ItemStack stack = matrix.getStackInSlot(slot);
|
||||
if (stack != null) {
|
||||
stack.stackSize = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,6 +43,10 @@ public class ButterflyGenome extends Genome implements IButterflyGenome {
|
||||
|
||||
// NBT RETRIEVAL
|
||||
public static IAlleleButterflySpecies getSpecies(ItemStack itemStack) {
|
||||
if (!PluginLepidopterology.butterflyInterface.isMember(itemStack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IAlleleSpecies species = getSpeciesDirectly(itemStack);
|
||||
if (species instanceof IAlleleButterflySpecies) {
|
||||
return (IAlleleButterflySpecies) species;
|
||||
|
||||
@@ -58,6 +58,9 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
for (int i = SLOT_STAMPS_1; i < SLOT_STAMPS_1 + SLOT_STAMPS_COUNT; i++) {
|
||||
slots.add(i);
|
||||
}
|
||||
for (int i = SLOT_RECEIVE_BUFFER; i < SLOT_RECEIVE_BUFFER + SLOT_RECEIVE_BUFFER_COUNT; i++) {
|
||||
slots.add(i);
|
||||
}
|
||||
for (int i = SLOT_SEND_BUFFER; i < SLOT_SEND_BUFFER + SLOT_SEND_BUFFER_COUNT; i++) {
|
||||
slots.add(i);
|
||||
}
|
||||
@@ -95,6 +98,10 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
||||
return canSlotAccept(i, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
// / CONSTANTS
|
||||
|
||||
@@ -275,11 +275,11 @@ public class PluginIC2 extends ForestryPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
if (plantBall != null && compressedPlantBall != null) {
|
||||
RecipeUtil.injectLeveledRecipe(plantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 4, Fluids.BIOMASS);
|
||||
RecipeUtil.injectLeveledRecipe(compressedPlantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 5, Fluids.BIOMASS);
|
||||
} else {
|
||||
Proxies.log.fine("No IC2 plantballs found.");
|
||||
if (plantBall != null) {
|
||||
RecipeUtil.injectLeveledRecipe(plantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 9, Fluids.BIOMASS);
|
||||
}
|
||||
if (compressedPlantBall != null) {
|
||||
RecipeUtil.injectLeveledRecipe(compressedPlantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 9, Fluids.BIOMASS);
|
||||
}
|
||||
|
||||
if (resin != null) {
|
||||
|
||||
Reference in new issue
Block a user