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;
}
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;
}
}
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;
}
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;
}
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");
}
}
Aggregations