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.
Example 1
Project: Kettle   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
Project: BigReactors   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
Project: NOVA-Core   File: BWBlockTransform.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@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
Project: Production-Line   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
Project: PneumaticCraft   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
Project: Cyberware   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
Project: Logistics-Pipes-2   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
Project: mocreaturesdev   File: MoCEntityWyvern.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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
Project: OpenPeripheral-Integration   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
Project: Wizardry   File: StandardWizardryWorld.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@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
Project: Sakura_mod   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
Project: PneumaticCraft   File: AmadronOfferCustom.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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
Project: Valkyrien-Skies   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
Project: AdvancedRocketry   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
Project: Cyberware   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
Project: PneumaticCraft   File: TileEntityPneumaticDynamo.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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
Project: TFC2   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
Project: enderutilities   File: ItemBuildersWand.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
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
Project: ExNihiloAdscensio   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
Project: AdvancedRocketry   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
Project: EmergingTechnology   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
Project: PneumaticCraft   File: ProgWidgetInventoryBase.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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
Project: NBTEdit   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
Project: ExtraCells1   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
Project: GardenCollection   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
Project: ExNihiloAdscensio   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
Project: enderutilities   File: NBTUtils.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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
Project: EmergingTechnology   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
Project: TofuCraftReload   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
Project: CommunityMod   File: TileEntityGnode.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    * 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;
   }
 
Example 31
Project: OpenModsLib   File: ItemUtils.java    License: MIT License 5 votes vote down vote up
/**
 * This function returns fingerprint of NBTTag. It can be used to compare two tags
 */
public static String getNBTHash(NBTTagCompound tag) {
	try {
		MessageDigest digest = MessageDigest.getInstance("MD5");
		OutputStream dump = new NullOutputStream();
		DigestOutputStream hasher = new DigestOutputStream(dump, digest);
		DataOutput output = new DataOutputStream(hasher);
		CompressedStreamTools.write(tag, output);
		byte[] hash = digest.digest();
		return new String(Hex.encodeHex(hash));
	} catch (IOException | NoSuchAlgorithmException e) {
		throw new RuntimeException(e);
	}
}
 
Example 32
Project: enderutilities   File: ItemBuildersWand.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public Mirror getMirror(ItemStack stack, Mode mode)
{
    int sel = this.getSelectionIndex(stack);
    NBTTagCompound tag = this.getModeTag(stack, mode);

    if (tag.getBoolean("IsMirrored_" + sel) && tag.hasKey("Mirror_" + sel, Constants.NBT.TAG_BYTE))
    {
        return Mirror.values()[tag.getByte("Mirror_" + sel) % Mirror.values().length];
    }

    return Mirror.NONE;
}
 
Example 33
Project: Wizardry   File: SpellData.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public NBTTagCompound serializeNBT() {
	NBTTagCompound compound = new NBTTagCompound();
	for (Entry<DataField<?>, Object> entry : data.entrySet()) {
		NBTBase nbtClass = entry.getKey().getDataTypeProcess().serialize(entry.getValue());
		compound.setTag(entry.getKey().getFieldName(), nbtClass);
	}

	return compound;
}
 
Example 34
Project: EmergingTechnology   File: HydroponicTileEntity.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.fluidHandler.readFromNBT(compound);

    this.energyHandler.readFromNBT(compound);
}
 
Example 35
Project: FastAsyncWorldedit   File: ForgeQueue_All.java    License: GNU General Public License v3.0 5 votes vote down vote up
public CompoundTag getTag(TileEntity tile) {
    try {
        NBTTagCompound tag = new NBTTagCompound();
        tile.writeToNBT(tag); // readTagIntoEntity
        CompoundTag result = (CompoundTag) methodToNative.invoke(null, tag);
        return result;
    } catch (Exception e) {
        MainUtil.handleError(e);
        return null;
    }
}
 
Example 36
Project: NotEnoughItems   File: ItemStackMap.java    License: MIT License 5 votes vote down vote up
public void addKeys(Item item, List<ItemStack> list) {
    if (wildcard != null)
        list.add(wildcard(item));
    if (damageMap != null)
        for (int damage : damageMap.keySet())
            list.add(newItemStack(item, 1, damage, WILDCARD_TAG));
    if (tagMap != null)
        for (NBTTagCompound tag : tagMap.keySet())
            list.add(newItemStack(item, 1, WILDCARD_VALUE, tag));
    if (metaMap != null)
        for (StackMetaKey key : metaMap.keySet())
            list.add(newItemStack(item, 1, key.damage, key.tag));
}
 
Example 37
Project: Gadomancy   File: OverrideRidingEntity.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public OverrideRidingEntity(EntityGolemBase golem, NBTTagCompound compound, Entity ridingEntity) {
    super(golem.worldObj);
    Entity.nextEntityID--;

    this.golem = golem;
    this.compound = compound;
    this.ridingEntity = ridingEntity;
}
 
Example 38
Project: litematica   File: SpongeSchematic.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
protected NBTTagCompound writePaletteToTag(List<IBlockState> list)
{
    final int size = list.size();
    NBTTagCompound tag = new NBTTagCompound();

    for (int id = 0; id < size; ++id)
    {
        IBlockState state = list.get(id);
        tag.setInteger(state.toString(), id);
    }

    return tag;
}
 
Example 39
Project: Cyberware   File: ItemBrainUpgrade.java    License: MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleClone(PlayerEvent.Clone event)
{
	if (event.isWasDeath())
	{
		EntityPlayer p = event.getOriginal();
		
		if (CyberwareAPI.isCyberwareInstalled(p, new ItemStack(this, 1, 0)) && !p.worldObj.getGameRules().getBoolean("keepInventory"))
		{
			/*float range = 5F;
			List<EntityXPOrb> orbs = p.worldObj.getEntitiesWithinAABB(EntityXPOrb.class, new AxisAlignedBB(p.posX - range, p.posY - range, p.posZ - range, p.posX + p.width + range, p.posY + p.height + range, p.posZ + p.width + range));
			for (EntityXPOrb orb : orbs)
			{
				orb.setDead();
			}*/

			if (!p.worldObj.isRemote)
			{
				ItemStack stack = new ItemStack(CyberwareContent.expCapsule);
				NBTTagCompound c = new NBTTagCompound();
				c.setInteger("xp", p.experienceTotal);
				stack.setTagCompound(c);
				EntityItem item = new EntityItem(p.worldObj, p.posX, p.posY, p.posZ, stack);
				p.worldObj.spawnEntityInWorld(item);
			}
		}
		else if (CyberwareAPI.isCyberwareInstalled(p, new ItemStack(this, 1, 2)) && !p.worldObj.getGameRules().getBoolean("keepInventory"))
		{
			event.getEntityPlayer().addExperience((int) (Math.min(100, p.experienceLevel * 7) * .9F));
		}
	}
}
 
Example 40
Project: GT-Classic   File: GTTileBaseRecolorableTile.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<ItemStack> getDrops() {
	List<ItemStack> drops = new ArrayList<>();
	ItemStack block = GTMaterialGen.get(getBlockDrop());
	if (this.isColored()) {
		NBTTagCompound nbt = StackUtil.getOrCreateNbtData(block);
		nbt.setInteger(NBT_COLOR, this.color);
	}
	drops.addAll(getInventoryDrops());
	drops.add(block);
	return drops;
}