use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class LogisticsSolderingTileEntity method getHandlerForRecipe.
public ICraftingResultHandler getHandlerForRecipe() {
for (SolderingStationRecipe recipe : SolderingStationRecipes.getRecipes()) {
boolean match = true;
for (int i = 0; i < 9; i++) {
ItemStack recipestack = recipe.source[i];
ItemStack inputStack = inv.getStackInSlot(i);
if (recipestack == null) {
if (inputStack != null) {
match = false;
}
continue;
} else if (inputStack == null) {
match = false;
continue;
} else {
if (!itemEquals(recipestack, inputStack)) {
match = false;
}
}
}
if (match) {
return recipe.handler;
}
}
return null;
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class LogisticsSolderingTileEntity method getRecipeForTagetAsItemIdentifierStackList.
public List<ItemIdentifierStack> getRecipeForTagetAsItemIdentifierStackList() {
LinkedList<ItemIdentifierStack> list = new LinkedList<>();
ItemStack[] array = getRecipeForTaget();
if (array != null) {
for (ItemStack stack : array) {
if (stack != null) {
list.addLast(ItemIdentifier.get(stack).makeStack(1));
} else {
list.addLast(null);
}
}
}
return list;
}
use of net.minecraft.item.ItemStack in project BluePower by Qmunity.
the class TileCircuitDatabase method copy.
/**
* Returns true of copy succeeded.
*
* @param player
* @param simulate
* @return
*/
public boolean copy(EntityPlayer player, ItemStack template, ItemStack target, boolean simulate) {
if (template != null && target != null) {
if (template.isItemEqual(target)) {
IDatabaseSaveable saveable = (IDatabaseSaveable) template.getItem();
if (saveable.canCopy(template, target)) {
if (!player.capabilities.isCreativeMode) {
List<ItemStack> stacksInTemplate = saveable.getItemsOnStack(template);
List<ItemStack> stacksInOutput = saveable.getItemsOnStack(target);
if (stacksInTemplate == null)
stacksInTemplate = new ArrayList<ItemStack>();
if (stacksInOutput == null)
stacksInOutput = new ArrayList<ItemStack>();
List<ItemStack> traversedItems = new ArrayList<ItemStack>();
List<ItemStack> allApplicableItems = new ArrayList<ItemStack>();
allApplicableItems.addAll(stacksInTemplate);
allApplicableItems.addAll(stacksInOutput);
for (ItemStack templateStack : allApplicableItems) {
boolean alreadyTraversed = false;
for (ItemStack traversedItem : traversedItems) {
if (traversedItem.isItemEqual(templateStack) && ItemStack.areItemStackTagsEqual(traversedItem, templateStack)) {
alreadyTraversed = true;
break;
}
}
if (alreadyTraversed)
continue;
traversedItems.add(templateStack);
int count = 0;
for (ItemStack stack : stacksInTemplate) {
if (stack.isItemEqual(templateStack) && ItemStack.areItemStackTagsEqual(stack, templateStack)) {
count += stack.stackSize;
}
}
for (ItemStack stack : stacksInOutput) {
if (stack.isItemEqual(templateStack) && ItemStack.areItemStackTagsEqual(stack, templateStack)) {
count -= stack.stackSize;
}
}
// if 5 items are inserted to be copied, the required items are x5.
count *= target.stackSize;
if (count > 0) {
// At this point we need assist from the inventory.
ItemStack retrievedStack = templateStack.copy();
retrievedStack.stackSize = count;
retrievedStack = IOHelper.extract(this, ForgeDirection.UNKNOWN, retrievedStack, true, simulate, 2);
if (retrievedStack == null || retrievedStack.stackSize < count)
return false;
} else if (count < 0) {
ItemStack returnedStack = templateStack.copy();
returnedStack.stackSize = -count;
returnedStack = IOHelper.insert(this, returnedStack, ForgeDirection.UNKNOWN, simulate);
if (returnedStack != null && !simulate) {
IOHelper.spawnItemInWorld(worldObj, returnedStack, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
}
}
}
}
if (!simulate) {
ItemStack copyStack = template.copy();
copyStack.stackSize = target.stackSize;
copyInventory.setInventorySlotContents(1, copyStack);
}
return true;
}
}
}
return false;
}
use of net.minecraft.item.ItemStack in project BluePower by Qmunity.
the class TileManager method acceptItemFromTube.
@Override
public TubeStack acceptItemFromTube(TubeStack stack, ForgeDirection from, boolean simulate) {
if (from == getFacingDirection().getOpposite()) {
// if (!isBufferEmpty()) return stack;
int itemsAccepted = acceptedItems(stack.stack);
if (itemsAccepted > 0) {
if (itemsAccepted >= stack.stack.stackSize) {
ItemStack rejectedStack = IOHelper.insert(getTileCache(getFacingDirection()), stack.stack, from, simulate);
if (rejectedStack == null || rejectedStack.stackSize != stack.stack.stackSize) {
if (!simulate) {
rejectTicker = 0;
sendUpdatePacket();
}
}
if (rejectedStack == null) {
return null;
} else {
stack.stack = rejectedStack;
return stack;
}
}
TubeStack injectedStack = stack.copy();
stack.stack.stackSize -= itemsAccepted;
injectedStack.stack.stackSize = itemsAccepted;
ItemStack rejectedStack = IOHelper.insert(getTileCache(getFacingDirection()), injectedStack.stack, from, simulate);
if (rejectedStack == null || rejectedStack.stackSize != injectedStack.stack.stackSize) {
if (!simulate) {
rejectTicker = 0;
sendUpdatePacket();
}
}
if (rejectedStack != null) {
stack.stack.stackSize += rejectedStack.stackSize;
}
}
}
stack.setTarget(null, null);
return super.acceptItemFromTube(stack, from, simulate);
}
use of net.minecraft.item.ItemStack in project BluePower by Qmunity.
the class TileManager method retrieveItemsFromManagers.
private void retrieveItemsFromManagers() {
PneumaticTube tube = MultipartCompatibility.getPart(worldObj, xCoord + getOutputDirection().offsetX, yCoord + getOutputDirection().offsetY, zCoord + getOutputDirection().offsetZ, PneumaticTube.class);
if (tube != null) {
for (ItemStack stack : inventory) {
int acceptedItems = acceptedItems(stack);
if (acceptedItems > 0) {
ItemStack retrievingStack = stack.copy();
retrievingStack.stackSize = retrievingStack.getMaxStackSize();
if (tube.getLogic().retrieveStack(this, getOutputDirection(), retrievingStack, filterColor))
return;
}
}
}
}
Aggregations