package jp.plusplus.fbs.item; import jp.plusplus.fbs.FBS; import jp.plusplus.fbs.block.BlockCore; import jp.plusplus.fbs.entity.EntityButterfly; import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.Facing; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; /** * Created by plusplus_F on 2015/08/20. * ちょうちょ */ public class ItemButterfly extends ItemBase { public ItemButterfly() { setUnlocalizedName("butterfly"); setTextureName("butterfly"); } //Entityの生成 public static Entity spawnCreature(World par0World, int meta, double x, double y, double z) { Entity entity = null; entity = new EntityButterfly(par0World); EntityLiving entityliving = (EntityLiving) entity; entity.setLocationAndAngles(x, y, z, MathHelper.wrapAngleTo180_float(par0World.rand.nextFloat() * 360.0F), 0.0F); entityliving.rotationYawHead = entityliving.rotationYaw; entityliving.renderYawOffset = entityliving.rotationYaw; entityliving.onSpawnWithEgg((IEntityLivingData) null); par0World.spawnEntityInWorld(entity); entityliving.playLivingSound(); return entity; } @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { if (par2World.isRemote) { return par1ItemStack; } else { MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true); if (movingobjectposition == null) { return par1ItemStack; } else { if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { int i = movingobjectposition.blockX; int j = movingobjectposition.blockY; int k = movingobjectposition.blockZ; if (!par2World.canMineBlock(par3EntityPlayer, i, j, k)) { return par1ItemStack; } if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) { return par1ItemStack; } if (par2World.getBlock(i, j, k) instanceof BlockLiquid) { Entity entity = spawnCreature(par2World, par1ItemStack.getItemDamage(), (double) i, (double) j, (double) k); if (entity != null) { if (entity instanceof EntityLivingBase && par1ItemStack.hasDisplayName()) { ((EntityLiving) entity).setCustomNameTag(par1ItemStack.getDisplayName()); } if (!par3EntityPlayer.capabilities.isCreativeMode) { --par1ItemStack.stackSize; } } } } return par1ItemStack; } } } @Override public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int x, int y, int z, int side, float par8, float par9, float par10) { if (par3World.isRemote) { return true; } else { Block block = par3World.getBlock(x, y, z); x += Facing.offsetsXForSide[side]; y += Facing.offsetsYForSide[side]; z += Facing.offsetsZForSide[side]; //-------------------------------ポータル生成処理------------------------------- boolean genPortal=false; if(block==BlockCore.plank){ int sizeMax=4;//半径 int sizeU=0, sizeD=0, sizeL=0, sizeR=0; int sx=x, sy=y, sz=z; //縦方向に木材があるか boolean foundT=false, foundB=false; for(int i=0;i