use of net.minecraft.item.ItemStack in project BluePower by Qmunity.
the class TileCircuitTable method getApplicableItems.
protected List<ItemStack> getApplicableItems() {
List<ItemStack> gates = new ArrayList<ItemStack>();
List<PartInfo> registeredParts = PartManager.getRegisteredParts();
for (PartInfo part : registeredParts) {
if (part.getExample() instanceof GateBase<?, ?, ?, ?, ?, ?> && ((GateBase<?, ?, ?, ?, ?, ?>) part.getExample()).isCraftableInCircuitTable()) {
ItemStack partStack = part.getStack().copy();
gates.add(partStack);
}
}
return gates;
}
use of net.minecraft.item.ItemStack in project BluePower by Qmunity.
the class TileRegulator method updateEntity.
@Override
public void updateEntity() {
super.updateEntity();
if (!worldObj.isRemote && isBufferEmpty()) {
boolean ratiosMatch = true;
for (int i = 0; i < 9; i++) {
if (inventory[i] != null) {
int inputFilterItems = getItemsInSection(inventory[i], EnumSection.INPUT_FILTER);
int bufferItems = getItemsInSection(inventory[i], EnumSection.BUFFER);
if (bufferItems < inputFilterItems) {
ratiosMatch = false;
break;
}
}
}
if (ratiosMatch && !isEjecting())
checkIndividualOutputFilterAndEject();
if (mode == 1 && !isEjecting()) {
// supply mode
IInventory inv = IOHelper.getInventoryForTE(getTileCache(getOutputDirection()));
if (inv != null) {
int[] accessibleSlots;
if (inv instanceof ISidedInventory) {
accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(getFacingDirection().ordinal());
} else {
accessibleSlots = new int[inv.getSizeInventory()];
for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
}
for (int i = 18; i < 27; i++) {
if (inventory[i] != null) {
int outputFilterItems = getItemsInSection(inventory[i], EnumSection.OUTPUT_FILTER);
int supplyingInvCount = 0;
for (int slot : accessibleSlots) {
ItemStack stackInSlot = inv.getStackInSlot(slot);
if (stackInSlot != null && ItemStackHelper.areStacksEqual(stackInSlot, inventory[i], fuzzySetting) && IOHelper.canInsertItemToInventory(inv, inventory[i], slot, getFacingDirection().ordinal())) {
supplyingInvCount += stackInSlot.stackSize;
}
}
if (supplyingInvCount < outputFilterItems) {
ItemStack requestedStack = inventory[i].copy();
requestedStack.stackSize = outputFilterItems - supplyingInvCount;
// try
ItemStack bufferItems = IOHelper.extract(this, ForgeDirection.UNKNOWN, requestedStack, true, false, fuzzySetting);
// the buffer.
if (bufferItems != null) {
// insert into
ItemStack remainder = IOHelper.insert(inv, bufferItems, getFacingDirection().ordinal(), false);
// supplying inv.
if (remainder != null) {
// when not every item can be supplied, return
IOHelper.insert(this, remainder, ForgeDirection.UNKNOWN, false);
// those to the buffer.
}
}
}
}
}
}
}
boolean shouldEmitRedstone = isSatisfied() || animationTicker >= 0;
if (isEjecting() != shouldEmitRedstone) {
setOutputtingRedstone(shouldEmitRedstone);
sendUpdatePacket();
}
}
}
use of net.minecraft.item.ItemStack in project BluePower by Qmunity.
the class TileRegulator method acceptItemFromTube.
@Override
public TubeStack acceptItemFromTube(TubeStack stack, ForgeDirection from, boolean simulate) {
if (from == getFacingDirection() && isBufferEmpty()) {
stack = stack.copy();
int bufferItems = getItemsInSection(stack.stack, EnumSection.BUFFER);
int inputFilterItems = getItemsInSection(stack.stack, EnumSection.INPUT_FILTER);
int allowedItems = inputFilterItems - bufferItems;
if (allowedItems <= 0)
return stack;
ItemStack acceptedStack = stack.stack.splitStack(Math.min(allowedItems, stack.stack.stackSize));
if (acceptedStack != null && acceptedStack.stackSize > 0) {
for (int i = EnumSection.INPUT_FILTER.ordinal() * 9; i < EnumSection.INPUT_FILTER.ordinal() * 9 + 9; i++) {
if (inventory[i] != null && ItemStackHelper.areStacksEqual(acceptedStack, inventory[i], fuzzySetting)) {
acceptedStack = IOHelper.insert(this, acceptedStack, EnumSection.BUFFER.ordinal() * 9 + i, ForgeDirection.UNKNOWN.ordinal(), simulate);
if (acceptedStack == null) {
break;
}
}
}
if (acceptedStack != null && acceptedStack.stackSize != 0) {
ItemStack remainder = IOHelper.insert(this, acceptedStack, ForgeDirection.UNKNOWN.ordinal(), simulate);
if (remainder != null) {
stack.stack.stackSize += remainder.stackSize;
}
}
if (stack.stack.stackSize > 0)
return stack;
else
return null;
} else {
return stack;
}
} else {
return super.acceptItemFromTube(stack, from, simulate);
}
}
use of net.minecraft.item.ItemStack in project BluePower by Qmunity.
the class TileProjectTable method craft.
protected void craft() {
for (int i = 0; i < craftingGrid.length; ++i) {
ItemStack itemstack1 = craftingGrid[i];
if (itemstack1 != null) {
boolean pulledFromInventory = false;
if (craftingGrid[i].stackSize == 1) {
ItemStack stackFromTable = ContainerProjectTable.extractStackFromTable(this, craftingGrid[i], false);
pulledFromInventory = stackFromTable != null;
}
if (!pulledFromInventory) {
craftingGrid[i].stackSize--;
if (craftingGrid[i].stackSize <= 0)
craftingGrid[i] = null;
}
if (itemstack1.getItem().hasContainerItem(itemstack1)) {
ItemStack itemstack2 = itemstack1.getItem().getContainerItem(itemstack1);
if (itemstack2 != null && itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage()) {
continue;
}
if (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1)) {
ItemStack remainder = IOHelper.insert(this, itemstack2, 0, false);
if (remainder != null) {
worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord, yCoord, zCoord, remainder));
}
}
}
}
}
}
use of net.minecraft.item.ItemStack in project BluePower by Qmunity.
the class TileProjectTable method getCraftingGrid.
public InventoryCrafting getCraftingGrid(Container listener) {
InventoryCrafting inventoryCrafting = new InventoryCrafting(listener, 3, 3) {
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
super.setInventorySlotContents(slot, stack);
updateCraftingGrid();
}
@Override
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
ItemStack stack = super.decrStackSize(p_70298_1_, p_70298_2_);
updateCraftingGrid();
return stack;
}
};
if (stackListFieldInventoryCrafting == null) {
stackListFieldInventoryCrafting = ReflectionHelper.findField(InventoryCrafting.class, "field_70466_a", "stackList");
}
try {
// Inject the array, so when stacks are being set to null by the
stackListFieldInventoryCrafting.set(inventoryCrafting, craftingGrid);
// container it'll make it's way over to the actual stacks.
return inventoryCrafting;
} catch (Exception e) {
BluePower.log.error("This is about to go wrong, Project Table getCraftingGrid:");
e.printStackTrace();
return null;
}
}
Aggregations