Search in sources :

Example 46 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.

the class TileEntityElectricCompressor method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbtTagCompound) {
    super.writeToNBT(nbtTagCompound);
    nbtTagCompound.setInteger("redstoneMode", redstoneMode);
    nbtTagCompound.setBoolean("outputTimer", outputTimer > 0);
    nbtTagCompound.setFloat("turbineSpeed", turbineSpeed);
    nbtTagCompound.setInteger("energyProduction", lastEnergyProduction);
    // Write the ItemStacks in the inventory to NBT
    NBTTagList tagList = new NBTTagList();
    for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) {
        if (inventory[currentIndex] != null) {
            NBTTagCompound tagCompound = new NBTTagCompound();
            tagCompound.setByte("Slot", (byte) currentIndex);
            inventory[currentIndex].writeToNBT(tagCompound);
            tagList.appendTag(tagCompound);
        }
    }
    nbtTagCompound.setTag("Items", tagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 47 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.

the class WailaHeatHandler method getNBTData.

@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z) {
    if (te instanceof IHeatExchanger) {
        Set<IHeatExchangerLogic> heatExchangers = new HashSet<IHeatExchangerLogic>();
        IHeatExchangerLogic logic = null;
        boolean isMultisided = true;
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            logic = ((IHeatExchanger) te).getHeatExchangerLogic(d);
            if (logic != null) {
                if (heatExchangers.contains(logic)) {
                    isMultisided = false;
                    break;
                } else {
                    heatExchangers.add(logic);
                }
            }
        }
        if (isMultisided) {
            NBTTagList tagList = new NBTTagList();
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                logic = ((IHeatExchanger) te).getHeatExchangerLogic(d);
                if (logic != null) {
                    NBTTagCompound heatTag = new NBTTagCompound();
                    heatTag.setByte("side", (byte) d.ordinal());
                    heatTag.setInteger("temp", (int) logic.getTemperature());
                    tagList.appendTag(heatTag);
                }
            }
            tag.setTag("heat", tagList);
        } else if (logic != null) {
            tag.setInteger("temp", (int) logic.getTemperature());
        }
    }
    return tag;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IHeatExchanger(pneumaticCraft.api.tileentity.IHeatExchanger) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IHeatExchangerLogic(pneumaticCraft.api.IHeatExchangerLogic) HashSet(java.util.HashSet)

Example 48 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.

the class TileEntityPneumaticGenerator method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbtTagCompound) {
    super.writeToNBT(nbtTagCompound);
    nbtTagCompound.setInteger("redstoneMode", redstoneMode);
    nbtTagCompound.setBoolean("outputting", outputting);
    nbtTagCompound.setInteger("energyProduction", curEnergyProduction);
    // Write the ItemStacks in the inventory to NBT
    NBTTagList tagList = new NBTTagList();
    for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) {
        if (inventory[currentIndex] != null) {
            NBTTagCompound tagCompound = new NBTTagCompound();
            tagCompound.setByte("Slot", (byte) currentIndex);
            inventory[currentIndex].writeToNBT(tagCompound);
            tagList.appendTag(tagCompound);
        }
    }
    nbtTagCompound.setTag("Items", tagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 49 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.

the class TileEntityAirCannon method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound tag) {
    super.writeToNBT(tag);
    tag.setBoolean("redstonePowered", redstonePowered);
    tag.setFloat("targetRotationAngle", targetRotationAngle);
    tag.setFloat("targetHeightAngle", targetHeightAngle);
    tag.setFloat("rotationAngle", rotationAngle);
    tag.setFloat("heightAngle", heightAngle);
    tag.setInteger("gpsX", gpsX);
    tag.setInteger("gpsY", gpsY);
    tag.setInteger("gpsZ", gpsZ);
    tag.setByte("redstoneMode", (byte) redstoneMode);
    tag.setBoolean("targetWithinReach", coordWithinReach);
    // Write the ItemStacks in the inventory to NBT
    NBTTagList tagList = new NBTTagList();
    for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) {
        if (inventory[currentIndex] != null) {
            NBTTagCompound tagCompound = new NBTTagCompound();
            tagCompound.setByte("Slot", (byte) currentIndex);
            inventory[currentIndex].writeToNBT(tagCompound);
            tagList.appendTag(tagCompound);
        }
    }
    tag.setTag("Items", tagList);
    tagList = new NBTTagList();
    for (EntityItem entity : trackedItems) {
        UUID uuid = entity.getUniqueID();
        NBTTagCompound t = new NBTTagCompound();
        t.setLong("UUIDMost", uuid.getMostSignificantBits());
        t.setLong("UUIDLeast", uuid.getLeastSignificantBits());
        tagList.appendTag(t);
    }
    tag.setTag("trackedItems", tagList);
    if (lastInsertingInventory != null) {
        tag.setInteger("inventoryX", lastInsertingInventory.chunkPosX);
        tag.setInteger("inventoryY", lastInsertingInventory.chunkPosY);
        tag.setInteger("inventoryZ", lastInsertingInventory.chunkPosZ);
        tag.setByte("inventorySide", (byte) lastInsertingInventorySide.ordinal());
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) UUID(java.util.UUID) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint) EntityItem(net.minecraft.entity.item.EntityItem)

Example 50 with NBTTagList

use of net.minecraft.nbt.NBTTagList in project PneumaticCraft by MineMaarten.

the class TileEntityAirCannon method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound tag) {
    super.readFromNBT(tag);
    redstonePowered = tag.getBoolean("redstonePowered");
    targetRotationAngle = tag.getFloat("targetRotationAngle");
    targetHeightAngle = tag.getFloat("targetHeightAngle");
    rotationAngle = tag.getFloat("rotationAngle");
    heightAngle = tag.getFloat("heightAngle");
    gpsX = tag.getInteger("gpsX");
    gpsY = tag.getInteger("gpsY");
    gpsZ = tag.getInteger("gpsZ");
    if (tag.hasKey("fireOnRightAngle")) {
        //TODO remove legacy
        redstoneMode = tag.getBoolean("fireOnRightAngle") ? 0 : 1;
    } else {
        redstoneMode = tag.getByte("redstoneMode");
    }
    coordWithinReach = tag.getBoolean("targetWithinReach");
    // Read in the ItemStacks in the inventory from NBT
    NBTTagList tagList = tag.getTagList("Items", 10);
    inventory = new ItemStack[getSizeInventory()];
    for (int i = 0; i < tagList.tagCount(); ++i) {
        NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
        byte slot = tagCompound.getByte("Slot");
        if (slot >= 0 && slot < inventory.length) {
            inventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
        }
    }
    trackedItemIds = new HashSet<UUID>();
    tagList = tag.getTagList("trackedItems", 10);
    for (int i = 0; i < tagList.tagCount(); i++) {
        NBTTagCompound t = tagList.getCompoundTagAt(i);
        trackedItemIds.add(new UUID(t.getLong("UUIDMost"), t.getLong("UUIDLeast")));
    }
    if (tag.hasKey("inventoryX")) {
        lastInsertingInventory = new ChunkPosition(tag.getInteger("inventoryX"), tag.getInteger("inventoryY"), tag.getInteger("inventoryZ"));
        lastInsertingInventorySide = ForgeDirection.getOrientation(tag.getByte("inventorySide"));
    } else {
        lastInsertingInventory = null;
        lastInsertingInventorySide = null;
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ChunkPosition(net.minecraft.world.ChunkPosition) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) UUID(java.util.UUID) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint)

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