use of net.minecraft.nbt.NBTTagList in project BetterStorage by copygirl.
the class ItemBucketSlime method onEaten.
@Override
public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) {
Handler handler = getHandler(stack);
if (handler != null) {
player.getFoodStats().addStats(handler.foodAmount(), handler.saturationAmount());
NBTTagList effectList = (NBTTagList) StackUtils.getTag(stack, "Effects");
if (effectList != null) {
for (int i = 0; i < effectList.tagCount(); i++) {
PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT(effectList.getCompoundTagAt(i));
int duration = (int) (effect.getDuration() * handler.durationMultiplier());
effect = new PotionEffect(effect.getPotionID(), duration, effect.getAmplifier());
player.addPotionEffect(effect);
}
}
handler.onEaten(player, false);
}
return new ItemStack(Items.bucket);
}
use of net.minecraft.nbt.NBTTagList 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.nbt.NBTTagList in project BetterStorage by copygirl.
the class ItemBucketSlime method addInformation.
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advancedTooltips) {
String id = getSlimeId(stack);
Handler handler = getHandler(id);
String name = StackUtils.get(stack, (String) null, "Slime", "name");
if ((name != null) || advancedTooltips)
list.add("Contains: " + ((name != null) ? ("\"" + name + "\"" + (advancedTooltips ? " (" + id + ")" : "")) : id));
NBTTagList effectList = (NBTTagList) StackUtils.getTag(stack, "Effects");
if ((effectList != null) && (handler != null)) {
int max = ((advancedTooltips || GuiScreen.isShiftKeyDown()) ? 6 : 3);
for (int i = 0; i < Math.min(effectList.tagCount(), max); i++) {
PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT(effectList.getCompoundTagAt(i));
Potion potion = Potion.potionTypes[effect.getPotionID()];
int duration = (int) (effect.getDuration() * handler.durationMultiplier());
StringBuilder str = new StringBuilder().append(potion.isBadEffect() ? EnumChatFormatting.RED : EnumChatFormatting.GRAY).append(StatCollector.translateToLocal(effect.getEffectName()));
if (effect.getAmplifier() > 0)
str.append(" ").append(StatCollector.translateToLocal("potion.potency." + effect.getAmplifier()));
str.append(" (").append(StringUtils.ticksToElapsedTime(duration)).append(")");
list.add(str.toString());
}
int more = (effectList.tagCount() - max);
if (more > 0)
list.add(EnumChatFormatting.DARK_GRAY.toString() + EnumChatFormatting.ITALIC + LanguageUtils.translateTooltip("bucketSlime.more." + ((more == 1) ? "1" : "x"), "%X%", Integer.toString(more)));
}
}
use of net.minecraft.nbt.NBTTagList in project compactsolars by cpw.
the class TileEntityCompactSolar method writeToNBT.
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < inventory.length; i++) {
if (inventory[i] != null) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
inventory[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
nbttagcompound.setTag("Items", nbttaglist);
energySource.onWriteToNbt(nbttagcompound);
}
use of net.minecraft.nbt.NBTTagList in project compactsolars by cpw.
the class TileEntityCompactSolar method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
energySource.onReadFromNbt(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
inventory = new ItemStack[getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); i++) {
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff;
if (j >= 0 && j < inventory.length) {
inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
}
Aggregations