Compare commits

..
20 Commits
Author SHA1 Message Date
mezz 27b9b7bc57 Fix Carpenter output Dupe bug 2015-09-26 23:06:56 -07:00
Nirek-K 06b1f9fabf Allow Biogas Engine fuel tank to be drained externally.
(cherry picked from commit 81d2c1971c)
2015-09-26 19:51:33 -07:00
Nirek-K b00f92ab76 Fix #847 TradeStation not outputting items to automation (also fix insertion filtering)
(cherry picked from commit 9478ffb7c1)
2015-09-26 14:45:04 -07:00
mezz 83a41d41d3 Bump version to 3.6.8 2015-09-24 01:47:11 -07:00
Nirek-K a47fab4579 Make plantball value slightly less terrible (equal to 9 wheat, so 'slightly' better to combine wheat, still worse for things like saplings)
(cherry picked from commit 31bd1e82fd)
2015-09-24 01:46:48 -07:00
Nirek-K 07389fe1dc Fix #829 IC2 plantballs not working in fermenter
(cherry picked from commit b56a299f63)
2015-09-24 01:46:42 -07:00
mezz b276c5bb38 Fix #750 Worktable not working properly with GT Tools
(cherry picked from commit 37dd0efee2)
2015-09-24 01:09:19 -07:00
mezz b630540a26 Fix #834 Fix machine fluid handling for IFluidContainerItem
(cherry picked from commit f49bcfd020)
2015-09-22 23:20:04 -07:00
mezz 340ba2dc7c Fix #680 and Fix #750 worktable handling of tools and ItemCraftedEvent
Cleanup some derped refactoring

(cherry picked from commit 9f1b1cc474)
2015-09-12 16:59:59 -07:00
mezz 3e6c8407ff Bump version 2015-09-09 23:16:33 -07:00
mezz 87908d2a35 Merge pull request #818 from bdew/3.6-fixes
Fixes for 3.6.x - BeekeepingLogic overwriting queens with old data + OreDict use in Squeezer recipes
2015-09-09 23:13:21 -07:00
bdew a137cf8f12 Fixed BeekeepingLogic overwriting queen with old data 2015-09-09 13:38:26 +03:00
bdew 70f710231d Changed squeezer recipes to prioritize specific recipes over OD and fixed accepting items 2015-09-09 11:45:27 +03:00
mezz 7a68e04053 Fix #813 Found Chromosome with invalid Alleles 2015-09-08 13:45:16 -07:00
mezz 3c37a81617 Fix #816 Exception during loading Alveary Heater 2015-09-08 13:32:55 -07:00
mezz a9cc367623 Fix crash from missing Agrarian bee allele from older worlds 2015-07-13 20:51:45 -07:00
mezz 7757790b84 Bump version to 3.6.3 2015-06-30 20:51:04 -07:00
mezz bcdbec5b89 Fix #742 Hopper doesn't fill last spot of Carpenter inventory 2015-06-28 15:02:06 -07:00
mezz 3fcb927201 Fix issue with BeekeepingLogic cached canWork 2015-06-28 15:01:24 -07:00
mezz b374f0b23c Bump version to 3.6.2 2015-06-28 15:01:05 -07:00
24 changed files with 363 additions and 371 deletions

No files matched your search

+1 -1
View File
@@ -2,4 +2,4 @@ mcversion=1.7.10
forgeversion=10.13.3.1370-1.7.10
version_major=3
version_minor=6
version_patch=1
version_patch=9
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.apiculture;
import java.util.Collections;
import java.util.Set;
import java.util.Stack;
@@ -36,7 +37,7 @@ public class BeekeepingLogic implements IBeekeepingLogic {
private static final int MAX_POLLINATION_ATTEMPTS = 20;
private static final int totalBreedingTime = Defaults.APIARY_BREEDING_TIME;
private static final int ticksPerCheckCanWork = 10;
private static final int ticksPerCheckQueenCanWork = 10;
private final IBeeHousing housing;
private final boolean housingSupportsMultipleErrorStates;
@@ -45,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;
@@ -53,8 +55,8 @@ public class BeekeepingLogic implements IBeekeepingLogic {
// Cached flowers check
private boolean hasFlowersCached = false;
private int hasFlowersCooldown = 0;
private boolean canWorkCached = false;
private int canWorkCooldown = 0;
private Set<IErrorState> queenCanWorkCached = Collections.emptySet();
private int queenCanWorkCooldown = 0;
public BeekeepingLogic(IBeeHousing housing) {
this.housing = housing;
@@ -128,16 +130,6 @@ public class BeekeepingLogic implements IBeekeepingLogic {
@Override
public boolean canWork() {
if (canWorkCooldown > 0) {
canWorkCooldown--;
} else {
canWorkCached = checkCanWork();
canWorkCooldown = ticksPerCheckCanWork;
}
return canWorkCached;
}
private boolean checkCanWork() {
if (housingSupportsMultipleErrorStates) {
Set<IErrorState> errorStates = housing.getErrorStates();
for (IErrorState errorState : errorStates) {
@@ -183,7 +175,7 @@ public class BeekeepingLogic implements IBeekeepingLogic {
if (hasFlowersCooldown <= 0) {
hasFlowersCached = queen.hasFlower(housing);
hasFlowersCooldown = PluginApiculture.ticksPerBeeWorkCycle / ticksPerCheckCanWork;
hasFlowersCooldown = PluginApiculture.ticksPerBeeWorkCycle;
// check more often if we haven't found flowers
if (!hasFlowersCached) {
@@ -318,7 +310,12 @@ public class BeekeepingLogic implements IBeekeepingLogic {
ItemStack queenStack = housing.getQueen();
if (queenStack == null || !ForestryItem.beeQueenGE.isItemEqual(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;
queen = null;
@@ -367,30 +364,46 @@ public class BeekeepingLogic implements IBeekeepingLogic {
}
private boolean queenCanWork() {
if (queen == null) {
return false;
if (queenCanWorkCooldown > 0) {
queenCanWorkCooldown--;
} else {
if (queen == null) {
return false;
}
queenCanWorkCached = checkQueenCanWork();
queenCanWorkCooldown = ticksPerCheckQueenCanWork;
}
if (housingSupportsMultipleErrorStates) {
try {
Set<IErrorState> errorStates = queen.getCanWork(housing);
Set<IErrorState> errorStates = queenCanWorkCached;
if (errorStates.size() > 0) {
if (housingSupportsMultipleErrorStates) {
for (IErrorState errorState : errorStates) {
housing.setErrorCondition(true, errorState);
}
return (errorStates.size() == 0);
} catch (Throwable ignored) {
// queen might not support getCanWork(housing)
} else {
IErrorState state = errorStates.iterator().next();
housing.setErrorState(state);
}
return false;
} else {
return true;
}
}
private Set<IErrorState> checkQueenCanWork() {
try {
return queen.getCanWork(housing);
} catch (Throwable ignored) {
// queen might not support getCanWork
}
IErrorState state = queen.canWork(housing);
if (state != EnumErrorCode.OK) {
housing.setErrorState(state);
return false;
return Collections.singleton(state);
}
return true;
return Collections.emptySet();
}
// / BREEDING
@@ -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;
@@ -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));
}
}
@@ -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);
}
+34 -18
View File
@@ -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) {
+30 -112
View File
@@ -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);
@@ -98,7 +98,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
craftPreviewInventory = new InventoryCraftResult();
setInternalInventory(new CarpenterInventoryAdapter(this));
InvTools.configureSided(getInternalInventory(), Defaults.FACINGS, SLOT_BOX, 20);
InvTools.configureSided(getInternalInventory(), Defaults.FACINGS, SLOT_BOX, 21);
tankManager = new TankManager(resourceTank);
}
@@ -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;
+13 -5
View File
@@ -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,47 @@ 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);
for (int i = 0; i < removed.length; i++) {
craftingInventory.setInventorySlotContents(i, removed[i]);
}
return removed != null;
}
@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 +231,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
@@ -297,6 +297,8 @@ public class PluginApiculture extends ForestryPlugin {
createAlleles();
BeeDefinition.initBees();
AlleleManager.alleleRegistry.registerDeprecatedAlleleReplacement("forestry.speciesArgrarian", BeeDefinition.AGRARIAN.getGenome().getPrimary());
// Hives
createHives();
registerBeehiveDrops();
@@ -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) {