use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class ModelDrinkingHelmet method render.
@Override
public void render(Entity entity, float v1, float v2, float v3, float v4, float v5, float v6) {
ItemStack[] potions = new ItemStack[2];
if (entity instanceof EntityLivingBase) {
ItemStack drinkingHelmet = ItemDrinkingHelmet.getDrinkingHelmet((EntityLivingBase) entity);
// rendering in the enchantment effect render pass.
if (!drinkingHelmet.isItemEnchanted() || (pass++ == 0))
potions = ItemDrinkingHelmet.getPotions(drinkingHelmet);
else if (pass > 2)
pass = 0;
}
left.stack = potions[0];
right.stack = potions[1];
setRotationAngles(v1, v2, v3, v4, v5, v6, entity);
bipedHead.render(v6);
}
use of net.minecraft.item.ItemStack 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.item.ItemStack in project BetterStorage by copygirl.
the class BackpackHandler method onPlayerRespawn.
@SubscribeEvent
public void onPlayerRespawn(PlayerRespawnEvent event) {
// If the player dies when when keepInventory is on and respawns,
// retrieve the backpack items from eir persistent NBT tag.
NBTTagCompound entityData = event.player.getEntityData();
if (!entityData.hasKey(EntityPlayer.PERSISTED_NBT_TAG))
return;
NBTTagCompound persistent = entityData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
if (!persistent.hasKey("Backpack"))
return;
NBTTagCompound compound = persistent.getCompoundTag("Backpack");
PropertiesBackpack backpackData = ItemBackpack.getBackpackData(event.player);
int size = compound.getInteger("count");
ItemStack[] contents = new ItemStack[size];
NbtUtils.readItems(contents, compound.getTagList("Items", NBT.TAG_COMPOUND));
backpackData.contents = contents;
if (compound.hasKey("Stack"))
backpackData.backpack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("Stack"));
persistent.removeTag("Backpack");
if (persistent.hasNoTags())
entityData.removeTag(EntityPlayer.PERSISTED_NBT_TAG);
}
use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class CardboardEnchantmentRecipe method makeEnchantedBook.
private ItemStack makeEnchantedBook(Enchantment ench, int level) {
ItemStack book = new ItemStack(Items.enchanted_book);
((ItemEnchantedBook) book.getItem()).addEnchantment(book, new EnchantmentData(ench, level));
return book;
}
use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class CardboardEnchantmentRecipe method checkMatch.
@Override
public StationCrafting checkMatch(ItemStack[] input, RecipeBounds bounds) {
// Quick check if input matches the recipe.
boolean hasCardboardItems = false;
int bookIndex = -1;
ItemStack book = null;
for (int i = 0; i < input.length; i++) {
ItemStack stack = input[i];
if (stack == null)
continue;
if (stack.getItem() instanceof ICardboardItem)
hasCardboardItems = true;
else if ((book == null) && (stack.getItem() == Items.enchanted_book)) {
bookIndex = i;
book = stack;
} else
return null;
}
if ((book == null) || !hasCardboardItems)
return null;
// Basic items match the recipe,
// do more expensive stuff now.
ItemStack[] output = new ItemStack[9];
int experienceCost = 0;
IRecipeInput[] requiredInput = new IRecipeInput[9];
Collection<StackEnchantment> bookEnchantments = StackUtils.getEnchantments(book).values();
for (int i = 0; i < input.length; i++) {
ItemStack stack = input[i];
if ((stack == null) || !(stack.getItem() instanceof ICardboardItem))
continue;
ItemStack outputStack = stack.copy();
boolean canApply = false;
Map<Integer, StackEnchantment> stackEnchants = StackUtils.getEnchantments(outputStack);
int numEnchants = stackEnchants.size();
for (StackEnchantment bookEnch : bookEnchantments) {
if (!StackUtils.isEnchantmentCompatible(outputStack, stackEnchants.values(), bookEnch))
continue;
StackEnchantment stackEnch = stackEnchants.get(bookEnch.ench.effectId);
// Calculate enchantment cost.
int level = (bookEnch.getLevel() - ((stackEnch != null) ? stackEnch.getLevel() : 0));
experienceCost += calculateCost(bookEnch, (stackEnch == null), numEnchants);
// Set enchantment level of output item.
if (stackEnch != null)
stackEnch.setLevel(bookEnch.getLevel());
else
outputStack.addEnchantment(bookEnch.ench, bookEnch.getLevel());
canApply = true;
}
// be applied on the item, the recipe is invalid.
if (!canApply)
return null;
output[i] = outputStack;
requiredInput[i] = new RecipeInputItemStack(StackUtils.copyStack(stack, 1), true);
}
requiredInput[bookIndex] = new RecipeInputItemStack(StackUtils.copyStack(book, 0, false));
return new StationCrafting(output, requiredInput, experienceCost);
}
Aggregations