mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-15 01:24:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
340ba2dc7c | ||
|
|
3e6c8407ff | ||
|
|
87908d2a35 | ||
|
|
a137cf8f12 | ||
|
|
70f710231d | ||
|
|
7a68e04053 | ||
|
|
3c37a81617 | ||
|
|
a9cc367623 | ||
|
|
7757790b84 |
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=2
|
||||
version_patch=6
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Executable → Regular
+27
-13
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -439,20 +366,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();
|
||||
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
@@ -297,6 +297,8 @@ public class PluginApiculture extends ForestryPlugin {
|
||||
createAlleles();
|
||||
BeeDefinition.initBees();
|
||||
|
||||
AlleleManager.alleleRegistry.registerDeprecatedAlleleReplacement("forestry.speciesArgrarian", BeeDefinition.AGRARIAN.getGenome().getPrimary());
|
||||
|
||||
// Hives
|
||||
createHives();
|
||||
registerBeehiveDrops();
|
||||
|
||||
Reference in new issue
Block a user