use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.
the class IOHelper method insert.
public static ItemStack insert(IInventory inventory, ItemStack itemStack, int side, boolean simulate) {
if (inventory instanceof ISidedInventory && side > -1) {
ISidedInventory isidedinventory = (ISidedInventory) inventory;
int[] aint = isidedinventory.getSlotsForFace(Direction.from3DDataValue(side));
for (int j = 0; j < aint.length && !itemStack.isEmpty() && itemStack.getCount() > 0; ++j) {
itemStack = insert(inventory, itemStack, aint[j], side, simulate);
}
} else {
int k = inventory.getContainerSize();
for (int l = 0; l < k && !itemStack.isEmpty() && itemStack.getCount() > 0; ++l) {
itemStack = insert(inventory, itemStack, l, side, simulate);
}
}
if (!itemStack.isEmpty() && itemStack.getCount() == 0) {
itemStack = ItemStack.EMPTY;
}
return itemStack;
}
use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.
the class IOHelper method extractOneItem.
public static ItemStack extractOneItem(TileEntity tile, Direction dir) {
IInventory inv = getInventoryForTE(tile);
if (inv != null && !inv.isEmpty()) {
int[] accessibleSlots;
if (inv instanceof ISidedInventory) {
accessibleSlots = ((ISidedInventory) inv).getSlotsForFace(dir);
} else {
accessibleSlots = new int[inv.getContainerSize()];
for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
}
for (int slot : accessibleSlots) {
ItemStack stack = inv.getItem(slot);
ItemStack retrievingStack = stack.isEmpty() ? ItemStack.EMPTY : stack.copy().split(1);
if (!stack.isEmpty() && IOHelper.canTakeItemThroughFaceFromInventory(inv, retrievingStack, slot, dir.ordinal())) {
ItemStack ret = stack.split(1);
if (stack.getCount() == 0)
inv.setItem(slot, ItemStack.EMPTY);
tile.setChanged();
return ret;
}
}
}
return ItemStack.EMPTY;
}
use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.
the class TileRegulator method isSatisfied.
/**
* Returns true if the supplying inventory has the items stated in the output filter.
*
* @return
*/
private boolean isSatisfied() {
IInventory inv = IOHelper.getInventoryForTE(getTileCache(getOutputDirection()));
if (inv != null) {
int[] accessibleSlots;
if (inv instanceof ISidedInventory) {
accessibleSlots = ((ISidedInventory) inv).getSlotsForFace(getFacingDirection());
} else {
accessibleSlots = new int[inv.getContainerSize()];
for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
}
boolean everythingNull = true;
for (int i = 18; i < 27; i++) {
if (!inventory.get(i).isEmpty()) {
everythingNull = false;
int outputFilterItems = getItemsInSection(inventory.get(i), EnumSection.OUTPUT_FILTER);
int supplyingInvCount = 0;
for (int slot : accessibleSlots) {
ItemStack stackInSlot = inv.getItem(slot);
if (!stackInSlot.isEmpty() && ItemStackHelper.areStacksEqual(stackInSlot, inventory.get(i), fuzzySetting) && IOHelper.canPlaceItemThroughFaceToInventory(inv, inventory.get(i), slot, getFacingDirection().ordinal())) {
supplyingInvCount += stackInSlot.getCount();
}
}
if (supplyingInvCount < outputFilterItems)
return false;
}
}
return !everythingNull;
}
return false;
}
use of net.minecraft.inventory.ISidedInventory in project ForestryMC by ForestryMC.
the class TileAlvearyPlain method updateServerSide.
@Override
protected void updateServerSide() {
if (beekeepingLogic == null) {
return;
}
if (!isMaster()) {
return;
}
beekeepingLogic.update();
// Equalize humidity and temperature
equalizeTemperature();
equalizeHumidity();
IBee queen = beekeepingLogic.getQueen();
if (queen == null) {
return;
}
// Add swarm effects
if (updateOnInterval(200)) {
ISidedInventory inventory = getStructureInventory();
if (inventory != null) {
onQueenChange(inventory.getStackInSlot(SLOT_QUEEN));
}
}
if (getErrorState() == EnumErrorCode.OK) {
queen.doFX(beekeepingLogic.getEffectData(), this);
}
if (getErrorState() == EnumErrorCode.OK && updateOnInterval(50)) {
float f = xCoord + 0.5F;
float f1 = yCoord + 0.0F + (worldObj.rand.nextFloat() * 6F) / 16F;
float f2 = zCoord + 0.5F;
float f3 = 0.52F;
float f4 = worldObj.rand.nextFloat() * 0.6F - 0.3F;
Proxies.common.addEntitySwarmFX(worldObj, (f - f3), f1, (f2 + f4), 0F, 0F, 0F);
Proxies.common.addEntitySwarmFX(worldObj, (f + f3), f1, (f2 + f4), 0F, 0F, 0F);
Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 - f3), 0F, 0F, 0F);
Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 + f3), 0F, 0F, 0F);
}
}
use of net.minecraft.inventory.ISidedInventory in project ForestryMC by ForestryMC.
the class TileAlvearyPlain method updateClientSide.
@Override
protected void updateClientSide() {
if (!isMaster()) {
return;
}
ISidedInventory inventory = getStructureInventory();
if (inventory == null) {
return;
}
// / Multiplayer FX
ItemStack queenStack = inventory.getStackInSlot(SLOT_QUEEN);
if (PluginApiculture.beeInterface.isMated(queenStack)) {
if (getErrorState() == EnumErrorCode.OK && updateOnInterval(2)) {
IBee displayQueen = PluginApiculture.beeInterface.getMember(queenStack);
displayQueen.doFX(beekeepingLogic.getEffectData(), this);
}
}
}
Aggregations