use of net.minecraftforge.items.IItemHandler in project Almura by AlmuraDev.
the class CapabilityDualItemHandlerGuiHandler method getClientGuiElement.
@SideOnly(Side.CLIENT)
@Nullable
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
final BlockPos pos = new BlockPos(x, y, z);
final Block block = world.getBlockState(pos).getBlock();
final TileEntity te = world.getTileEntity(pos);
if (te == null || !(te instanceof MultiSlotTileEntity)) {
return null;
}
final IItemHandler teItemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (teItemHandler == null) {
return null;
}
final IItemHandler playerItemHandler = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (playerItemHandler == null) {
return null;
}
return new DualItemHandlerGui(teItemHandler, playerItemHandler, new TextComponentString(block.getLocalizedName()), new TextComponentTranslation("container.inventory"));
}
use of net.minecraftforge.items.IItemHandler in project ConvenientAdditions by Necr0.
the class EventHandlerSoulbound method onPlayerDrops.
@SubscribeEvent
public void onPlayerDrops(PlayerDropsEvent e) {
if (e.getEntityPlayer().getEntityWorld().isRemote || e.getEntityPlayer().getEntityWorld().getGameRules().getBoolean("keepInventory"))
return;
Iterator<EntityItem> i = e.getDrops().iterator();
while (i.hasNext()) {
EntityItem ent = i.next();
ItemStack stack = ent.getEntityItem();
if (!stack.isEmpty() && stack.getItem() instanceof ISoulbound && ((ISoulbound) stack.getItem()).isSoulbound(stack, e.getEntityPlayer())) {
IItemHandler h = e.getEntityPlayer().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
ItemStack out = tryInsert(stack, h);
if (out == null)
i.remove();
else
stack.setCount(out.getCount());
}
}
}
use of net.minecraftforge.items.IItemHandler in project MinecraftForge by MinecraftForge.
the class FluidUtil method interactWithFluidHandler.
/**
* Used to handle the common case of a player holding a fluid item and right-clicking on a fluid handler.
* First it tries to fill the container item from the fluid handler,
* if that action fails then it tries to drain the container item into the fluid handler.
*
* @param stack The filled or empty fluid container.
* Will not be modified directly, if modifications are necessary a modified copy is returned in the result.
* @param fluidHandler The fluid handler to interact with.
* @param player The player doing the interaction between the item and fluid handler.
* @return a {@link FluidActionResult} holding the result and resulting container.
*/
@Nonnull
public static FluidActionResult interactWithFluidHandler(@Nonnull ItemStack stack, IFluidHandler fluidHandler, EntityPlayer player) {
if (stack.isEmpty() || fluidHandler == null || player == null) {
return FluidActionResult.FAILURE;
}
IItemHandler playerInventory = new InvWrapper(player.inventory);
FluidActionResult fillResult = tryFillContainerAndStow(stack, fluidHandler, playerInventory, Integer.MAX_VALUE, player);
if (fillResult.isSuccess()) {
return fillResult;
} else {
return tryEmptyContainerAndStow(stack, fluidHandler, playerInventory, Integer.MAX_VALUE, player);
}
}
use of net.minecraftforge.items.IItemHandler in project ImmersiveEngineering by BluSunrize.
the class Utils method insertStackIntoInventory.
public static ItemStack insertStackIntoInventory(TileEntity inventory, ItemStack stack, EnumFacing side) {
if (stack != null && inventory != null && inventory.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)) {
IItemHandler handler = inventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
ItemStack temp = ItemHandlerHelper.insertItem(handler, stack.copy(), true);
if (temp == null || temp.stackSize < stack.stackSize)
return ItemHandlerHelper.insertItem(handler, stack, false);
}
return stack;
}
use of net.minecraftforge.items.IItemHandler in project minecolonies by Minecolonies.
the class InventoryUtils method forceItemStackToProvider.
/**
* Adapted from {@link net.minecraft.entity.player.InventoryPlayer#addItemStackToInventory(ItemStack)}.
*
* @param provider {@link ICapabilityProvider} to add
* itemstack to.
* @param itemStack ItemStack to add.
* @param itemStackToKeepPredicate The {@link Predicate} that determines
* which ItemStacks to keep in the
* inventory. Return false to replace.
* @return itemStack which has been replaced.
*/
@Nullable
public static ItemStack forceItemStackToProvider(@NotNull final ICapabilityProvider provider, @NotNull final ItemStack itemStack, @NotNull final Predicate<ItemStack> itemStackToKeepPredicate) {
final ItemStack standardInsertionResult = addItemStackToProviderWithResult(provider, itemStack);
if (!isItemStackEmpty(standardInsertionResult)) {
ItemStack resultStack = standardInsertionResult.copy();
final Iterator<IItemHandler> iterator = getItemHandlersFromProvider(provider).iterator();
while (iterator.hasNext() && !isItemStackEmpty(resultStack)) {
resultStack = forceItemStackToItemHandler(iterator.next(), resultStack, itemStackToKeepPredicate);
}
return resultStack;
}
return EMPTY;
}
Aggregations