use of net.minecraft.inventory.ISidedInventory in project Charset by CharsetMC.
the class PartPipe method internalConnects.
private boolean internalConnects(EnumFacing side) {
ISlottedPart part = getContainer().getPartInSlot(PartSlot.getFaceSlot(side));
if (part instanceof IMicroblock.IFaceMicroblock) {
if (!((IMicroblock.IFaceMicroblock) part).isFaceHollow()) {
return false;
}
}
if (!OcclusionHelper.occlusionTest(getContainer().getParts(), this, BOXES[side.ordinal()])) {
return false;
}
if (PipeUtils.getPipe(getWorld(), getPos().offset(side), side.getOpposite()) != null) {
return true;
}
TileEntity tile = getNeighbourTile(side);
if (tile != null && tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite())) {
return true;
}
if (tile instanceof ISidedInventory || tile instanceof IInventory) {
return true;
}
if (tile != null && tile.hasCapability(ModCharsetPipes.CAP_SHIFTER, side.getOpposite())) {
return tile.getCapability(ModCharsetPipes.CAP_SHIFTER, side.getOpposite()).getMode() == IShifter.Mode.Extract;
}
return false;
}
use of net.minecraft.inventory.ISidedInventory in project BloodMagic by WayofTime.
the class RitualEffectAutoAlchemy method performEffect.
@Override
public void performEffect(IMasterRitualStone ritualStone) {
String owner = ritualStone.getOwner();
int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
World world = ritualStone.getWorld();
int x = ritualStone.getXCoord();
int y = ritualStone.getYCoord();
int z = ritualStone.getZCoord();
if (currentEssence < this.getCostPerRefresh() * 6) {
SoulNetworkHandler.causeNauseaToPlayer(owner);
} else {
boolean hasPotentia = this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, false);
int flag = 0;
TileEntity topEntity = world.getTileEntity(x, y + 1, z);
if (!(topEntity instanceof IBloodAltar) || !(topEntity instanceof IBloodAltar)) {
return;
}
IBloodAltar altar = (IBloodAltar) topEntity;
ItemStack targetStack = ((IInventory) altar).getStackInSlot(0);
if (targetStack == null) {
return;
}
ItemStack[] recipe = AlchemyRecipeRegistry.getRecipeForItemStack(targetStack);
if (recipe != null) {
TEWritingTable alchemyEntity;
IInventory outputInv = null;
IInventory inputInv1 = null;
IInventory inputInv2 = null;
TileEntity northEntity = world.getTileEntity(x, y, z - 1);
TileEntity southEntity = world.getTileEntity(x, y, z + 1);
TileEntity eastEntity = world.getTileEntity(x + 1, y, z);
TileEntity westEntity = world.getTileEntity(x - 1, y, z);
if (northEntity instanceof TEWritingTable) {
alchemyEntity = (TEWritingTable) northEntity;
if (southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) {
outputInv = (IInventory) southEntity;
}
if (eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) {
inputInv1 = (IInventory) eastEntity;
}
if (westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) {
inputInv2 = (IInventory) westEntity;
}
} else if (southEntity instanceof TEWritingTable) {
alchemyEntity = (TEWritingTable) southEntity;
if (northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) {
outputInv = (IInventory) northEntity;
}
if (eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) {
inputInv1 = (IInventory) eastEntity;
}
if (westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) {
inputInv2 = (IInventory) westEntity;
}
} else if (eastEntity instanceof TEWritingTable) {
alchemyEntity = (TEWritingTable) eastEntity;
if (westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) {
outputInv = (IInventory) westEntity;
}
if (northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) {
inputInv1 = (IInventory) northEntity;
}
if (southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) {
inputInv2 = (IInventory) southEntity;
}
} else if (westEntity instanceof TEWritingTable) {
alchemyEntity = (TEWritingTable) westEntity;
if (eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) {
outputInv = (IInventory) eastEntity;
}
if (northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) {
inputInv1 = (IInventory) northEntity;
}
if (southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) {
inputInv2 = (IInventory) southEntity;
}
} else {
return;
}
if (alchemyEntity != null && hasPotentia) {
alchemyEntity.setAccelerationTime(5);
if (alchemyEntity.isWorking()) {
this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, true);
}
}
if (outputInv != null) {
ItemStack outputStack = alchemyEntity.getStackInSlot(6);
if (outputStack != null) {
for (int i = 0; i < outputInv.getSizeInventory(); i++) {
ItemStack curStack = outputInv.getStackInSlot(i);
if (curStack == null) {
ItemStack copyStack = outputStack.copy();
copyStack.stackSize = 1;
outputStack.stackSize--;
if (outputStack.stackSize <= 0) {
alchemyEntity.setInventorySlotContents(6, null);
} else {
alchemyEntity.setInventorySlotContents(6, outputStack);
}
outputInv.setInventorySlotContents(i, copyStack);
flag++;
break;
} else if (curStack.isItemEqual(outputStack) && curStack.stackSize < curStack.getMaxStackSize() && ItemStack.areItemStackTagsEqual(outputStack, curStack)) {
outputStack.stackSize--;
if (outputStack.stackSize <= 0) {
alchemyEntity.setInventorySlotContents(6, null);
} else {
alchemyEntity.setInventorySlotContents(6, outputStack);
}
curStack.stackSize++;
outputInv.setInventorySlotContents(i, curStack);
flag++;
break;
}
}
}
for (int i = 0; i < 5; i++) {
ItemStack recItem;
if (recipe.length <= i) {
recItem = null;
} else {
recItem = recipe[i];
}
ItemStack alchStack = alchemyEntity.getStackInSlot(i + 1);
if ((recItem == null && alchStack != null) || (alchStack != null && !(areItemStacksEqualWithWildcard(recItem, alchStack)))) {
for (int j = 0; j < outputInv.getSizeInventory(); j++) {
ItemStack curStack = outputInv.getStackInSlot(j);
if (curStack == null) {
ItemStack copyStack = alchStack.copy();
copyStack.stackSize = 1;
alchStack.stackSize--;
if (alchStack.stackSize <= 0) {
alchemyEntity.setInventorySlotContents(i + 1, null);
} else {
alchemyEntity.setInventorySlotContents(i + 1, alchStack);
}
outputInv.setInventorySlotContents(j, copyStack);
flag++;
break;
} else if (curStack.isItemEqual(alchStack) && curStack.stackSize < curStack.getMaxStackSize() && ItemStack.areItemStackTagsEqual(alchStack, curStack)) {
alchStack.stackSize--;
if (alchStack.stackSize <= 0) {
alchemyEntity.setInventorySlotContents(i + 1, null);
} else {
alchemyEntity.setInventorySlotContents(i + 1, alchStack);
}
curStack.stackSize++;
outputInv.setInventorySlotContents(j, curStack);
flag++;
break;
}
}
continue;
}
}
}
if (world.getWorldTime() % 10 == 0) {
if (flag == 0 && inputInv1 != null) {
for (int i = 0; i < recipe.length; i++) {
ItemStack recItem = recipe[i];
if (recItem == null) {
continue;
}
ItemStack alchStack = alchemyEntity.getStackInSlot(i + 1);
if (alchStack != null && ((!areItemStacksEqualWithWildcard(recItem, alchStack)) || alchStack.stackSize >= (fillToOne ? 1 : alchStack.getMaxStackSize()))) {
continue;
}
for (int j = 0; j < inputInv1.getSizeInventory(); j++) {
ItemStack curItem = inputInv1.getStackInSlot(j);
if (curItem == null) {
continue;
}
if (!inputInv1.isItemValidForSlot(j, curItem) || (inputInv1 instanceof ISidedInventory && !((ISidedInventory) inputInv1).canExtractItem(j, curItem, ForgeDirection.DOWN.ordinal()))) {
continue;
}
if (areItemStacksEqualWithWildcard(recItem, curItem)) {
if (alchStack == null) {
ItemStack copyStack = recItem.copy();
copyStack.stackSize = 1;
alchemyEntity.setInventorySlotContents(i + 1, copyStack);
curItem.stackSize--;
if (curItem.stackSize <= 0) {
inputInv1.setInventorySlotContents(j, null);
} else {
inputInv1.setInventorySlotContents(j, curItem);
}
flag++;
break;
} else {
alchStack.stackSize++;
alchemyEntity.setInventorySlotContents(i + 1, alchStack);
curItem.stackSize--;
if (curItem.stackSize <= 0) {
inputInv1.setInventorySlotContents(j, null);
} else {
inputInv1.setInventorySlotContents(j, curItem);
}
flag++;
break;
}
}
}
}
}
if (flag == 0 && inputInv2 != null) {
for (int i = 0; i < recipe.length; i++) {
ItemStack recItem = recipe[i];
if (recItem == null) {
continue;
}
ItemStack alchStack = alchemyEntity.getStackInSlot(i + 1);
if (alchStack != null && ((!areItemStacksEqualWithWildcard(recItem, alchStack)) || alchStack.stackSize >= (fillToOne ? 1 : alchStack.getMaxStackSize()))) {
continue;
}
for (int j = 0; j < inputInv2.getSizeInventory(); j++) {
ItemStack curItem = inputInv2.getStackInSlot(j);
if (curItem == null) {
continue;
}
if (areItemStacksEqualWithWildcard(recItem, curItem)) {
if (alchStack == null) {
ItemStack copyStack = recItem.copy();
copyStack.stackSize = 1;
alchemyEntity.setInventorySlotContents(i + 1, copyStack);
curItem.stackSize--;
if (curItem.stackSize <= 0) {
inputInv2.setInventorySlotContents(j, null);
} else {
inputInv2.setInventorySlotContents(j, curItem);
}
flag++;
break;
} else {
alchStack.stackSize++;
alchemyEntity.setInventorySlotContents(i + 1, alchStack);
curItem.stackSize--;
if (curItem.stackSize <= 0) {
inputInv2.setInventorySlotContents(j, null);
} else {
inputInv2.setInventorySlotContents(j, curItem);
}
flag++;
break;
}
}
}
}
}
}
}
if (flag > 0) {
world.markBlockForUpdate(x, y, z + 1);
world.markBlockForUpdate(x, y, z - 1);
world.markBlockForUpdate(x + 1, y, z);
world.markBlockForUpdate(x - 1, y, z);
SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh() * flag);
}
}
}
use of net.minecraft.inventory.ISidedInventory in project BloodMagic by WayofTime.
the class SpellHelper method getNumberOfItemsInInventory.
public static int getNumberOfItemsInInventory(IInventory inventory, ForgeDirection dir) {
boolean[] canBeInserted = new boolean[inventory.getSizeInventory()];
if (inventory instanceof ISidedInventory) {
int[] array = ((ISidedInventory) inventory).getAccessibleSlotsFromSide(dir.ordinal());
for (int in : array) {
canBeInserted[in] = true;
}
} else {
for (int i = 0; i < canBeInserted.length; i++) {
canBeInserted[i] = true;
}
}
int amountOfItems = 0;
for (int i = 0; i < canBeInserted.length; i++) {
if (canBeInserted[i]) {
ItemStack stack = inventory.getStackInSlot(i);
if (stack != null) {
amountOfItems += stack.stackSize;
}
}
}
return amountOfItems;
}
use of net.minecraft.inventory.ISidedInventory in project LogisticsPipes by RS485.
the class PipeTransportLogistics method handleTileReachedServer_internal.
protected final void handleTileReachedServer_internal(LPTravelingItemServer arrivingItem, TileEntity tile, ForgeDirection dir) {
if (isRouted && getPipe().container.tilePart.getBCPipePluggable(dir) != null && getPipe().container.tilePart.getBCPipePluggable(dir).isAcceptingItems(arrivingItem)) {
LPTravelingItemServer remainingItem = getPipe().container.tilePart.getBCPipePluggable(dir).handleItem(arrivingItem);
if (remainingItem != null) {
getRoutedPipe().getRouter().update(true, getRoutedPipe());
this.injectItem(remainingItem, dir);
}
return;
}
if (getPipe() instanceof PipeItemsFluidSupplier) {
((PipeItemsFluidSupplier) getPipe()).endReached(arrivingItem, tile);
if (arrivingItem.getItemIdentifierStack().getStackSize() <= 0) {
return;
}
}
markChunkModified(tile);
if (MainProxy.isServer(getWorld()) && arrivingItem.getInfo() != null && arrivingItem.getArrived() && isRouted) {
getRoutedPipe().notifyOfItemArival(arrivingItem.getInfo());
}
if (getPipe() instanceof FluidRoutedPipe) {
if (((FluidRoutedPipe) getPipe()).endReached(arrivingItem, tile)) {
return;
}
}
boolean isSpecialConnectionInformationTransition = false;
if (MainProxy.isServer(getWorld())) {
if (SimpleServiceLocator.specialtileconnection.needsInformationTransition(tile)) {
isSpecialConnectionInformationTransition = true;
SimpleServiceLocator.specialtileconnection.transmit(tile, arrivingItem);
}
}
if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
if (passToNextPipe(arrivingItem, tile)) {
return;
}
} else if (tile instanceof IInventory && isRouted) {
getRoutedPipe().getCacheHolder().trigger(CacheTypes.Inventory);
// items.scheduleRemoval(arrivingItem);
if (MainProxy.isServer(getWorld())) {
// destroy the item on exit if it isn't exitable
if (!isSpecialConnectionInformationTransition && !isItemExitable(arrivingItem.getItemIdentifierStack())) {
return;
}
// last chance for chassi to back out
if (arrivingItem != null) {
if (arrivingItem.getTransportMode() != TransportMode.Active && !getRoutedPipe().getTransportLayer().stillWantItem(arrivingItem)) {
reverseItem(arrivingItem);
return;
}
}
ISlotUpgradeManager slotManager;
{
ModulePositionType slot = null;
int positionInt = -1;
if (arrivingItem.getInfo().targetInfo instanceof ChassiTargetInformation) {
positionInt = ((ChassiTargetInformation) arrivingItem.getInfo().targetInfo).getModuleSlot();
slot = ModulePositionType.SLOT;
} else if (LPConstants.DEBUG && container.pipe instanceof PipeLogisticsChassi) {
System.out.println(arrivingItem);
new RuntimeException("[ItemInsertion] Information weren't ment for a chassi pipe").printStackTrace();
}
slotManager = getRoutedPipe().getUpgradeManager(slot, positionInt);
}
boolean tookSome = false;
if (arrivingItem.getAdditionalTargetInformation() instanceof ITargetSlotInformation) {
ITargetSlotInformation information = (ITargetSlotInformation) arrivingItem.getAdditionalTargetInformation();
IInventory inv = (IInventory) tile;
if (inv instanceof ISidedInventory) {
inv = new SidedInventoryMinecraftAdapter((ISidedInventory) inv, ForgeDirection.UNKNOWN, false);
}
IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv);
if (util instanceof ISpecialInsertion) {
int slot = information.getTargetSlot();
int amount = information.getAmount();
if (util.getSizeInventory() > slot) {
ItemStack content = util.getStackInSlot(slot);
ItemStack toAdd = arrivingItem.getItemIdentifierStack().makeNormalStack();
toAdd.stackSize = Math.min(toAdd.stackSize, Math.max(0, amount - (content != null ? content.stackSize : 0)));
if (toAdd.stackSize > 0) {
if (util.getSizeInventory() > slot) {
int added = ((ISpecialInsertion) util).addToSlot(toAdd, slot);
arrivingItem.getItemIdentifierStack().lowerStackSize(added);
if (added > 0) {
tookSome = true;
}
}
}
}
if (information.isLimited()) {
if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
reverseItem(arrivingItem);
}
return;
}
}
}
// sneaky insertion
if (!getRoutedPipe().getUpgradeManager().hasCombinedSneakyUpgrade() || slotManager.hasOwnSneakyUpgrade()) {
ForgeDirection insertion = arrivingItem.output.getOpposite();
if (slotManager.hasSneakyUpgrade()) {
insertion = slotManager.getSneakyOrientation();
}
ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
if (added.stackSize > 0 && arrivingItem instanceof IRoutedItem) {
tookSome = true;
arrivingItem.setBufferCounter(0);
}
ItemRoutingInformation info;
if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
// we have some leftovers, we are splitting the stack, we need to clone the info
info = arrivingItem.getInfo().clone();
// For InvSysCon
info.getItem().setStackSize(added.stackSize);
insertedItemStack(info, tile);
} else {
info = arrivingItem.getInfo();
info.getItem().setStackSize(added.stackSize);
// For InvSysCon
insertedItemStack(info, tile);
// every item has been inserted.
return;
}
} else {
ForgeDirection[] dirs = getRoutedPipe().getUpgradeManager().getCombinedSneakyOrientation();
for (ForgeDirection insertion : dirs) {
if (insertion == null) {
continue;
}
ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
if (added.stackSize > 0) {
tookSome = true;
arrivingItem.setBufferCounter(0);
}
ItemRoutingInformation info;
if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
// we have some leftovers, we are splitting the stack, we need to clone the info
info = arrivingItem.getInfo().clone();
// For InvSysCon
info.getItem().setStackSize(added.stackSize);
insertedItemStack(info, tile);
} else {
info = arrivingItem.getInfo();
info.getItem().setStackSize(added.stackSize);
// For InvSysCon
insertedItemStack(info, tile);
// every item has been inserted.
return;
}
}
}
if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
reverseItem(arrivingItem);
}
}
// the item is handled
return;
}
// end of insert into IInventory
dropItem(arrivingItem);
}
use of net.minecraft.inventory.ISidedInventory in project LogisticsPipes by RS485.
the class ModuleApiaristRefiller method tick.
@Override
public void tick() {
if (++currentTickCount < ticksToOperation) {
return;
}
currentTickCount = 0;
IInventory inv = _service.getRealInventory();
if (!(inv instanceof ISidedInventory)) {
return;
}
ISidedInventory sinv = (ISidedInventory) inv;
ForgeDirection direction = _service.inventoryOrientation().getOpposite();
ItemStack stack = extractItem(sinv, false, direction, 1);
if (stack == null) {
return;
}
if (!(_service.canUseEnergy(100))) {
return;
}
currentTickCount = ticksToOperation;
if (reinsertBee(stack, sinv, direction)) {
return;
}
Pair<Integer, SinkReply> reply = _service.hasDestination(ItemIdentifier.get(stack), true, new ArrayList<>());
if (reply == null) {
return;
}
_service.useEnergy(20);
extractItem(sinv, true, direction, 1);
_service.sendStack(stack, reply, ItemSendMode.Normal);
}
Aggregations