當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonToNBT類代碼示例

本文整理匯總了Java中net.minecraft.nbt.JsonToNBT的典型用法代碼示例。如果您正苦於以下問題:Java JsonToNBT類的具體用法?Java JsonToNBT怎麽用?Java JsonToNBT使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonToNBT類屬於net.minecraft.nbt包,在下文中一共展示了JsonToNBT類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseStack

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
public static ItemStack parseStack(String name) {
    if (name.contains("/")) {
        String[] split = StringUtils.split(name, "/");
        ItemStack stack = parseStackNoNBT(split[0]);
        if (ItemStackTools.isEmpty(stack)) {
            return stack;
        }
        NBTTagCompound nbt;
        try {
            nbt = JsonToNBT.getTagFromJson(split[1]);
        } catch (NBTException e) {
            InControl.logger.log(Level.ERROR, "Error parsing NBT in '" + name + "'!");
            return ItemStackTools.getEmptyStack();
        }
        stack.setTagCompound(nbt);
        return stack;
    } else {
        return parseStackNoNBT(name);
    }
}
 
開發者ID:McJty,項目名稱:InControl,代碼行數:21,代碼來源:Tools.java

示例2: buildReward

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
private void buildReward(Reward reward) {
	Item rewardItem = Item.getItemById(reward.type);
	ItemStack rewardStack = new ItemStack(rewardItem, reward.quantity);
	
	if (reward.subType > 0) {
		rewardStack.setItemDamage(reward.subType);
	}
	
	if (reward.nbt != null) {
		try {
			rewardStack.setTagCompound(JsonToNBT.getTagFromJson(reward.nbt));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	setInventorySlotContents(REWARD_OUTPUT_INDEX, rewardStack);
}
 
開發者ID:ToroCraft,項目名稱:Dailies,代碼行數:19,代碼來源:BaileyInventory.java

示例3: addBlockMorph

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
/**
 * Add an entity morph to the morph list
 */
private void addBlockMorph(MorphList morphs, World world, String json)
{
    try
    {
        BlockMorph morph = new BlockMorph();
        NBTTagCompound tag = JsonToNBT.getTagFromJson(json);

        tag.setString("Name", morph.name);
        morph.fromNBT(tag);

        morphs.addMorphVariant("block", "blocks", morph.block.getBlock().getLocalizedName(), morph);
    }
    catch (Exception e)
    {
        System.out.println("Failed to create a block morph with the data! " + json);
        e.printStackTrace();
    }
}
 
開發者ID:mchorse,項目名稱:metamorph,代碼行數:22,代碼來源:MobMorphFactory.java

示例4: getEntityDataTag

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
public NBTTagCompound getEntityDataTag()
{
	NBTTagCompound tag = null;
	
	if (!this.entityNBTData.equals(""))
	{
		try
		{
			tag = JsonToNBT.getTagFromJson(this.entityNBTData);
		}
		catch (NBTException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	return tag;
}
 
開發者ID:Brian-Wuest,項目名稱:MC-Prefab,代碼行數:20,代碼來源:BuildEntity.java

示例5: getBlockStateDataTag

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
public NBTTagCompound getBlockStateDataTag()
{
	NBTTagCompound tag = null;
	
	if (!this.blockStateData.equals(""))
	{
		try
		{
			tag = JsonToNBT.getTagFromJson(this.blockStateData);
		}
		catch (NBTException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	return tag;
}
 
開發者ID:Brian-Wuest,項目名稱:MC-Prefab,代碼行數:20,代碼來源:BuildBlock.java

示例6: SpecialItem

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
SpecialItem(String n, byte c, short m, @Nullable String t) {
	name = n;
	amount = c;
	meta = m;
	if (t != null) {
		NBTTagCompound nbt;
		try {
			nbt = JsonToNBT.getTagFromJson(t);
		} catch (NBTException e) {
			MCFluxReport.sendException(e, "NBT Decoding");
			nbt = null;
		}
		tag = nbt;
	} else
		tag = null;
	item = Item.getByNameOrId(name);
}
 
開發者ID:Szewek,項目名稱:Minecraft-Flux,代碼行數:18,代碼來源:SpecialEvent.java

示例7: Deserialize

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
@Override
public Object Deserialize(Object input) {
    String json = "{}";
    if(input instanceof String) {
        json = input.toString();
    } else if(input instanceof ScriptObjectMirror) {
        json = NashornConfigProcessor.getInstance().nashorn.stringifyJsonObject((JSObject) input);
    }

    try {
        return JsonToNBT.getTagFromJson(json);
    } catch (NBTException e) {
        LogHelper.error("Unable to convert '" + json + "' to NBT tag.", e);
        return new NBTTagCompound();
    }
}
 
開發者ID:legendblade,項目名稱:CraftingHarmonics,代碼行數:17,代碼來源:NbtTagCompoundDeserializer.java

示例8: makeItemStackFromString

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
/** Creates a new ItemStack from the string acquired from makeStringFromItemStack or an oredict name, with an oredict index option */
public static ItemStack makeItemStackFromString(String stackString, int oreIndex) {
	if(stackString == LightningInfusionRecipe.nullIdentifier) return null;
	try { // try to load it as a regular NBT stack
		if(!isStringOreDict(stackString)) {
			return ItemStack.loadItemStackFromNBT(JsonToNBT.getTagFromJson(stackString));
		} else {
			throw new NBTException("OreDict exists");
		}
	} catch(NBTException e) { // now try to get it as an oredict entry
		List<ItemStack> list;
		if(isStringOreDict(stackString) && oreIndex < (list = OreDictionary.getOres(stackString)).size()) {
			return list.get(oreIndex); // yep
		} else {
			return null; // guess not
		}
	}
}
 
開發者ID:sblectric,項目名稱:LightningCraft,代碼行數:19,代碼來源:StackHelper.java

示例9: handleClickServer

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
public void handleClickServer(EntityNPC npc){
	if(action.startsWith("action.nbt=")){
		String[] equalsplit = action.split("=");
		String nbt_json = "";
		for(int i = 1; i < equalsplit.length; i++){
			nbt_json += equalsplit[i];
		}
		NBTTagCompound newNBT;
		try {
			newNBT = JsonToNBT.getTagFromJson(nbt_json);
		} catch (NBTException e) {
			e.printStackTrace();
			return;
		}
		npc.getScriptData().merge(newNBT);
	}
}
 
開發者ID:tiffit,項目名稱:TaleCraft,代碼行數:18,代碼來源:NPCDialogue.java

示例10: getResourceStack

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
public ItemStack getResourceStack() {
    if(stackOverride != null) {
        NBTTagCompound tag;
        try {
            tag = JsonToNBT.getTagFromJson(stackOverride);
        } catch (NBTException e) {
            e.printStackTrace();
            return new ItemStack(getBlock(), 1, stackMeta);
        }
        if(tag != null) {
            ItemStack stack = new ItemStack(tag);
            if(stack != null) {
                return stack;
            }
        }
    }
    return new ItemStack(getBlock(), 1, stackMeta);
}
 
開發者ID:InfinityRaider,項目名稱:SettlerCraft,代碼行數:19,代碼來源:Schematic.java

示例11: getItemStackwNBT

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
/**
 * Get an ItemStack instance with given amount of items and NBT Tag pTag is
 * optional, and this function will return an ItemStack without NBT if pTag
 * is empty
 * 
 * @param pAmount
 * @param pTag
 * @return An itemstack with attached NBTTag, or null if the tag was invalid, or the itemdescriptor
 * couldn't be turned into a valid itemstack
 */
public ItemStack getItemStackwNBT( int pAmount, String pTag )
{
  NBTTagCompound tNBT = null;
  boolean tDamagedNBT = false;

  try
  {
    if( !pTag.isEmpty() )
      tNBT = (NBTTagCompound) JsonToNBT.func_150315_a( pTag );
  }
  catch( Exception e )
  {
    _mLog.error( String.format( "Found invalid NBT Tag: %s", pTag ) );
    tDamagedNBT = true;
  }

  if( !tDamagedNBT )
    return getItemStackwNBT( pAmount, tNBT );
  else
    return null;
}
 
開發者ID:GTNewHorizons,項目名稱:Yamcl,代碼行數:32,代碼來源:ItemDescriptor.java

示例12: decodeInto

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
{
    try
    {
        byte[] readBytes = new byte[buffer.readableBytes()];
        buffer.readBytes(readBytes);
        ByteArrayInputStream bais = new ByteArrayInputStream(readBytes);
        DataInputStream inputStream = new DataInputStream(bais);

        x = inputStream.readInt();
        y = inputStream.readInt();
        z = inputStream.readInt();
        
        String str = inputStream.readUTF();
        if(!str.equals("null"))
            stack = ItemStack.loadItemStackFromNBT((NBTTagCompound) JsonToNBT.func_150315_a(str));
        inputStream.close();
        bais.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}
 
開發者ID:jglrxavpok,項目名稱:CustomAI,代碼行數:26,代碼來源:PacketAIEStackUpdate.java

示例13: validateChildren

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
protected boolean validateChildren() throws ParserException
 {
     super.validateChildren();
     this.blocks = this.validateRequiredAttribute(String.class, "Block", true);
     this.weight = this.validateNamedAttribute(Float.class, "Weight", this.weight, true);
     String nbtJson = this.validateNamedAttribute(String.class, "NBT", null, true);
     if (nbtJson != null) {
     	try {
     		NBTBase base = JsonToNBT.getTagFromJson(nbtJson);
     		if (base instanceof NBTTagCompound) {
     			this.nbt = (NBTTagCompound)base;
     		} else {
     			throw new ParserException("NBT is not a compound tag");
     		}
} catch (NBTException e) {
	throw new ParserException("Failed to parse JSON", e);
}
     }
     return true;
 }
 
開發者ID:lawremi,項目名稱:CustomOreGen,代碼行數:21,代碼來源:ValidatorBlockDescriptor.java

示例14: WeightedRandomLoot

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
public WeightedRandomLoot(JsonObject json, int weight) throws Exception{

	this.name = json.get("name").getAsString();
	ResourceLocation location = new ResourceLocation(name);
	this.item = (Item) Item.REGISTRY.getObject(location);
	try{
		this.item.getUnlocalizedName();
	} catch (NullPointerException e){
		throw new Exception("Invalid item: " + this.name);
	}
	this.damage = json.has("meta") ? json.get("meta").getAsInt() : 0;
	this.weight = weight;
	this.enchLevel = json.has("ench") ? json.get("ench").getAsInt() : 0;

	if(json.has("min") && json.has("max")){
		min = json.get("min").getAsInt();
		max = json.get("max").getAsInt();	
	} else {
		min = 1;
		max = 1;
	}
	
	if(json.has("nbt")) this.nbt = JsonToNBT.getTagFromJson(json.get("nbt").getAsString());
	
}
 
開發者ID:Greymerk,項目名稱:minecraft-roguelike,代碼行數:26,代碼來源:WeightedRandomLoot.java

示例15: onInitialSpawn

import net.minecraft.nbt.JsonToNBT; //導入依賴的package包/類
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) {
	setItemStackToSlot(this.isLeftHanded() ? EntityEquipmentSlot.OFFHAND : EntityEquipmentSlot.MAINHAND, new ItemStack(HarshenItems.PROPS, 1, 0));
	try {
		setItemStackToSlot(this.isLeftHanded() ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND, new ItemStack(JsonToNBT.getTagFromJson("{id:\"minecraft:shield\",Count:1b,tag:{BlockEntityTag:{Patterns:[{Pattern:\"ss\",Color:6},{Pattern:\"flo\",Color:1}],Base:8}},Damage:0s}")));
	} catch (NBTException e) {
		e.printStackTrace();
	}
       this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextGaussian() * 0.05D, 1));
       this.setLeftHanded(false);
	return livingdata;
}
 
開發者ID:kenijey,項目名稱:harshencastle,代碼行數:13,代碼來源:EntitySoullessKnight.java


注:本文中的net.minecraft.nbt.JsonToNBT類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。