You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
227 lines
8.0 KiB
Java
227 lines
8.0 KiB
Java
package net.minecraft.item;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockLiquid;
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityList;
|
|
import net.minecraft.entity.EntityLiving;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.IEntityLivingData;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.util.Facing;
|
|
import net.minecraft.util.IIcon;
|
|
import net.minecraft.util.MathHelper;
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
import net.minecraft.util.StatCollector;
|
|
import net.minecraft.world.World;
|
|
|
|
public class ItemMonsterPlacer extends Item
|
|
{
|
|
@SideOnly(Side.CLIENT)
|
|
private IIcon theIcon;
|
|
private static final String __OBFID = "CL_00000070";
|
|
|
|
public ItemMonsterPlacer()
|
|
{
|
|
this.setHasSubtypes(true);
|
|
this.setCreativeTab(CreativeTabs.tabMisc);
|
|
}
|
|
|
|
public String getItemStackDisplayName(ItemStack p_77653_1_)
|
|
{
|
|
String s = ("" + StatCollector.translateToLocal(this.getUnlocalizedName() + ".name")).trim();
|
|
String s1 = EntityList.getStringFromID(p_77653_1_.getItemDamage());
|
|
|
|
if (s1 != null)
|
|
{
|
|
s = s + " " + StatCollector.translateToLocal("entity." + s1 + ".name");
|
|
}
|
|
|
|
return s;
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public int getColorFromItemStack(ItemStack p_82790_1_, int p_82790_2_)
|
|
{
|
|
EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)EntityList.entityEggs.get(Integer.valueOf(p_82790_1_.getItemDamage()));
|
|
return entityegginfo != null ? (p_82790_2_ == 0 ? entityegginfo.primaryColor : entityegginfo.secondaryColor) : 16777215;
|
|
}
|
|
|
|
/**
|
|
* Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
|
|
* True if something happen and false if it don't. This is for ITEMS, not BLOCKS
|
|
*/
|
|
public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer p_77648_2_, World p_77648_3_, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_)
|
|
{
|
|
if (p_77648_3_.isRemote)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
Block block = p_77648_3_.getBlock(p_77648_4_, p_77648_5_, p_77648_6_);
|
|
p_77648_4_ += Facing.offsetsXForSide[p_77648_7_];
|
|
p_77648_5_ += Facing.offsetsYForSide[p_77648_7_];
|
|
p_77648_6_ += Facing.offsetsZForSide[p_77648_7_];
|
|
double d0 = 0.0D;
|
|
|
|
if (p_77648_7_ == 1 && block.getRenderType() == 11)
|
|
{
|
|
d0 = 0.5D;
|
|
}
|
|
|
|
Entity entity = spawnCreature(p_77648_3_, p_77648_1_.getItemDamage(), (double)p_77648_4_ + 0.5D, (double)p_77648_5_ + d0, (double)p_77648_6_ + 0.5D);
|
|
|
|
if (entity != null)
|
|
{
|
|
if (entity instanceof EntityLivingBase && p_77648_1_.hasDisplayName())
|
|
{
|
|
((EntityLiving)entity).setCustomNameTag(p_77648_1_.getDisplayName());
|
|
}
|
|
|
|
if (!p_77648_2_.capabilities.isCreativeMode)
|
|
{
|
|
--p_77648_1_.stackSize;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
|
*/
|
|
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer player)
|
|
{
|
|
if (worldIn.isRemote)
|
|
{
|
|
return itemStackIn;
|
|
}
|
|
else
|
|
{
|
|
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, player, true);
|
|
|
|
if (movingobjectposition == null)
|
|
{
|
|
return itemStackIn;
|
|
}
|
|
else
|
|
{
|
|
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
|
{
|
|
int i = movingobjectposition.blockX;
|
|
int j = movingobjectposition.blockY;
|
|
int k = movingobjectposition.blockZ;
|
|
|
|
if (!worldIn.canMineBlock(player, i, j, k))
|
|
{
|
|
return itemStackIn;
|
|
}
|
|
|
|
if (!player.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStackIn))
|
|
{
|
|
return itemStackIn;
|
|
}
|
|
|
|
if (worldIn.getBlock(i, j, k) instanceof BlockLiquid)
|
|
{
|
|
Entity entity = spawnCreature(worldIn, itemStackIn.getItemDamage(), (double)i, (double)j, (double)k);
|
|
|
|
if (entity != null)
|
|
{
|
|
if (entity instanceof EntityLivingBase && itemStackIn.hasDisplayName())
|
|
{
|
|
((EntityLiving)entity).setCustomNameTag(itemStackIn.getDisplayName());
|
|
}
|
|
|
|
if (!player.capabilities.isCreativeMode)
|
|
{
|
|
--itemStackIn.stackSize;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return itemStackIn;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Spawns the creature specified by the egg's type in the location specified by the last three parameters.
|
|
* Parameters: world, entityID, x, y, z.
|
|
*/
|
|
public static Entity spawnCreature(World p_77840_0_, int p_77840_1_, double p_77840_2_, double p_77840_4_, double p_77840_6_)
|
|
{
|
|
if (!EntityList.entityEggs.containsKey(Integer.valueOf(p_77840_1_)))
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
Entity entity = null;
|
|
|
|
for (int j = 0; j < 1; ++j)
|
|
{
|
|
entity = EntityList.createEntityByID(p_77840_1_, p_77840_0_);
|
|
|
|
if (entity != null && entity instanceof EntityLivingBase)
|
|
{
|
|
EntityLiving entityliving = (EntityLiving)entity;
|
|
entity.setLocationAndAngles(p_77840_2_, p_77840_4_, p_77840_6_, MathHelper.wrapAngleTo180_float(p_77840_0_.rand.nextFloat() * 360.0F), 0.0F);
|
|
entityliving.rotationYawHead = entityliving.rotationYaw;
|
|
entityliving.renderYawOffset = entityliving.rotationYaw;
|
|
entityliving.onSpawnWithEgg((IEntityLivingData)null);
|
|
p_77840_0_.spawnEntityInWorld(entity);
|
|
entityliving.playLivingSound();
|
|
}
|
|
}
|
|
|
|
return entity;
|
|
}
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public boolean requiresMultipleRenderPasses()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Gets an icon index based on an item's damage value and the given render pass
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public IIcon getIconFromDamageForRenderPass(int p_77618_1_, int p_77618_2_)
|
|
{
|
|
return p_77618_2_ > 0 ? this.theIcon : super.getIconFromDamageForRenderPass(p_77618_1_, p_77618_2_);
|
|
}
|
|
|
|
/**
|
|
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public void getSubItems(Item p_150895_1_, CreativeTabs p_150895_2_, List p_150895_3_)
|
|
{
|
|
Iterator iterator = EntityList.entityEggs.values().iterator();
|
|
|
|
while (iterator.hasNext())
|
|
{
|
|
EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)iterator.next();
|
|
p_150895_3_.add(new ItemStack(p_150895_1_, 1, entityegginfo.spawnedID));
|
|
}
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public void registerIcons(IIconRegister register)
|
|
{
|
|
super.registerIcons(register);
|
|
this.theIcon = register.registerIcon(this.getIconString() + "_overlay");
|
|
}
|
|
} |