use of net.minecraftforge.common.IPlantable in project AgriCraft by AgriCraft.
the class TileEntitySprinkler method irrigate.
/**
* Depending on the block type either irrigates farmland or forces plant
* GROWTH (based on chance)
*/
private void irrigate(BlockPos pos, boolean farmlandOnly) {
IBlockState state = this.getWorld().getBlockState(pos);
Block block = state.getBlock();
if (block instanceof BlockFarmland && block.getMetaFromState(state) < 7) {
// irrigate farmland
int flag = counter == 0 ? 2 : 6;
worldObj.setBlockState(pos, block.getStateFromMeta(7), flag);
} else if (!farmlandOnly && ((block instanceof IPlantable) || (block instanceof IGrowable))) {
// X1 chance to force GROWTH tick on plant every Y1 ticks
if (counter == 0 && worldObj.rand.nextDouble() <= AgriCraftConfig.sprinklerGrowthChancePercent) {
block.updateTick(this.getWorld(), pos, state, worldObj.rand);
}
}
}
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 PneumaticCraft by MineMaarten.
the class EntityVortex method onUpdate.
@Override
public void onUpdate() {
oldMotionX = motionX;
oldMotionY = motionY;
oldMotionZ = motionZ;
super.onUpdate();
//blowOtherEntities();
// equal to the potion effect friction. 0.95F
motionX *= 0.95D;
motionY *= 0.95D;
motionZ *= 0.95D;
if (motionX * motionX + motionY * motionY + motionZ * motionZ < 0.1D) {
setDead();
}
if (!worldObj.isRemote) {
int blockX = (int) Math.floor(posX);
int blockY = (int) Math.floor(posY);
int blockZ = (int) Math.floor(posZ);
for (int i = 0; i < 7; i++) {
// to 7 so the middle block will also trigger (with UNKNOWN direction)
Block block = worldObj.getBlock(blockX + ForgeDirection.getOrientation(i).offsetX, blockY + ForgeDirection.getOrientation(i).offsetY, blockZ + ForgeDirection.getOrientation(i).offsetZ);
if (block instanceof IPlantable || block instanceof BlockLeaves) {
worldObj.func_147480_a(blockX + ForgeDirection.getOrientation(i).offsetX, blockY + ForgeDirection.getOrientation(i).offsetY, blockZ + ForgeDirection.getOrientation(i).offsetZ, true);
}
}
}
}
use of net.minecraftforge.common.IPlantable in project PneumaticCraft by MineMaarten.
the class EntityVortex method onImpact.
@Override
protected void onImpact(MovingObjectPosition objectPosition) {
if (objectPosition.entityHit != null) {
Entity entity = objectPosition.entityHit;
entity.motionX += motionX;
entity.motionY += motionY;
entity.motionZ += motionZ;
if (!entity.worldObj.isRemote && entity instanceof IShearable) {
IShearable shearable = (IShearable) entity;
int x = (int) Math.floor(posX);
int y = (int) Math.floor(posY);
int z = (int) Math.floor(posZ);
if (shearable.isShearable(null, worldObj, x, y, z)) {
List<ItemStack> drops = shearable.onSheared(null, worldObj, x, y, z, 0);
for (ItemStack stack : drops) {
PneumaticCraftUtils.dropItemOnGround(stack, worldObj, entity.posX, entity.posY, entity.posZ);
}
}
}
} else {
Block block = worldObj.getBlock(objectPosition.blockX, objectPosition.blockY, objectPosition.blockZ);
if (block instanceof IPlantable || block instanceof BlockLeaves) {
motionX = oldMotionX;
motionY = oldMotionY;
motionZ = oldMotionZ;
} else {
setDead();
}
}
hitCounter++;
if (hitCounter > 20)
setDead();
}
use of net.minecraftforge.common.IPlantable in project ArsMagica2 by Mithion.
the class Plant method applyEffectBlock.
@Override
public boolean applyEffectBlock(ItemStack stack, World world, int blockx, int blocky, int blockz, int blockFace, double impactX, double impactY, double impactZ, EntityLivingBase caster) {
Block soil = world.getBlock(blockx, blocky, blockz);
IInventory inventory = DummyEntityPlayer.fromEntityLiving(caster).inventory;
HashMap<Integer, ItemStack> seeds = GetAllSeedsInInventory(inventory);
int currentSlot = 0;
if (soil != Blocks.air && seeds.size() > 0) {
currentSlot = seeds.keySet().iterator().next();
ItemStack seedStack = seeds.get(currentSlot);
IPlantable seed = (IPlantable) seedStack.getItem();
if (soil != null && soil.canSustainPlant(world, blockx, blocky, blockz, ForgeDirection.UP, seed) && world.isAirBlock(blockx, blocky + 1, blockz)) {
world.setBlock(blockx, blocky + 1, blockz, seed.getPlant(world, blockx, blocky, blockz));
seedStack.stackSize--;
if (seedStack.stackSize <= 0) {
inventory.setInventorySlotContents(currentSlot, null);
seeds.remove(currentSlot);
if (seeds.size() == 0)
return true;
}
}
return true;
}
return false;
}
Aggregations