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;
}
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;
}
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];
}
}
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()]);
}
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());
}
Aggregations