Java Code Examples for net.minecraft.nbt.NBTTagCompound

The following examples show how to use net.minecraft.nbt.NBTTagCompound. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Kettle   Source File: CraftOfflinePlayer.java    License: GNU General Public License v3.0 6 votes vote down vote up
public String getName() {
    Player player = getPlayer();
    if (player != null) {
        return player.getName();
    }

    // This might not match lastKnownName but if not it should be more correct
    if (profile.getName() != null) {
        return profile.getName();
    }

    NBTTagCompound data = getBukkitData();

    if (data != null) {
        if (data.hasKey("lastKnownName")) {
            return data.getString("lastKnownName");
        }
    }

    return null;
}
 
Example 2
Source Project: BigReactors   Source File: TileEntityBeefBase.java    License: MIT License 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound tag) {
	super.readFromNBT(tag);
	
	// Rotation
	if(tag.hasKey("facing")) {
		facing = Math.max(0, Math.min(5, tag.getInteger("facing")));
	}
	else {
		facing = 2;
	}

	// Exposure settings
	if(tag.hasKey("exposures")) {
		int[] tagExposures = tag.getIntArray("exposures");
		assert(tagExposures.length == exposures.length);
		System.arraycopy(tagExposures, 0, exposures, 0, exposures.length);
	}
}
 
Example 3
@Override
public void setWorld(World world) {
	net.minecraft.world.World oldWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(this.world);
	net.minecraft.world.World newWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(world);
	Optional<TileEntity> tileEntity = Optional.ofNullable(oldWorld.getTileEntity((int) position.getX(), (int) position.getY(), (int) position.getZ()));
	Optional<NBTTagCompound> nbt = Optional.empty();
	if (tileEntity.isPresent()) {
		NBTTagCompound compound = new NBTTagCompound();
		tileEntity.get().writeToNBT(compound);
		nbt = Optional.of(compound);
	}
	newWorld.setBlock((int) position.getX(), (int) position.getY(), (int) position.getZ(), block.mcBlock, block.getMetadata(), 3);
	oldWorld.removeTileEntity((int) position.getX(), (int) position.getY(), (int) position.getZ());
	oldWorld.setBlockToAir((int) position.getX(), (int) position.getY(), (int) position.getZ());
	Optional<TileEntity> newTileEntity = Optional.ofNullable(newWorld.getTileEntity((int) position.getX(), (int) position.getY(), (int) position.getZ()));
	if (newTileEntity.isPresent() && nbt.isPresent()) {
		newTileEntity.get().readFromNBT(nbt.get());
	}
	this.world = world;
}
 
Example 4
Source Project: Production-Line   Source File: ItemBlockEUStorage.java    License: MIT License 6 votes vote down vote up
/**
 * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
 */
@SideOnly(Side.CLIENT)
@Override
public void getSubItems(@Nonnull Item item, @Nonnull CreativeTabs creativeTabs, @Nonnull List<ItemStack> list) {
    super.getSubItems(item, creativeTabs, list);
    ItemStack itemStack;
    NBTTagCompound nbt;

    itemStack = PLBlocks.evsu.copy();
    nbt = StackUtil.getOrCreateNbtData(itemStack);
    nbt.setInteger("energy", (int) 1E8);
    list.add(itemStack);

    itemStack = PLBlocks.cseu.copy();
    nbt = StackUtil.getOrCreateNbtData(itemStack);
    nbt.setInteger("energy", (int) 720E3);
    list.add(itemStack);

    itemStack = PLBlocks.parallelSpaceSU.copy();
    nbt = StackUtil.getOrCreateNbtData(itemStack);
    nbt.setInteger("energy", (int) 2E8);
    list.add(itemStack);
}
 
Example 5
Source Project: PneumaticCraft   Source File: ItemGPSTool.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List infoList, boolean par4){
    super.addInformation(stack, player, infoList, par4);
    NBTTagCompound compound = stack.stackTagCompound;
    if(compound != null) {
        int x = compound.getInteger("x");
        int y = compound.getInteger("y");
        int z = compound.getInteger("z");
        if(x != 0 || y != 0 || z != 0) {
            infoList.add("\u00a72Set to " + x + ", " + y + ", " + z);
        }
        String varName = getVariable(stack);
        if(!varName.equals("")) {
            infoList.add(I18n.format("gui.tooltip.gpsTool.variable", varName));
        }
    }
}
 
Example 6
Source Project: Cyberware   Source File: CyberwareDataHandler.java    License: MIT License 6 votes vote down vote up
@SubscribeEvent
public void startTrackingEvent(StartTracking event)
{			
	EntityPlayer tracker = event.getEntityPlayer();
	Entity target = event.getTarget();
	
	if (!target.worldObj.isRemote)
	{
		if (CyberwareAPI.hasCapability(target))
		{
			if (target instanceof EntityPlayer)
			{
				//System.out.println("Sent data for player " + ((EntityPlayer) target).getName() + " to player " + tracker.getName());
			}

			NBTTagCompound nbt = CyberwareAPI.getCapability(target).serializeNBT();
			CyberwarePacketHandler.INSTANCE.sendTo(new CyberwareSyncPacket(nbt, target.getEntityId()), (EntityPlayerMP) tracker);
		}
	}
	
}
 
Example 7
Source Project: Logistics-Pipes-2   Source File: LPRoutedItem.java    License: MIT License 6 votes vote down vote up
public NBTTagCompound writeToNBT() {
	NBTTagCompound tag = new NBTTagCompound();
	Triple<Double, Double, Double> pos = getPosition();
	tag.setDouble("posX", pos.getFirst());
	tag.setDouble("posY", pos.getSecnd());
	tag.setDouble("posZ", pos.getThird());
	tag.setInteger("heading", heading.ordinal());
	tag.setUniqueId("UID", this.ID);
	tag.setTag("inventory", stack.serializeNBT());
	tag.setInteger("ticks", this.ticks);
	NBTTagList routeList = new NBTTagList();
	for(EnumFacing node : route) {
		NBTTagCompound nodeTag = new NBTTagCompound();
		//nodeTag.setUniqueId("UID", node.getKey());
		nodeTag.setInteger("heading", node.ordinal());
		routeList.appendTag(nodeTag);
	}
	tag.setTag("route", routeList);
	return tag;
}
 
Example 8
@Override
public void readEntityFromNBT(NBTTagCompound nbttagcompound)
{
	super.readEntityFromNBT(nbttagcompound);
	setRideable(nbttagcompound.getBoolean("Saddle"));
	setIsChested(nbttagcompound.getBoolean("Chested"));
	setArmorType(nbttagcompound.getByte("ArmorType"));
	setSitting(nbttagcompound.getBoolean("isSitting"));
	if (getIsChested())
	{
		NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
		localchest = new MoCAnimalChest("WyvernChest", 14);
		for (int i = 0; i < nbttaglist.tagCount(); i++)
		{
			NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
			int j = nbttagcompound1.getByte("Slot") & 0xff;
			if ((j >= 0) && j < localchest.getSizeInventory())
			{
				localchest.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound1));
			}
		}
	}
}
 
Example 9
Source Project: OpenPeripheral-Integration   Source File: SafariNetMetaProvider.java    License: MIT License 6 votes vote down vote up
@Override
public Object getMeta(Item target, ItemStack stack) {
	Map<String, Object> result = Maps.newHashMap();

	String type = safariNets.get(target.getUnlocalizedName());
	result.put("type", Objects.firstNonNull(type, "unknown"));

	NBTTagCompound tag = stack.getTagCompound();
	if (tag != null) {
		if (tag.getBoolean("hide")) {
			result.put("captured", "?");
		} else if (tag.hasKey("id", Constants.NBT.TAG_STRING)) {
			result.put("captured", tag.getString("id"));
		}
	}

	return result;
}
 
Example 10
@Override
public NBTTagCompound serializeNBT() {
	NBTTagCompound compound = new NBTTagCompound();

	compound.setTag("spell_object_manager", spellObjectManager.manager.toNbt());

	NBTTagList driveNBT = new NBTTagList();
	for (Map.Entry<BlockPos, NemezTracker> entry : blockNemezDrives.entrySet()) {
		if (entry == null) continue;
		NBTTagCompound compound1 = new NBTTagCompound();
		compound1.setLong("pos", entry.getKey().toLong());
		compound1.setTag("drive", entry.getValue().serializeNBT());
		driveNBT.appendTag(compound1);
	}

	compound.setTag("drives", driveNBT);
	return compound;
}
 
Example 11
Source Project: Sakura_mod   Source File: TileEntityShoji.java    License: MIT License 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);
    if (compound.hasKey("type")) {
        type = compound.getInteger("type");
    }
    if (compound.hasKey("facing")) {
        facing = EnumFacing.byName(compound.getString("facing"));
    }
    if (compound.hasKey("open")) {
        open = compound.getBoolean("open");
    }
    if (compound.hasKey("animation")) {
        animation = compound.getInteger("animation");
    }
}
 
Example 12
@Override
public void writeToNBT(NBTTagCompound tag){
    super.writeToNBT(tag);
    tag.setString("offeringPlayerId", offeringPlayerId);
    tag.setString("offeringPlayerName", offeringPlayerName);
    tag.setInteger("inStock", inStock);
    tag.setInteger("maxTrades", maxTrades);
    tag.setInteger("pendingPayments", pendingPayments);
    if(providingPosition != null) {
        tag.setInteger("providingDimensionId", providingDimensionId);
        tag.setInteger("providingX", providingPosition.chunkPosX);
        tag.setInteger("providingY", providingPosition.chunkPosY);
        tag.setInteger("providingZ", providingPosition.chunkPosZ);
    }
    if(returningPosition != null) {
        tag.setInteger("returningDimensionId", returningDimensionId);
        tag.setInteger("returningX", returningPosition.chunkPosX);
        tag.setInteger("returningY", returningPosition.chunkPosY);
        tag.setInteger("returningZ", returningPosition.chunkPosZ);
    }
}
 
Example 13
Source Project: Valkyrien-Skies   Source File: TileEntityGearbox.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);
    if (compound.hasKey("inputFacing")) {
        this.inputFacing = EnumFacing.values()[compound.getByte("inputFacing")];
    }
    if (compound.hasKey("hasOutput")) {
        if (compound.getBoolean("hasOutput")) {
            if (compound.hasKey("outputRatio")) {
                this.outputRatio = Optional.of(compound.getDouble("outpuRatio"));
            }
        }
    }
}
 
Example 14
Source Project: AdvancedRocketry   Source File: TileSatelliteBuilder.java    License: MIT License 5 votes vote down vote up
@Override
public void useNetworkData(EntityPlayer player, Side side, byte id,
		NBTTagCompound nbt) {
	super.useNetworkData(player, side, id, nbt);


	onInventoryButtonPressed(id - 100);
}
 
Example 15
Source Project: Cyberware   Source File: TileEntityEngineeringTable.java    License: MIT License 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound)
{
	super.readFromNBT(compound);
	
	slots.deserializeNBT(compound.getCompoundTag("inv"));
	
	if (compound.hasKey("CustomName", 8))
	{
		customName = compound.getString("CustomName");
	}
	
	this.time = compound.getInteger("time");
	
	lastPlayerArchive = new HashMap<String, BlockPos>();
	NBTTagList list = (NBTTagList) compound.getTag("playerArchive");
	for (int i = 0; i < list.tagCount(); i++)
	{
		NBTTagCompound comp = list.getCompoundTagAt(i);
		String name = comp.getString("name");
		int x = comp.getInteger("x");
		int y = comp.getInteger("y");
		int z = comp.getInteger("z");
		BlockPos pos = new BlockPos(x, y, z);
		lastPlayerArchive.put(name, pos);
	}

}
 
Example 16
@Override
public void writeToNBT(NBTTagCompound tag){
    super.writeToNBT(tag);
    energy.writeToNBT(tag);
    writeInventoryToNBT(tag, inventory);
    tag.setInteger("redstoneMode", redstoneMode);
    tag.setBoolean("isEnabled", isEnabled);
}
 
Example 17
Source Project: TFC2   Source File: TileSmallVessel.java    License: GNU General Public License v3.0 5 votes vote down vote up
/***********************************************************************************
 * 3. NBT Methods
 ***********************************************************************************/
@Override
public void readSyncableNBT(NBTTagCompound nbt)
{
	NBTTagList invList = nbt.getTagList("inventory", 10);
	inventory = Helper.readStackArrayFromNBTList(invList, getSizeInventory());
	rotation = EnumFacing.Axis.values()[nbt.getInteger("axis")];
}
 
Example 18
private void setSelectedFixedBlockType(ItemStack stack, EntityPlayer player, World world, BlockPos pos, boolean secondary)
{
    int sel = this.getSelectionIndex(stack, secondary);

    if (sel < 0)
    {
        return;
    }

    String tagName = secondary ? TAG_NAME_BLOCKS + "2" : TAG_NAME_BLOCKS;
    NBTTagCompound blocksTag = NBTUtils.getCompoundTag(stack, WRAPPER_TAG_NAME, tagName, true);
    NBTTagCompound tag = NBTUtils.getCompoundTag(blocksTag, TAG_NAME_BLOCK_PRE + sel, true);

    this.setSelectedFixedBlockType(tag, player, world, pos);
}
 
Example 19
Source Project: ExNihiloAdscensio   Source File: ItemInfo.java    License: MIT License 5 votes vote down vote up
public NBTTagCompound writeToNBT(NBTTagCompound tag)
{
    tag.setString("item", Item.REGISTRY.getNameForObject(item).toString());
    tag.setInteger("meta", meta);
    
    return tag;
}
 
Example 20
Source Project: AdvancedRocketry   Source File: ItemStationChip.java    License: MIT License 5 votes vote down vote up
/**
 * @param stack
 * @return Vector3F containing the takeoff coords or null if there is none
 */
public Vector3F<Float> getTakeoffCoords(ItemStack stack, int dimid) {
	if(stack.hasTagCompound()) {
		NBTTagCompound nbt = stack.getTagCompound();
		if(nbt.hasKey("dimid" + dimid)) {
			nbt = nbt.getCompoundTag("dimid" + dimid);
			return new Vector3F<Float>(nbt.getFloat("x"), nbt.getFloat("y"),nbt.getFloat("z"));
		}
	}
	return null;
}
 
Example 21
Source Project: EmergingTechnology   Source File: BioreactorTileEntity.java    License: MIT License 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);

    this.itemHandler.deserializeNBT(compound.getCompoundTag("Inventory"));

    this.setWater(compound.getInteger("GuiWater"));
    this.setEnergy(compound.getInteger("GuiEnergy"));
    this.setProgress(compound.getInteger("GuiProgress"));

    this.fluidHandler.readFromNBT(compound);
    this.energyHandler.readFromNBT(compound);
}
 
Example 22
@Override
public void writeToNBT(NBTTagCompound tag){
    super.writeToNBT(tag);
    for(int i = 0; i < 6; i++) {
        tag.setBoolean(ForgeDirection.getOrientation(i).name(), accessingSides[i]);
    }
    tag.setBoolean("useCount", useCount);
    tag.setInteger("count", count);
}
 
Example 23
Source Project: NBTEdit   Source File: SaveStates.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void read() throws IOException{
	if (file.exists() && file.canRead()){
		NBTTagCompound root = CompressedStreamTools.read(file);
		for (int i =0; i < 7; ++i){
			String name = "slot" + (i+1);
			if (root.hasKey(name))
				tags[i].tag = root.getCompoundTag(name);
			if (root.hasKey(name+"Name"))
				tags[i].name = root.getString(name+"Name");
		}
	}
}
 
Example 24
Source Project: ExtraCells1   Source File: TileEntityCertusTank.java    License: MIT License 5 votes vote down vote up
public FluidTank readFromNBT(NBTTagCompound nbt)
{
	if (!nbt.hasKey("Empty"))
	{
		FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt);
		setFluid(fluid);
	} else
	{
		setFluid(null);
	}
	return this;
}
 
Example 25
Source Project: GardenCollection   Source File: AspectList.java    License: MIT License 5 votes vote down vote up
public void writeToNBT(NBTTagCompound nbttagcompound, String label)
  {
      NBTTagList tlist = new NBTTagList();
nbttagcompound.setTag(label, tlist);
for (Aspect aspect : getAspects())
	if (aspect != null) {
		NBTTagCompound f = new NBTTagCompound();
		f.setString("key", aspect.getTag());
		f.setInteger("amount", getAmount(aspect));
		tlist.appendTag(f);
	}
  }
 
Example 26
Source Project: ExNihiloAdscensio   Source File: BlockInfo.java    License: MIT License 5 votes vote down vote up
public static BlockInfo readFromNBT(NBTTagCompound tag)
{
    Block item_ = Block.REGISTRY.getObject(new ResourceLocation(tag.getString("block")));
    int meta_ = tag.getInteger("meta");
    
    return new BlockInfo(item_, meta_);
}
 
Example 27
/**
 * Cycle a byte value in the given ItemStack's NBT in a tag <b>tagName</b>. If <b>containerTagName</b>
 * is not null, then the value is stored inside a compound tag by that name.
 * The low end of the range is 0.
 */
public static void cycleByteValue(@Nonnull ItemStack stack, @Nullable String containerTagName,
        @Nonnull String tagName, int maxValue, boolean reverse)
{
    NBTTagCompound nbt = getCompoundTag(stack, containerTagName, true);
    cycleByteValue(nbt, tagName, 0, maxValue, reverse);
}
 
Example 28
Source Project: EmergingTechnology   Source File: SolarGlassTileEntity.java    License: MIT License 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);

    this.energyHandler.readFromNBT(compound);

    this.setEnergy(compound.getInteger("GuiEnergy"));
}
 
Example 29
Source Project: TofuCraftReload   Source File: StructureTofuMineshaftPieces.java    License: MIT License 5 votes vote down vote up
/**
 * (abstract) Helper method to write subclass data to NBT
 */
protected void writeStructureToNBT(NBTTagCompound tagCompound) {
    super.writeStructureToNBT(tagCompound);
    NBTTagList nbttaglist = new NBTTagList();

    for (StructureBoundingBox structureboundingbox : this.connectedRooms) {
        nbttaglist.appendTag(structureboundingbox.toNBTTagIntArray());
    }

    tagCompound.setTag("Entrances", nbttaglist);
}
 
Example 30
/**
    * Writes a tile entity to NBT.
    * @return 
    */
@Override
   public NBTTagCompound writeToNBT(NBTTagCompound nbt)
   {
       NBTTagCompound compound = super.writeToNBT(nbt);
       nbt.setLong("buildseed", this.buildseed);
       return compound;
   }