Search in sources :

Example 1 with TEString

use of com.eerussianguy.firmalife.te.TEString in project firmalife by eerussianguy.

the class BlockString method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote && hand == EnumHand.MAIN_HAND) {
        TEString te = Helpers.getTE(world, pos, TEString.class);
        if (te == null)
            return false;
        ItemStack held = player.getHeldItem(hand);
        if (held.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
            return false;
        IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        if (inv == null)
            return false;
        ItemStack current = inv.getStackInSlot(0);
        if (!held.isEmpty() && current.isEmpty()) {
            IFood cap = held.getCapability(CapabilityFood.CAPABILITY, null);
            if (cap != null) {
                List<FoodTrait> traits = cap.getTraits();
                boolean isFoodValid = (traits.contains(FoodTrait.BRINED) && OreDictionaryHelper.doesStackMatchOre(held, "categoryMeat") && HeatRecipe.get(held) != null) || OreDictionaryHelper.doesStackMatchOre(held, "cheese");
                if (!traits.contains(FoodDataFL.SMOKED) && isFoodValid) {
                    ItemStack leftover = inv.insertItem(0, held.splitStack(1), false);
                    Helpers.spawnItemStack(world, pos.add(0.5D, 0.5D, 0.5D), leftover);
                    te.markForSync();
                    return true;
                }
            }
        } else if (held.isEmpty() && !current.isEmpty()) {
            Helpers.spawnItemStack(world, pos, inv.extractItem(0, 1, false));
            te.markForSync();
            return true;
        }
    }
    return false;
}
Also used : IFood(net.dries007.tfc.api.capability.food.IFood) IItemHandler(net.minecraftforge.items.IItemHandler) FoodTrait(net.dries007.tfc.api.capability.food.FoodTrait) TEString(com.eerussianguy.firmalife.te.TEString) ItemStack(net.minecraft.item.ItemStack)

Example 2 with TEString

use of com.eerussianguy.firmalife.te.TEString in project firmalife by eerussianguy.

the class BlockString method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    TEString tile = Helpers.getTE(worldIn, pos, TEString.class);
    if (tile != null) {
        tile.resetCounter();
    }
    super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}
Also used : TEString(com.eerussianguy.firmalife.te.TEString)

Aggregations

TEString (com.eerussianguy.firmalife.te.TEString)2 FoodTrait (net.dries007.tfc.api.capability.food.FoodTrait)1 IFood (net.dries007.tfc.api.capability.food.IFood)1 ItemStack (net.minecraft.item.ItemStack)1 IItemHandler (net.minecraftforge.items.IItemHandler)1