Java Code Examples for net.minecraft.nbt.NBTTagCompound#setInteger()

The following examples show how to use net.minecraft.nbt.NBTTagCompound#setInteger() . 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 File: EntityTippedChingerArrow.java    From TofuCraftReload with MIT License 6 votes vote down vote up
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound compound) {
    super.writeEntityToNBT(compound);

    if (this.potion != PotionTypes.EMPTY && this.potion != null) {
        compound.setString("Potion", ((ResourceLocation) PotionType.REGISTRY.getNameForObject(this.potion)).toString());
    }

    if (this.fixedColor) {
        compound.setInteger("Color", this.getColor());
    }

    if (!this.customPotionEffects.isEmpty()) {
        NBTTagList nbttaglist = new NBTTagList();

        for (PotionEffect potioneffect : this.customPotionEffects) {
            nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
        }

        compound.setTag("CustomPotionEffects", nbttaglist);
    }
}
 
Example 2
Source File: TileEntityEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Get the data used for syncing the TileEntity to the client.
 * The data returned from this method doesn't have the position,
 * the position will be added in getUpdateTag() which calls this method.
 */
public NBTTagCompound getUpdatePacketTag(NBTTagCompound nbt)
{
    nbt.setByte("r", (byte)(this.facing.getIndex() & 0x07));

    if (this.camoState != null)
    {
        nbt.setInteger("Camo", Block.getStateId(this.camoState));

        if (this.camoData != null)
        {
            nbt.setTag("CD", this.camoData);
        }
    }

    if (this.ownerData != null)
    {
        nbt.setString("o", this.ownerData.getOwnerName());
        nbt.setBoolean("pu", this.ownerData.getIsPublic());
    }

    return nbt;
}
 
Example 3
Source File: SpongeSchematic.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void writeBlockEntitiesToTag(NBTTagCompound tag)
{
    String tagName = this.version == 1 ? "TileEntities" : "BlockEntities";
    NBTTagList tagList = new NBTTagList();

    for (Map.Entry<BlockPos, NBTTagCompound> entry : this.blockEntities.entrySet())
    {
        NBTTagCompound beTag = entry.getValue().copy();
        NBTUtils.writeBlockPosToArrayTag(entry.getKey(), beTag, "Pos");

        // Add the Sponge tag and remove the vanilla/Litematica tag
        beTag.setString("Id", beTag.getString("id"));
        beTag.removeTag("id");

        if (this.version == 1)
        {
            beTag.setInteger("ContentVersion", 1);
        }

        tagList.appendTag(beTag);
    }

    tag.setTag(tagName, tagList);
}
 
Example 4
Source File: SpawnPotential.java    From minecraft-roguelike with GNU General Public License v3.0 6 votes vote down vote up
private NBTTagCompound getRoguelike(int level, String type, NBTTagCompound tag){
 	
tag.setString("id", type);

      if(!(RogueConfig.getBoolean(RogueConfig.ROGUESPAWNERS)
      		&& this.equip)) return tag;

NBTTagList activeEffects = new NBTTagList();
tag.setTag("ActiveEffects", activeEffects);

NBTTagCompound buff = new NBTTagCompound();
activeEffects.appendTag(buff);

buff.setByte("Id", (byte) 4);
buff.setByte("Amplifier", (byte) level);
buff.setInteger("Duration", 10);
buff.setByte("Ambient", (byte) 0);

return tag;
  }
 
Example 5
Source File: RiverAttribute.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound nbt) 
{
	nbt.setString("uuid", id.toString());
	nbt.setDouble("river", river);
	if(downriver != null)
		nbt.setInteger("downriver", downriver.index);

	if(upriver != null && upriver.size() > 0)
	{
		int[] nArray = new int[upriver.size()];
		for(int i = 0; i < nArray.length; i++)
		{
			nArray[i] = upriver.get(i).index;
		}
		nbt.setIntArray("upriver", nArray);
	}

	nbt.setDouble("midX", riverMid.x);
	nbt.setDouble("midY", riverMid.y);
	nbt.setBoolean("isDead", deadRiver);
}
 
Example 6
Source File: EntityMountable.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@Override
protected void writeEntityToNBT(NBTTagCompound compound) {
    // Try to prevent data race
    Vec3d mountPosLocal = mountPos;
    compound.setDouble("vs_mount_pos_x", mountPosLocal.x);
    compound.setDouble("vs_mount_pos_y", mountPosLocal.y);
    compound.setDouble("vs_mount_pos_z", mountPosLocal.z);

    compound.setInteger("vs_coord_type", mountPosSpace.ordinal());

    compound.setBoolean("vs_ref_pos_present", referencePos != null);
    if (referencePos != null) {
        compound.setInteger("vs_ref_pos_x", referencePos.getX());
        compound.setInteger("vs_ref_pos_y", referencePos.getY());
        compound.setInteger("vs_ref_pos_z", referencePos.getZ());
    }
}
 
Example 7
Source File: TileEntityElectrostaticCompressor.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound){

    super.writeToNBT(nbtTagCompound);
    nbtTagCompound.setInteger("redstoneMode", redstoneMode);
    // 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);
}
 
Example 8
Source File: StructureTofuMineshaftPieces.java    From TofuCraftReload with 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);
    tagCompound.setBoolean("hr", this.hasRails);
    tagCompound.setBoolean("sc", this.hasSpiders);
    tagCompound.setBoolean("hps", this.spawnerPlaced);
    tagCompound.setInteger("Num", this.sectionCount);
}
 
Example 9
Source File: PacketUpdateSearchStack.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleServerSide(PacketUpdateSearchStack message, EntityPlayer player){
    ItemStack helmetStack = player.inventory.armorItemInSlot(3);
    if(helmetStack != null) {
        NBTTagCompound tag = NBTUtil.getCompoundTag(helmetStack, "SearchStack");
        tag.setInteger("itemID", message.itemId);
        tag.setInteger("itemDamage", message.itemDamage);
    }
}
 
Example 10
Source File: EntityElephant.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
@Override
public void writeEntityToNBT (NBTTagCompound nbt)
{
	super.writeEntityToNBT (nbt);
	nbt.setInteger("ElephantType", elephantType.ordinal());
	nbt.setInteger("gender", gender.ordinal());
}
 
Example 11
Source File: HarvesterTileEntity.java    From EmergingTechnology with MIT License 5 votes vote down vote up
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    super.writeToNBT(compound);
    compound.setTag("Inventory", this.itemHandler.serializeNBT());

    compound.setInteger("GuiEnergy", energy);
    // compound.setInteger("AnimRotation", RotationEnum.getId(this.rotation));

    this.energyHandler.writeToNBT(compound);

    return compound;
}
 
Example 12
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 5 votes vote down vote up
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    super.writeToNBT(compound);
    compound.setTag("Inventory", this.itemHandler.serializeNBT());
    compound.setInteger("GuiWater", water);
    compound.setInteger("GuiEnergy", energy);

    this.fluidHandler.writeToNBT(compound);
    this.energyHandler.writeToNBT(compound);

    return compound;
}
 
Example 13
Source File: IslandData.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public void writeToNBT(NBTTagCompound nbt)
{
	nbt.setBoolean("isIslandUnlocked", isIslandUnlocked);
	nbt.setInteger("northPortalState", northPortalState.ordinal());
	nbt.setInteger("southPortalState", southPortalState.ordinal());
	nbt.setInteger("eastPortalState", eastPortalState.ordinal());
	nbt.setInteger("westPortalState", westPortalState.ordinal());
	nbt.setInteger("islandLevel", islandLevel);

	NBTTagCompound wmNBT = new NBTTagCompound();
	wildlifeManager.writeToNBT(wmNBT);
	nbt.setTag("wildlifeManager", wmNBT);
}
 
Example 14
Source File: EventHandler.java    From TinkersToolLeveling with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onToolBuild(TinkerToolEvent.OnItemBuilding event) {
  // we build a dummy tool tag to get the base modifier amount, unchanged by traits
  List<Material> materials = Lists.newArrayList();
  for(int i = 0; i < event.tool.getRequiredComponents().size(); i++) {
    materials.add(Material.UNKNOWN);
  }
  NBTTagCompound baseTag = event.tool.buildTag(materials);

  int modifiers = baseTag.getInteger(Tags.FREE_MODIFIERS);
  int modifierDelta = Config.getStartingModifiers() - modifiers;

  // set free modifiers
  NBTTagCompound toolTag = TagUtil.getToolTag(event.tag);
  modifiers = toolTag.getInteger(Tags.FREE_MODIFIERS);
  modifiers += modifierDelta;
  modifiers = Math.max(0, modifiers);
  toolTag.setInteger(Tags.FREE_MODIFIERS, modifiers);
  TagUtil.setToolTag(event.tag, toolTag);

  if(TinkerUtil.getModifierTag(event.tag, TinkerToolLeveling.modToolLeveling.getModifierIdentifier()).hasNoTags()) {
    TinkerToolLeveling.modToolLeveling.apply(event.tag);
  }

  if(!TinkerUtil.hasModifier(event.tag, TinkerToolLeveling.modToolLeveling.getModifierIdentifier())) {
    TinkerToolLeveling.modToolLeveling.apply(event.tag);
  }
}
 
Example 15
Source File: ScaffolderTileEntity.java    From EmergingTechnology with MIT License 5 votes vote down vote up
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    super.writeToNBT(compound);
    compound.setTag("Inventory", this.itemHandler.serializeNBT());

    compound.setInteger("GuiEnergy", energy);
    compound.setInteger("GuiProgress", progress);

    this.energyHandler.writeToNBT(compound);

    return compound;
}
 
Example 16
Source File: LingerBrain.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound nbt)
{
	nbt.setInteger("activityTimer", activityTimer);

	NBTTagCompound goalNBT = new NBTTagCompound();
	currentGoal.writeToNBT(goalNBT);
	nbt.setTag("currentGoal", goalNBT);

	nbt.setInteger("currentLocation", currentLocation.index);
	nbt.setString("currentActivity", currentActivity.getName());
}
 
Example 17
Source File: TofuVillageCollection.java    From TofuCraftReload with MIT License 5 votes vote down vote up
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    compound.setInteger("Tick", this.tickCounter);
    NBTTagList nbttaglist = new NBTTagList();

    for (TofuVillage village : this.villageList) {
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        village.writeTofuVillageDataToNBT(nbttagcompound);
        nbttaglist.appendTag(nbttagcompound);
    }

    compound.setTag("TofuVillages", nbttaglist);
    return compound;
}
 
Example 18
Source File: WorldCoordinates.java    From Chisel-2 with GNU General Public License v2.0 4 votes vote down vote up
public void writeNBT(NBTTagCompound nbt) {
	nbt.setInteger("w_x",x);
	nbt.setInteger("w_y",y);
	nbt.setInteger("w_z",z);
	nbt.setInteger("w_d",dim);
}
 
Example 19
Source File: MoCEntityEgg.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void writeEntityToNBT(NBTTagCompound nbttagcompound)
{
    super.writeEntityToNBT(nbttagcompound);
    nbttagcompound.setInteger("EggType", getEggType());
}
 
Example 20
Source File: TileTorch.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void writeSyncableNBT(NBTTagCompound compound) {
	compound.setInteger("torchTimer", torchTimer);
}