Search in sources :

Example 1 with ExistingItemFilter

use of crazypants.enderio.base.filter.filters.ExistingItemFilter in project EnderIO by SleepyTrousers.

the class ItemExistingItemFilter method onItemUse.

@Override
@Nonnull
public EnumActionResult onItemUse(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumHand hand, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return EnumActionResult.SUCCESS;
    }
    if (player.isSneaking()) {
        IItemHandler externalInventory = ItemTools.getExternalInventory(world, pos, side);
        if (externalInventory != null) {
            ItemStack heldItem = player.getHeldItem(hand);
            ExistingItemFilter filter = (ExistingItemFilter) createFilterFromStack(heldItem);
            player.sendStatusMessage(filter.mergeSnapshot(externalInventory) ? Lang.ITEM_FILTER_UPDATED.toChatServer() : Lang.ITEM_FILTER_NOTUPDATED.toChatServer(), true);
            FilterRegistry.writeFilterToStack(filter, heldItem);
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) ExistingItemFilter(crazypants.enderio.base.filter.filters.ExistingItemFilter) Nonnull(javax.annotation.Nonnull)

Example 2 with ExistingItemFilter

use of crazypants.enderio.base.filter.filters.ExistingItemFilter in project EnderIO by SleepyTrousers.

the class ItemExistingItemFilter method createFilterFromStack.

@Override
public IItemFilter createFilterFromStack(@Nonnull ItemStack stack) {
    IItemFilter filter = new ExistingItemFilter();
    NBTTagCompound tag = NbtValue.FILTER.getTag(stack);
    filter.readFromNBT(tag);
    return filter;
}
Also used : IItemFilter(crazypants.enderio.base.filter.IItemFilter) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ExistingItemFilter(crazypants.enderio.base.filter.filters.ExistingItemFilter)

Aggregations

ExistingItemFilter (crazypants.enderio.base.filter.filters.ExistingItemFilter)2 IItemFilter (crazypants.enderio.base.filter.IItemFilter)1 Nonnull (javax.annotation.Nonnull)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 IItemHandler (net.minecraftforge.items.IItemHandler)1