use of net.mcft.copy.betterstorage.entity.EntityFrienderman in project BetterStorage by copygirl.
the class BackpackHandler method onSpecialSpawn.
@SubscribeEvent
public void onSpecialSpawn(SpecialSpawn event) {
// When a mob spawns naturally, see if it has a chance to spawn with a backpack.
EntityLivingBase entity = event.entityLiving;
World world = entity.worldObj;
double probability = 0.0;
for (BetterStorageBackpack.BackpackSpawnEntry entry : BetterStorageBackpack.spawnWithBackpack) {
if (!entity.getClass().equals(entry.entityClass))
continue;
probability = entry.probability;
break;
}
if (!RandomUtils.getBoolean(probability) || entity.isChild())
return;
// If entity is a vanilla enderman, replace it with a friendly one.
if (entity.getClass().equals(EntityEnderman.class)) {
if ((BetterStorageTiles.enderBackpack != null) && // Don't spawn friendly endermen in the end or end biome, would make them too easy to get.
(world.provider.dimensionId != 1) && (world.getBiomeGenForCoords((int) entity.posX, (int) entity.posZ) != BiomeGenBase.sky)) {
EntityFrienderman frienderman = new EntityFrienderman(world);
frienderman.setPositionAndRotation(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, 0);
world.spawnEntityInWorld(frienderman);
ItemBackpack.getBackpackData(frienderman).spawnsWithBackpack = true;
entity.setDead();
}
// Otherwise, just mark it to spawn with a backpack.
} else if (BetterStorageTiles.backpack != null)
ItemBackpack.getBackpackData(entity).spawnsWithBackpack = true;
}
use of net.mcft.copy.betterstorage.entity.EntityFrienderman 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);
}
Aggregations