use of net.minecraft.entity.EntityLiving in project BetterStorage by copygirl.
the class CommonProxy method onEntityInteract.
@SubscribeEvent
public void onEntityInteract(EntityInteractEvent event) {
if (event.entity.worldObj.isRemote || event.isCanceled())
return;
EntityPlayer player = event.entityPlayer;
Entity target = event.target;
ItemStack holding = player.getCurrentEquippedItem();
if ((target.getClass() == EntityChicken.class) && (holding != null) && (holding.getItem() == Items.name_tag)) {
EntityChicken chicken = (EntityChicken) target;
if (!chicken.isDead && !chicken.isChild() && "Cluckington".equals(holding.getDisplayName()))
EntityCluckington.spawn(chicken);
}
if ((BetterStorageItems.slimeBucket != null) && (target instanceof EntityLiving) && (holding != null) && (holding.getItem() == Items.bucket)) {
ItemBucketSlime.pickUpSlime(player, (EntityLiving) target);
if (player.getCurrentEquippedItem().getItem() instanceof ItemBucketSlime)
preventSlimeBucketUse = true;
}
}
use of net.minecraft.entity.EntityLiving in project BetterStorage by copygirl.
the class ItemBucketSlime method onItemUse.
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
// instead of placing it in the world.
if (player.isSneaking())
return false;
if (world.isRemote)
return true;
x += Facing.offsetsXForSide[side];
y += Facing.offsetsYForSide[side];
z += Facing.offsetsZForSide[side];
String id = getSlimeId(stack);
String name = StackUtils.get(stack, (String) null, "Slime", "name");
Entity entity = EntityList.createEntityByName(id, world);
Handler handler = getHandler(id);
if ((entity != null) && (handler != null) && (entity instanceof EntityLiving)) {
EntityLiving slime = (EntityLiving) entity;
float rotation = MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F);
slime.setLocationAndAngles(x + 0.5, y, z + 0.5, rotation, 0.0F);
slime.rotationYawHead = slime.renderYawOffset = rotation;
if (name != null)
slime.setCustomNameTag(name);
handler.setSize(slime, 1);
NBTTagList effectList = (NBTTagList) StackUtils.getTag(stack, "Effects");
if (effectList != null)
for (int i = 0; i < effectList.tagCount(); i++) slime.addPotionEffect(PotionEffect.readCustomPotionEffectFromNBT(effectList.getCompoundTagAt(i)));
world.spawnEntityInWorld(slime);
slime.playSound("mob.slime.big", 1.2F, 0.6F);
player.setCurrentItemOrArmor(EquipmentSlot.HELD, new ItemStack(Items.bucket));
}
return true;
}
use of net.minecraft.entity.EntityLiving in project BetterStorage by copygirl.
the class BackpackHandler method onLivingUpdate.
@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event) {
EntityLivingBase entity = event.entityLiving;
EntityPlayer player = ((entity instanceof EntityPlayer) ? (EntityPlayer) entity : null);
ItemStack backpack = ItemBackpack.getBackpack(entity);
PropertiesBackpack backpackData;
if (backpack == null) {
backpackData = EntityUtils.getProperties(entity, PropertiesBackpack.class);
if (backpackData == null)
return;
// with a backpack, equip it with one.
if (backpackData.spawnsWithBackpack) {
ItemStack[] contents = null;
if (entity instanceof EntityFrienderman) {
backpack = new ItemStack(BetterStorageItems.itemEnderBackpack);
// Remove drop chance for the backpack.
((EntityLiving) entity).setEquipmentDropChance(EquipmentSlot.CHEST, 0.0F);
} else {
backpack = new ItemStack(BetterStorageItems.itemBackpack, 1, RandomUtils.getInt(120, 240));
ItemBackpack backpackType = (ItemBackpack) backpack.getItem();
if (RandomUtils.getBoolean(0.15)) {
// Give the backpack a random color.
int r = RandomUtils.getInt(32, 224);
int g = RandomUtils.getInt(32, 224);
int b = RandomUtils.getInt(32, 224);
int color = (r << 16) | (g << 8) | b;
StackUtils.set(backpack, color, "display", "color");
}
contents = new ItemStack[backpackType.getBackpackColumns() * backpackType.getBackpackRows()];
// Set drop chance for the backpack to 100%.
((EntityLiving) entity).setEquipmentDropChance(EquipmentSlot.CHEST, 1.0F);
}
// If the entity spawned with enchanted armor,
// move the enchantments over to the backpack.
ItemStack armor = entity.getEquipmentInSlot(EquipmentSlot.CHEST);
if (armor != null && armor.isItemEnchanted()) {
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("ench", armor.getTagCompound().getTag("ench"));
backpack.setTagCompound(compound);
}
if (contents != null) {
// Add random items to the backpack.
InventoryStacks inventory = new InventoryStacks(contents);
// Add normal random backpack loot.
WeightedRandomChestContent.generateChestContents(RandomUtils.random, randomBackpackItems, inventory, 20);
// With a chance of 10%, add some random dungeon loot.
if (RandomUtils.getDouble() < 0.1) {
ChestGenHooks info = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);
WeightedRandomChestContent.generateChestContents(RandomUtils.random, info.getItems(RandomUtils.random), inventory, 5);
}
}
ItemBackpack.setBackpack(entity, backpack, contents);
backpackData.spawnsWithBackpack = false;
} else {
// but still has some backpack data, drop the items.
if (backpackData.contents != null) {
for (ItemStack stack : backpackData.contents) WorldUtils.dropStackFromEntity(entity, stack, 1.5F);
backpackData.contents = null;
}
}
}
ItemBackpack.getBackpackData(entity).update(entity);
if (backpack != null)
((ItemBackpack) backpack.getItem()).onEquippedUpdate(entity, backpack);
}
use of net.minecraft.entity.EntityLiving in project SimplyJetpacks by Tonius.
the class EntityInteractHandler method onEntityInteract.
@SubscribeEvent
public void onEntityInteract(EntityInteractEvent evt) {
if (evt.entityPlayer.isSneaking() && (evt.target instanceof EntityZombie || evt.target instanceof EntitySkeleton)) {
EntityLiving target = (EntityLiving) evt.target;
ItemStack heldStack = evt.entityPlayer.getHeldItem();
if (heldStack != null && heldStack.getItem() instanceof ItemJetpack) {
if (!target.worldObj.isRemote) {
target.dropEquipment(true, 3);
}
target.setCurrentItemOrArmor(3, heldStack.copy());
target.equipmentDropChances[3] = 2.0F;
target.persistenceRequired = true;
evt.entityPlayer.getHeldItem().stackSize--;
}
}
}
use of net.minecraft.entity.EntityLiving in project PneumaticCraft by MineMaarten.
the class HackableLivingDisarm method onHackFinished.
@Override
public void onHackFinished(Entity entity, EntityPlayer player) {
if (!entity.worldObj.isRemote) {
Random rand = new Random();
if (fieldDropChance == null) {
fieldDropChance = ReflectionHelper.findField(EntityLiving.class, "field_82174_bp", "equipmentDropChances");
}
try {
float[] equipmentDropChances = (float[]) fieldDropChance.get(entity);
for (int i = 0; i < ((EntityLiving) entity).getLastActiveItems().length; i++) {
ItemStack stack = ((EntityLiving) entity).getLastActiveItems()[i];
float equipmentDropChance = equipmentDropChances[i];
boolean flag1 = equipmentDropChance > 1.0F;
if (stack != null && rand.nextFloat() < equipmentDropChance) {
if (!flag1 && stack.isItemStackDamageable()) {
int k = Math.max(stack.getMaxDamage() - 25, 1);
int l = stack.getMaxDamage() - rand.nextInt(rand.nextInt(k) + 1);
if (l > k) {
l = k;
}
if (l < 1) {
l = 1;
}
stack.setItemDamage(l);
}
entity.entityDropItem(stack, 0.0F);
}
((EntityLiving) entity).setCurrentItemOrArmor(i, null);
}
((EntityLiving) entity).setCanPickUpLoot(false);
} catch (Exception e) {
Log.error("Reflection failed on HackableLivingDisarm");
e.printStackTrace();
}
}
}
Aggregations