Search in sources :

Example 11 with IPlantable

use of net.minecraftforge.common.IPlantable in project ArsMagica2 by Mithion.

the class Plant method GetAllSeedsInInventory.

private HashMap<Integer, ItemStack> GetAllSeedsInInventory(IInventory inventory) {
    HashMap<Integer, ItemStack> seeds = new HashMap<Integer, ItemStack>();
    for (int i = 0; i < inventory.getSizeInventory(); ++i) {
        ItemStack slotStack = inventory.getStackInSlot(i);
        if (slotStack == null)
            continue;
        Item item = slotStack.getItem();
        if (!(item instanceof IPlantable))
            continue;
        seeds.put(i, slotStack);
    }
    return seeds;
}
Also used : Item(net.minecraft.item.Item) HashMap(java.util.HashMap) IPlantable(net.minecraftforge.common.IPlantable) ItemStack(net.minecraft.item.ItemStack)

Example 12 with IPlantable

use of net.minecraftforge.common.IPlantable in project minecolonies by Minecolonies.

the class EntityAIWorkFarmer method plantCrop.

/**
     * Plants the crop at a given location.
     *
     * @param item     the crop.
     * @param position the location.
     */
private boolean plantCrop(final ItemStack item, @NotNull final BlockPos position) {
    final int slot = worker.findFirstSlotInInventoryWith(item.getItem(), item.getItemDamage());
    if (slot == -1) {
        return false;
    } else {
        @NotNull final IPlantable seed = (IPlantable) item.getItem();
        world.setBlockState(position.up(), seed.getPlant(world, position));
        new InvWrapper(getInventory()).extractItem(slot, 1, false);
        requestSeeds = false;
        //Flag 1+2 is needed for updates
        return true;
    }
}
Also used : InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IPlantable(net.minecraftforge.common.IPlantable) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with IPlantable

use of net.minecraftforge.common.IPlantable in project BluePower by Qmunity.

the class ItemSeedBag method onItemUse.

@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int posX, int posY, int posZ, int par7, float par8, float par9, float par10) {
    if (par2EntityPlayer.isSneaking()) {
        return false;
    }
    IInventory seedBagInventory = InventoryItem.getItemInventory(par2EntityPlayer, par2EntityPlayer.getCurrentEquippedItem(), "Seed Bag", 9);
    seedBagInventory.openInventory();
    ItemStack seed = getSeedType(par1ItemStack);
    if (seed != null && seed.getItem() instanceof IPlantable) {
        IPlantable plant = (IPlantable) seed.getItem();
        for (int modX = -2; modX < 3; modX++) {
            for (int modZ = -2; modZ < 3; modZ++) {
                Block b = par3World.getBlock(posX + modX, posY, posZ + modZ);
                if (b.canSustainPlant(par3World, posX, posY, posZ, ForgeDirection.UP, plant) && par3World.isAirBlock(posX + modX, posY + 1, posZ + modZ)) {
                    for (int i = 0; i < seedBagInventory.getSizeInventory(); i++) {
                        ItemStack is = seedBagInventory.getStackInSlot(i);
                        if (is != null) {
                            Item item = is.getItem();
                            item.onItemUse(is, par2EntityPlayer, par3World, posX + modX, posY, posZ + modZ, par7, par8 + modX, par9, par10 + modZ);
                            seedBagInventory.decrStackSize(i, 0);
                            break;
                        }
                    }
                }
            }
        }
        return true;
    }
    seedBagInventory.closeInventory();
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) Item(net.minecraft.item.Item) InventoryItem(com.bluepowermod.container.inventory.InventoryItem) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 14 with IPlantable

use of net.minecraftforge.common.IPlantable in project RFToolsDimensions by McJty.

the class KnownDimletConfiguration method getBlockFeatures.

public static Set<Filter.Feature> getBlockFeatures(Block block) {
    Set<Filter.Feature> features = EnumSet.noneOf(Filter.Feature.class);
    ItemStack stack = null;
    try {
        stack = new ItemStack(block, 1, OreDictionary.WILDCARD_VALUE);
    } catch (Exception e) {
        Logging.getLogger().log(Level.ERROR, "Failed to create a dimlet for block " + block.getRegistryName() + "! Please report to the correct mod!", e);
        return features;
    }
    int[] iDs = null;
    if (!stack.isEmpty() && stack.getItem() != null) {
        iDs = OreDictionary.getOreIDs(stack);
    }
    if (iDs != null && iDs.length > 0) {
        features.add(Filter.Feature.OREDICT);
    }
    if (block instanceof BlockFalling) {
        features.add(Filter.Feature.FALLING);
    }
    if (block.hasTileEntity(block.getDefaultState())) {
        features.add(Filter.Feature.TILEENTITY);
    }
    if (block instanceof IPlantable) {
        features.add(Filter.Feature.PLANTABLE);
    }
    if (!block.isFullBlock(block.getDefaultState())) {
        features.add(Filter.Feature.NOFULLBLOCK);
    }
    return features;
}
Also used : Filter(mcjty.rftoolsdim.config.Filter) IPlantable(net.minecraftforge.common.IPlantable) BlockFalling(net.minecraft.block.BlockFalling) ItemStack(net.minecraft.item.ItemStack)

Example 15 with IPlantable

use of net.minecraftforge.common.IPlantable in project AgriCraft by AgriCraft.

the class PlayerInteractEventHandler method vanillaSeedPlanting.

/**
 * Event handler to disable vanilla farming.
 *
 * @param event
 */
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void vanillaSeedPlanting(PlayerInteractEvent.RightClickBlock event) {
    // If not disabled, don't bother.
    if (!AgriCraftConfig.disableVanillaFarming) {
        return;
    }
    // Fetch the event itemstack.
    final ItemStack stack = event.getItemStack();
    // If the stack is null, or otherwise invalid, who cares?
    if (!StackHelper.isValid(stack)) {
        return;
    }
    // If the item in the player's hand is not a seed, who cares?
    if (!AgriApi.getSeedRegistry().hasAdapter(stack)) {
        return;
    }
    // Fetch world information.
    final BlockPos pos = event.getPos();
    final World world = event.getWorld();
    final IBlockState state = world.getBlockState(pos);
    // Fetch the block at the location.
    final Block block = state.getBlock();
    // If clicking crop block, who cares?
    if (block instanceof IAgriCrop) {
        return;
    }
    // If the item is an instance of IPlantable we need to perfom an extra check.
    if (stack.getItem() instanceof IPlantable) {
        // If the clicked block cannot support the given plant, then who cares?
        if (!block.canSustainPlant(state, world, pos, EnumFacing.UP, (IPlantable) stack.getItem())) {
            return;
        }
    }
    // If clicking crop tile, who cares?
    if (WorldHelper.getTile(event.getWorld(), event.getPos(), IAgriCrop.class).isPresent()) {
        return;
    }
    // The player is attempting to plant a seed, which is simply unacceptable.
    // We must deny this event.
    event.setUseItem(Event.Result.DENY);
    // If we are on the client side we are done.
    if (event.getSide().isClient()) {
        return;
    }
    // Should the server notify the player that vanilla farming has been disabled?
    if (AgriCraftConfig.showDisabledVanillaFarmingWarning) {
        MessageUtil.messagePlayer(event.getEntityPlayer(), "`7Vanilla planting is disabled!`r");
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IPlantable (net.minecraftforge.common.IPlantable)16 Block (net.minecraft.block.Block)12 IBlockState (net.minecraft.block.state.IBlockState)8 ItemStack (net.minecraft.item.ItemStack)6 BlockPos (net.minecraft.util.math.BlockPos)5 IGrowable (net.minecraft.block.IGrowable)4 Item (net.minecraft.item.Item)3 CABlock (convenientadditions.base.block.CABlock)2 BlockFarmland (net.minecraft.block.BlockFarmland)2 BlockLeaves (net.minecraft.block.BlockLeaves)2 IInventory (net.minecraft.inventory.IInventory)2 ItemBlock (net.minecraft.item.ItemBlock)2 World (net.minecraft.world.World)2 IShearable (net.minecraftforge.common.IShearable)2 Affinity (am2.api.spell.enums.Affinity)1 AMParticle (am2.particles.AMParticle)1 ParticleFloatUpward (am2.particles.ParticleFloatUpward)1 InventoryItem (com.bluepowermod.container.inventory.InventoryItem)1 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)1 HashMap (java.util.HashMap)1