Search in sources :

Example 1 with NBTTagList

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);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) PotionEffect(net.minecraft.potion.PotionEffect) ItemStack(net.minecraft.item.ItemStack)

Example 2 with NBTTagList

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;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Entity(net.minecraft.entity.Entity) EntityLiving(net.minecraft.entity.EntityLiving) ItemStack(net.minecraft.item.ItemStack)

Example 3 with NBTTagList

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)));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) PotionEffect(net.minecraft.potion.PotionEffect) Potion(net.minecraft.potion.Potion) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 4 with NBTTagList

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);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 5 with NBTTagList

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);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

NBTTagList (net.minecraft.nbt.NBTTagList)451 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)385 ItemStack (net.minecraft.item.ItemStack)69 NBTTagString (net.minecraft.nbt.NBTTagString)42 BlockPos (net.minecraft.util.math.BlockPos)18 HashMap (java.util.HashMap)17 Map (java.util.Map)17 NotNull (org.jetbrains.annotations.NotNull)17 ArrayList (java.util.ArrayList)14 AMVector3 (am2.api.math.AMVector3)9 ChunkPosition (net.minecraft.world.ChunkPosition)9 NBTBase (net.minecraft.nbt.NBTBase)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 Vec3d (net.minecraft.util.math.Vec3d)7 WorldCoordinate (mods.railcraft.api.core.WorldCoordinate)6 Block (net.minecraft.block.Block)6 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)5 Entity (net.minecraft.entity.Entity)5 TileEntity (net.minecraft.tileentity.TileEntity)5 ChunkPos (net.minecraft.util.math.ChunkPos)5