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

The following examples show how to use net.minecraft.nbt.NBTTagCompound#getString() . 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: CraftOfflinePlayer.java    From Thermos with 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 File: ArtifactTickHandler.java    From Artifacts with MIT License 6 votes vote down vote up
private void updateKnockbackResistance(int artifactKnockbackCount, EntityPlayer player) {
	NBTTagCompound playerData = player.getEntityData();
	int oldKnockbackCount = playerData.getInteger("artifactKnockbackCount");
	
	if(oldKnockbackCount != artifactKnockbackCount) {
		String uu = playerData.getString("artifactKnockbackUUID");
		UUID knockbackID;
		
		if(uu.equals("")) {
			knockbackID = UUID.randomUUID();
			playerData.setString("artifactKnockbackUUID", knockbackID.toString());
		}
		else {
			knockbackID = UUID.fromString(uu);
		}
		
		IAttributeInstance atinst = player.getEntityAttribute(SharedMonsterAttributes.knockbackResistance);
		
		atinst.removeModifier(new AttributeModifier(knockbackID, "KnockbackComponent", 0.2F * oldKnockbackCount, 0));
		atinst.applyModifier(new AttributeModifier(knockbackID, "KnockbackComponent", 0.2F * artifactKnockbackCount, 0));
		
		playerData.setInteger("artifactKnockbackCount", artifactKnockbackCount);
	}
}
 
Example 3
Source File: TileContainer.java    From Production-Line with MIT License 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);

    NBTTagList nbttaglist = nbt.getTagList("Items", 10);
    for (int i = 0; i < nbttaglist.tagCount(); ++i) {
        NBTTagCompound tag = nbttaglist.getCompoundTagAt(i);
        byte slot = tag.getByte("Slot");

        if (slot >= 0 && slot < this.getSizeInventory()) {
            this.tileSlots.get(i).readFromNBT(tag);
        }
    }

    if (nbt.hasKey("CustomName", 8)) {
        this.name = nbt.getString("CustomName");
    }
}
 
Example 4
Source File: TileEntityCamoMine.java    From AdvancedMod with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound tag){
    super.readFromNBT(tag);
    timer = tag.getInteger("timer");
    target = tag.getString("target");

    camoStacks = new ItemStack[6];
    NBTTagList camoStackTag = tag.getTagList("camoStacks", 10);

    for(int i = 0; i < camoStackTag.tagCount(); i++) {
        NBTTagCompound t = camoStackTag.getCompoundTagAt(i);
        int index = t.getByte("index");
        if(index >= 0 && index < camoStacks.length) {
            camoStacks[index] = ItemStack.loadItemStackFromNBT(t);
        }
    }
}
 
Example 5
Source File: TileStickyJar.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void readCustomNBT(NBTTagCompound compound) {
    String parentType = compound.getString("parentType");
    if(parentType.length() > 0) {
        Block block = GameData.getBlockRegistry().getObject(parentType);
        if(block != null && compound.hasKey("parent") && compound.hasKey("parentMetadata")) {
            NBTTagCompound data = compound.getCompoundTag("parent");
            int metadata = compound.getInteger("parentMetadata");
            TileEntity tile = block.createTileEntity(getWorldObj(), metadata);
            if(tile instanceof TileJarFillable) {
                placedOn = ForgeDirection.getOrientation(compound.getInteger("placedOn"));
                tile.readFromNBT(data);
                init((TileJarFillable) tile, block, metadata, placedOn);
            }
        }
    }

    if(!isValid() && !getWorldObj().isRemote) {
        getWorldObj().setBlockToAir(xCoord, yCoord, zCoord);
    }
}
 
Example 6
Source File: ModuleAirGrate.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound tag){
    super.readFromNBT(tag);
    vacuum = tag.getBoolean("vacuum");
    grateRange = tag.getInteger("grateRange");
    entityFilter = tag.getString("entityFilter");
}
 
Example 7
Source File: Herd.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public void readFromNBT(NBTTagCompound nbt, IslandMap map)
{
	NBTTagList invList = nbt.getTagList("animalList", 10);
	for(int i = 0; i < invList.tagCount(); i++)
	{
		VirtualAnimal a = new VirtualAnimal("", null);
		a.readFromNBT((NBTTagCompound)invList.get(i));
		animals.add(a);
	}
	brain.readFromNBT(nbt, map);
	animalType = nbt.getString("animalType");
	uuid = nbt.getUniqueId("uuid");
}
 
Example 8
Source File: TileEntityReactorControlRod.java    From BigReactors with MIT License 5 votes vote down vote up
private void readLocalDataFromNBT(NBTTagCompound data) {
	if(data.hasKey("controlRodInsertion")) {
		this.controlRodInsertion = data.getShort("controlRodInsertion");
	}
	
	if(data.hasKey("name")) {
		this.name = data.getString("name");
	}
	else {
		this.name = "";
	}
}
 
Example 9
Source File: ProgWidgetItemFilter.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound tag){
    super.readFromNBT(tag);
    filter = tag.getTag("id") instanceof NBTPrimitive ? ItemStack.loadItemStackFromNBT(tag) : loadItemStackByName(tag);
    useMetadata = tag.getBoolean("useMetadata");
    useNBT = tag.getBoolean("useNBT");
    useOreDict = tag.getBoolean("useOreDict");
    useModSimilarity = tag.getBoolean("useModSimilarity");
    specificMeta = tag.getInteger("specificMeta");
    variable = tag.getString("variable");
}
 
Example 10
Source File: TileEntityAphorismTile.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void readFromPacket(NBTTagCompound tag){
    super.readFromPacket(tag);
    int lines = tag.getInteger("lines");
    textLines = new String[lines];
    for(int i = 0; i < lines; i++) {
        textLines[i] = tag.getString("line" + i);
    }
}
 
Example 11
Source File: BlockLantern.java    From GardenCollection with MIT License 5 votes vote down vote up
public String getLightSource (ItemStack item) {
    if (item.hasTagCompound()) {
        NBTTagCompound tag = item.getTagCompound();
        if (tag.hasKey("src", Constants.NBT.TAG_STRING))
            return tag.getString("src");
    }

    return null;
}
 
Example 12
Source File: TargetData.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public NBTTagCompound readTargetTagFromNBT(NBTTagCompound nbt)
{
    if (nbtHasTargetTag(nbt) == false)
    {
        return null;
    }

    NBTTagCompound tag = nbt.getCompoundTag("Target");
    this.pos = new BlockPos(tag.getInteger("posX"), tag.getInteger("posY"), tag.getInteger("posZ"));
    this.dimension = tag.getInteger("Dim");
    this.dimensionName = tag.getString("DimName");
    this.blockName = tag.getString("BlockName");
    this.blockMeta = tag.getByte("BlockMeta");
    this.itemMeta = tag.getByte("ItemMeta");
    this.blockFace = tag.getByte("BlockFace");
    this.facing = EnumFacing.byIndex(this.blockFace);

    this.dPosX = tag.hasKey("dPosX", Constants.NBT.TAG_DOUBLE) ? tag.getDouble("dPosX") : this.pos.getX() + 0.5d;
    this.dPosY = tag.hasKey("dPosY", Constants.NBT.TAG_DOUBLE) ? tag.getDouble("dPosY") : this.pos.getY();
    this.dPosZ = tag.hasKey("dPosZ", Constants.NBT.TAG_DOUBLE) ? tag.getDouble("dPosZ") : this.pos.getZ() + 0.5d;

    if (tag.hasKey("Yaw", Constants.NBT.TAG_FLOAT) && tag.hasKey("Pitch", Constants.NBT.TAG_FLOAT))
    {
        this.hasRotation = true;
        this.yaw = tag.getFloat("Yaw");
        this.pitch = tag.getFloat("Pitch");
    }

    return tag;
}
 
Example 13
Source File: ItemMobCrystal.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
    if (stack.hasTagCompound()) {
        NBTTagCompound nbttagcompound = stack.getTagCompound();
        String string = nbttagcompound.getString("mob");

        if (string != null)
            return icons[1];
    }

    return icons[0];
}
 
Example 14
Source File: DataConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Data toNova(NBTTagCompound nbt) {
	Data data = new Data();
	if (nbt != null) {
		data.className = nbt.getString("class");
		@SuppressWarnings("unchecked")
		Set<String> keys = nbt.getKeySet();
		keys.stream().filter(k -> k != null && !"class".equals(k)).filter(Data.ILLEGAL_SUFFIX.asPredicate().negate()).forEach(k -> data.put(k, load(nbt, k)));
	}
	return data;
}
 
Example 15
Source File: TileEntityBusFluidExport.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound nbt)
{
	super.readFromNBT(nbt);
	NBTTagList nbttaglist = nbt.getTagList("Items");
	inventory.readFromNBT(nbttaglist);
	if (nbt.hasKey("CustomName"))
	{
		customName = nbt.getString("CustomName");
	}

	setRedstoneMode(RedstoneModeInput.values()[nbt.getInteger("RedstoneMode")]);
	setFluidMode(FluidMode.values()[nbt.getInteger("FluidMode")]);
	redstoneStatus = nbt.getBoolean("RedstoneState");
}
 
Example 16
Source File: IMCHandler.java    From VersionChecker with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void processCurseCheckMessage(String sender, NBTTagCompound tag)
{
    if (tag.hasKey(IMCOperations.CURSE_PROJECT_NAME) && tag.hasKey(IMCOperations.CURSE_FILENAME_PARSER))
    {
        String curseProjectName = tag.getString(IMCOperations.CURSE_PROJECT_NAME);
        String latestFilename = WebHelper.getLatestFilenameFromCurse("http://minecraft.curseforge.com/projects/" + curseProjectName + "/files/latest");
        if (latestFilename != null)
        {
            String fileNameParser = tag.getString(IMCOperations.CURSE_FILENAME_PARSER);
            int i = fileNameParser.indexOf('[');
            int o = fileNameParser.indexOf(']');
            if (i != -1 && o != -1)
            {
                String version = latestFilename.replace(fileNameParser.substring(0, i), "").replace(fileNameParser.substring(o + 1, fileNameParser.length()), "");

                if (version.equals(tag.hasKey(IMCOperations.OLD_VERSION) ? tag.getString(IMCOperations.OLD_VERSION) : ModHelper.getModContainer(sender).getVersion()))
                    return;

                Update update = new Update(sender);

                update.newVersion = version;
                update.updateURL = "http://minecraft.curseforge.com/projects/" + curseProjectName + "/files/latest";
                update.isDirectLink = true;
                update.newFileName = latestFilename;
                update.changeLog = I18n.translateToLocal(Strings.CURSE_UPDATE);

                if (tag.hasKey(IMCOperations.MOD_DISPLAY_NAME))
                {
                    update.displayName = tag.getString(IMCOperations.MOD_DISPLAY_NAME);
                }
                else
                {
                    update.displayName = ModHelper.getModContainer(sender).getName();
                }

                if (tag.hasKey(IMCOperations.OLD_VERSION))
                {
                    update.oldVersion = tag.getString(IMCOperations.OLD_VERSION);
                }
                else
                {
                    update.oldVersion = ModHelper.getModContainer(sender).getVersion();
                }

                update.updateType = Update.UpdateType.CURSE;

                UpdateHandler.addUpdate(update);
                return;
            }
        }
    }
    LogHandler.error(String.format("An error was encountered when fetching latest version from Curse for %s!", sender));
}
 
Example 17
Source File: SyncableString.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound nbt, String name) {
	value = nbt.getString(name);
}
 
Example 18
Source File: MixinTileEntityItemStackRenderer.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @author CCBlueX
 */
@Overwrite
public void renderByItem(ItemStack itemStackIn) {
    if(itemStackIn.getItem() == Items.banner) {
        this.banner.setItemValues(itemStackIn);
        TileEntityRendererDispatcher.instance.renderTileEntityAt(this.banner, 0.0D, 0.0D, 0.0D, 0.0F);
    }else if(itemStackIn.getItem() == Items.skull) {
        GameProfile gameprofile = null;

        if(itemStackIn.hasTagCompound()) {
            NBTTagCompound nbttagcompound = itemStackIn.getTagCompound();

            try {
                if(nbttagcompound.hasKey("SkullOwner", 10)) {
                    gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
                }else if(nbttagcompound.hasKey("SkullOwner", 8) && nbttagcompound.getString("SkullOwner").length() > 0) {
                    GameProfile lvt_2_2_ = new GameProfile(null, nbttagcompound.getString("SkullOwner"));
                    gameprofile = TileEntitySkull.updateGameprofile(lvt_2_2_);
                    nbttagcompound.removeTag("SkullOwner");
                    nbttagcompound.setTag("SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile));
                }
            }catch(Exception ignored) {
            }
        }

        if(TileEntitySkullRenderer.instance != null) {
            GlStateManager.pushMatrix();
            GlStateManager.translate(-0.5F, 0.0F, -0.5F);
            GlStateManager.scale(2.0F, 2.0F, 2.0F);
            GlStateManager.disableCull();
            TileEntitySkullRenderer.instance.renderSkull(0.0F, 0.0F, 0.0F, EnumFacing.UP, 0.0F, itemStackIn.getMetadata(), gameprofile, -1);
            GlStateManager.enableCull();
            GlStateManager.popMatrix();
        }
    }else{
        Block block = Block.getBlockFromItem(itemStackIn.getItem());

        if(block == Blocks.ender_chest) {
            TileEntityRendererDispatcher.instance.renderTileEntityAt(this.enderChest, 0.0D, 0.0D, 0.0D, 0.0F);
        }else if(block == Blocks.trapped_chest) {
            TileEntityRendererDispatcher.instance.renderTileEntityAt(this.field_147718_c, 0.0D, 0.0D, 0.0D, 0.0F);
        }else if(block != Blocks.chest)
            net.minecraftforge.client.ForgeHooksClient.renderTileItem(itemStackIn.getItem(), itemStackIn.getMetadata());
        else{
            TileEntityRendererDispatcher.instance.renderTileEntityAt(this.field_147717_b, 0.0D, 0.0D, 0.0D, 0.0F);
        }
    }
}
 
Example 19
Source File: ItemDolly.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean tryPlaceDownBlock(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side)
{
    pos = pos.offset(side);

    if (this.isCarryingBlock(stack) == false || world.isBlockModifiable(player, pos) == false)
    {
        return false;
    }

    NBTTagCompound tagCarrying = NBTUtils.getCompoundTag(stack, "Carrying", false);
    String name = tagCarrying.getString("Block");
    int meta = tagCarrying.getByte("Meta");
    Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(name));

    try
    {
        if (block != null && block != Blocks.AIR && world.mayPlace(block, pos, false, side, player))
        {
            @SuppressWarnings("deprecation")
            IBlockState state = block.getStateFromMeta(meta);
            EnumFacing pickupFacing = EnumFacing.byIndex(tagCarrying.getByte("PickupFacing"));
            EnumFacing currentFacing = EntityUtils.getHorizontalLookingDirection(player);
            Rotation rotation = PositionUtils.getRotation(pickupFacing, currentFacing);
            state = state.withRotation(rotation);

            if (world.setBlockState(pos, state))
            {
                TileEntity te = world.getTileEntity(pos);

                if (te != null && tagCarrying.hasKey("te", Constants.NBT.TAG_COMPOUND))
                {
                    NBTTagCompound nbt = tagCarrying.getCompoundTag("te");
                    TileUtils.createAndAddTileEntity(world, pos, nbt, rotation, Mirror.NONE);
                }

                NBTUtils.removeCompoundTag(stack, null, "Carrying");
                return true;
            }
        }
    }
    catch (Exception e)
    {
        EnderUtilities.logger.warn("Failed to place down a block from the Dolly", e);
    }

    return false;
}
 
Example 20
Source File: TileFrequencyOwner.java    From EnderStorage with MIT License 4 votes vote down vote up
public void readFromNBT(NBTTagCompound tag)
{
    super.readFromNBT(tag);
    freq = tag.getInteger("freq");
    owner = tag.getString("owner");
}