use of net.minecraft.inventory.ISidedInventory in project SpongeCommon by SpongePowered.
the class IMixinSingleBlockCarrier method getInventory.
static Inventory getInventory(Direction from, BlockCarrier thisThing) {
if (thisThing instanceof ISidedInventory) {
EnumFacing facing = DirectionFacingProvider.getInstance().get(from).get();
int[] slots = ((ISidedInventory) thisThing).getSlotsForFace(facing);
QueryOperation<?>[] indices = new QueryOperation[slots.length];
for (int i = 0; i < slots.length; i++) {
indices[i] = QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(slots[i]));
}
return thisThing.getInventory().query(indices);
}
return thisThing.getInventory();
}
use of net.minecraft.inventory.ISidedInventory in project RebornCore by TechReborn.
the class InventoryHelper method insertItemIntoInventory.
public static void insertItemIntoInventory(IInventory inventory, ItemStack stack, EnumFacing side, int intoSlot, boolean doMove, boolean canStack) {
if (stack.isEmpty())
return;
IInventory targetInventory = inventory;
if (!doMove) {
targetInventory = new GenericInventory("temporary.inventory", false, targetInventory.getSizeInventory());
((GenericInventory) targetInventory).copyFrom(inventory);
}
int i = 0;
int[] attemptSlots = new int[0];
if (inventory instanceof ISidedInventory && side != null) {
attemptSlots = ((ISidedInventory) inventory).getSlotsForFace(side);
if (attemptSlots == null)
attemptSlots = new int[0];
} else {
attemptSlots = new int[inventory.getSizeInventory()];
for (int a = 0; a < inventory.getSizeInventory(); a++) attemptSlots[a] = a;
}
if (intoSlot > -1) {
Set<Integer> x = new HashSet<Integer>();
for (int attemptedSlot : attemptSlots) x.add(attemptedSlot);
if (x.contains(intoSlot))
attemptSlots = new int[] { intoSlot };
else
attemptSlots = new int[0];
}
while (stack.getCount() > 0 && i < attemptSlots.length) {
if (side != null && inventory instanceof ISidedInventory)
if (!((ISidedInventory) inventory).canInsertItem(attemptSlots[i], stack, side.getOpposite())) {
i++;
continue;
}
tryInsertStack(targetInventory, attemptSlots[i], stack, canStack);
i++;
}
}
use of net.minecraft.inventory.ISidedInventory in project Solar by ArekkuusuJerii.
the class TileGravityHopper method update.
@Override
@SuppressWarnings("ConstantConditions")
public void update() {
if (!world.isRemote) {
if (cooldown <= 0) {
EnumFacing facing = getFacing();
traceBlock(facing).ifPresent(out -> {
traceBlock(facing.getOpposite()).ifPresent(in -> {
Pair<IItemHandler, ISidedInventory> invOut = getInventory(out, facing.getOpposite());
Pair<IItemHandler, ISidedInventory> invIn;
ItemStack stack = transferOut(invOut, true);
if (!stack.isEmpty() && transferIn(invIn = getInventory(in, facing), stack, true)) {
if (transferIn(invIn, transferOut(invOut, false), false))
cooldown = 5;
}
});
});
} else
cooldown--;
} else {
spawnParticles();
}
}
use of net.minecraft.inventory.ISidedInventory in project Solar by ArekkuusuJerii.
the class TileVacuumConveyor method dropItems.
private void dropItems() {
if (cooldown <= 0) {
IItemHandler handler = from.getKey();
ISidedInventory sidedInv = from.getValue();
for (int slot = 0; slot < handler.getSlots(); slot++) {
ItemStack inSlot = handler.getStackInSlot(slot);
if (!inSlot.isEmpty() && (lookup.isEmpty() || ItemHandlerHelper.canItemStacksStack(lookup, inSlot)) && (sidedInv == null || sidedInv.canExtractItem(slot, inSlot, getFacingLazy()))) {
BlockPos offset = pos.offset(getFacingLazy());
Vector3 spawn = Vector3.apply(offset.getX(), offset.getY(), offset.getZ()).add(0.5D);
ItemStack out = handler.extractItem(slot, Integer.MAX_VALUE, false);
EntityTemporalItem entity = new EntityTemporalItem(world, spawn.x(), spawn.y(), spawn.z(), out);
impulseEntityItem(spawn, entity);
world.spawnEntity(entity);
break;
}
}
cooldown = 5;
} else
cooldown--;
applyGravity(repulse, -1.25D);
}
use of net.minecraft.inventory.ISidedInventory in project BloodMagic by WayofTime.
the class Utils method insertStackIntoInventory.
/**
* Inserts the desired stack into the inventory up to a limit for the
* inventory.
*
* @param stack
* @param inventory
* @param dir
* @param limit
* @return
*/
public static ItemStack insertStackIntoInventory(ItemStack stack, IInventory inventory, EnumFacing dir, int limit) {
if (stack.isEmpty()) {
return ItemStack.EMPTY;
}
boolean[] canBeInserted = new boolean[inventory.getSizeInventory()];
if (inventory instanceof ISidedInventory) {
int[] array = ((ISidedInventory) inventory).getSlotsForFace(dir);
for (int in : array) {
canBeInserted[in] = ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
}
} else {
for (int i = 0; i < canBeInserted.length; i++) {
canBeInserted[i] = true;
}
}
int numberMatching = 0;
for (int i = 0; i < inventory.getSizeInventory(); i++) {
if (!canBeInserted[i]) {
continue;
}
ItemStack invStack = inventory.getStackInSlot(i);
if (!invStack.isEmpty() && canCombine(stack, invStack)) {
numberMatching += invStack.getCount();
}
}
if (numberMatching >= limit) {
return stack;
}
int newLimit = limit - numberMatching;
for (int i = 0; i < inventory.getSizeInventory(); i++) {
if (!canBeInserted[i]) {
continue;
}
int prevStackSize = stack.getCount();
ItemStack[] combinedStacks = combineStacks(stack, inventory.getStackInSlot(i), newLimit);
stack = combinedStacks[0];
// TODO
inventory.setInventorySlotContents(i, combinedStacks[1]);
newLimit -= (prevStackSize - stack.getCount());
if (newLimit <= 0 || stack.isEmpty()) {
return stack;
}
}
return stack;
}
Aggregations