mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-12 16:27:34 +00:00
Extrated grafter superclass from Thaumium Grafter so manasteel version can also do the thing with Thaumcraft trees.
61 lines
2.0 KiB
Java
61 lines
2.0 KiB
Java
package magicbees.item;
|
|
|
|
import magicbees.main.Config;
|
|
import magicbees.main.utils.compat.ThaumcraftHelper;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.item.EntityItem;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.world.World;
|
|
import forestry.api.arboriculture.IToolGrafter;
|
|
|
|
public class ItemGrafter extends Item implements IToolGrafter {
|
|
|
|
public ItemGrafter() {
|
|
super();
|
|
this.setMaxStackSize(1);
|
|
this.setCreativeTab(forestry.api.core.Tabs.tabArboriculture);
|
|
this.setHarvestLevel("grafter", 3);
|
|
}
|
|
|
|
@Override
|
|
public float getSaplingModifier(ItemStack stack, World world, EntityPlayer player, int x, int y, int z) {
|
|
return 100f;
|
|
}
|
|
|
|
@Override
|
|
public boolean onBlockDestroyed(ItemStack itemstack, World world, Block block, int x, int y, int z, EntityLivingBase entityLiving) {
|
|
int damage = 1;
|
|
if (ThaumcraftHelper.isActive()) {
|
|
if (block == Config.tcLeaf)
|
|
{
|
|
int meta = world.getBlockMetadata(x, y, z) & 1;
|
|
if (meta == 0 || meta == 1)
|
|
{
|
|
double chance = Math.random();
|
|
if (chance <= Config.thaumcraftSaplingDroprate)
|
|
{
|
|
this.dropItem(world, x, y, z, new ItemStack(Config.tcPlant, 1, meta));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
itemstack.damageItem(damage, entityLiving);
|
|
return true;
|
|
}
|
|
|
|
protected void dropItem(World world, int x, int y, int z, ItemStack item) {
|
|
if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
|
|
float f = 0.7F;
|
|
double d0 = (double)(world.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
|
double d1 = (double)(world.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
|
double d2 = (double)(world.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
|
EntityItem entityitem = new EntityItem(world, (double)x + d0, (double)y + d1, (double)z + d2, item);
|
|
entityitem.delayBeforeCanPickup = 10;
|
|
world.spawnEntityInWorld(entityitem);
|
|
}
|
|
}
|
|
|
|
} |