Search in sources :

Example 96 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound in project Railcraft by Railcraft.

the class ItemEnergyContainer method receiveEnergy.

/* IEnergyContainerItem */
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
    if (!container.hasTagCompound()) {
        container.setTagCompound(new NBTTagCompound());
    }
    int energy = container.getTagCompound().getInteger("Energy");
    int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
    if (!simulate) {
        energy += energyReceived;
        container.getTagCompound().setInteger("Energy", energy);
    }
    return energyReceived;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 97 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound in project Railcraft by Railcraft.

the class TileThaumcraft method getUpdateTag.

@Override
public NBTTagCompound getUpdateTag() {
    NBTTagCompound nbt = new NBTTagCompound();
    this.writeCustomNBT(nbt);
    return nbt;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 98 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound in project Railcraft by Railcraft.

the class SchematicBlock method readRequirementsFromNBT.

protected void readRequirementsFromNBT(NBTTagCompound nbt, MappingRegistry registry) {
    if (nbt.hasKey("rq")) {
        NBTTagList rq = nbt.getTagList("rq", Constants.NBT.TAG_COMPOUND);
        ArrayList<ItemStack> rqs = new ArrayList<ItemStack>();
        for (int i = 0; i < rq.tagCount(); ++i) {
            try {
                NBTTagCompound sub = rq.getCompoundTagAt(i);
                registry.stackToWorld(sub);
                rqs.add(ItemStack.loadItemStackFromNBT(sub));
            } catch (MappingNotFoundException e) {
                defaultPermission = BuildingPermission.CREATIVE_ONLY;
            } catch (Throwable t) {
                t.printStackTrace();
                defaultPermission = BuildingPermission.CREATIVE_ONLY;
            }
        }
        storedRequirements = rqs.toArray(new ItemStack[rqs.size()]);
    } else {
        storedRequirements = new ItemStack[0];
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 99 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound in project Railcraft by Railcraft.

the class SchematicEntity method readSchematicFromNBT.

@Override
public void readSchematicFromNBT(NBTTagCompound nbt, MappingRegistry registry) {
    super.readSchematicFromNBT(nbt, registry);
    entityNBT = nbt.getCompoundTag("entity");
    NBTTagList rq = nbt.getTagList("rq", Constants.NBT.TAG_COMPOUND);
    ArrayList<ItemStack> rqs = new ArrayList<ItemStack>();
    for (int i = 0; i < rq.tagCount(); ++i) {
        try {
            NBTTagCompound sub = rq.getCompoundTagAt(i);
            if (sub.getInteger("id") >= 0) {
                // Maps the id in the blueprint to the id in the world
                sub.setInteger("id", Item.REGISTRY.getIDForObject(registry.getItemForId(sub.getInteger("id"))));
                rqs.add(ItemStack.loadItemStackFromNBT(sub));
            } else {
                defaultPermission = BuildingPermission.CREATIVE_ONLY;
            }
        } catch (Throwable t) {
            t.printStackTrace();
            defaultPermission = BuildingPermission.CREATIVE_ONLY;
        }
    }
    storedRequirements = rqs.toArray(new ItemStack[rqs.size()]);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 100 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound in project Railcraft by Railcraft.

the class Identifier method getFor.

public static Identifier getFor(Object obj) {
    if (obj == null)
        throw new NullPointerException("obj");
    if (obj instanceof TileEntity) {
        return Tile.create((TileEntity) obj);
    }
    if (obj instanceof Entity) {
        return MovableEntity.create((Entity) obj);
    }
    if (obj instanceof NBTTagCompound) {
        NBTTagCompound nbt = (NBTTagCompound) obj;
        String type = nbt.getString("type");
        if (!registeredIdentifiers.containsKey(type))
            return null;
        return registeredIdentifiers.get(type).get().load(nbt.getCompoundTag("data"));
    }
    throw new IllegalArgumentException("Unknown type " + obj.getClass());
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3985 NBTTagList (net.minecraft.nbt.NBTTagList)1052 ItemStack (net.minecraft.item.ItemStack)883 BlockPos (net.minecraft.util.math.BlockPos)229 TileEntity (net.minecraft.tileentity.TileEntity)173 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)148 ArrayList (java.util.ArrayList)99 Block (net.minecraft.block.Block)98 ResourceLocation (net.minecraft.util.ResourceLocation)96 IBlockState (net.minecraft.block.state.IBlockState)92 EntityPlayer (net.minecraft.entity.player.EntityPlayer)81 NBTTagString (net.minecraft.nbt.NBTTagString)79 Nonnull (javax.annotation.Nonnull)74 Map (java.util.Map)71 UUID (java.util.UUID)69 NBTBase (net.minecraft.nbt.NBTBase)66 HashMap (java.util.HashMap)64 EnumFacing (net.minecraft.util.EnumFacing)61 NotNull (org.jetbrains.annotations.NotNull)60 Item (net.minecraft.item.Item)55