本文整理匯總了Java中net.minecraft.nbt.JsonToNBT.getTagFromJson方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonToNBT.getTagFromJson方法的具體用法?Java JsonToNBT.getTagFromJson怎麽用?Java JsonToNBT.getTagFromJson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.nbt.JsonToNBT
的用法示例。
在下文中一共展示了JsonToNBT.getTagFromJson方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
示例5: 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();
}
}
示例6: 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);
}
}
示例7: 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);
}
示例8: 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;
}
示例9: 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());
}
示例10: makeItemStack
import net.minecraft.nbt.JsonToNBT; //導入方法依賴的package包/類
/**
* Makes an {@link ItemStack} based on the itemName reference, with supplied meta, stackSize and nbt, if possible
* <p/>
* Will return null if the item doesn't exist (because it's not from a loaded mod for example)
* Will throw a {@link RuntimeException} if the nbtString is invalid for use in an {@link ItemStack}
*
* @param itemName a registry name reference
* @param meta the meta
* @param stackSize the stack size
* @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT}
* @return a new itemstack
*/
public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString)
{
if (itemName == null)
{
throw new IllegalArgumentException("The itemName cannot be null");
}
Item item = GameData.getItemRegistry().getObject(new ResourceLocation(itemName));
if (item == null)
{
FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName);
return null;
}
ItemStack is = new ItemStack(item, stackSize, meta);
if (!Strings.isNullOrEmpty(nbtString))
{
NBTBase nbttag = null;
try
{
nbttag = JsonToNBT.getTagFromJson(nbtString);
} catch (NBTException e)
{
FMLLog.getLogger().log(Level.WARN, "Encountered an exception parsing ItemStack NBT string {}", nbtString, e);
throw Throwables.propagate(e);
}
if (!(nbttag instanceof NBTTagCompound))
{
FMLLog.getLogger().log(Level.WARN, "Unexpected NBT string - multiple values {}", nbtString);
throw new RuntimeException("Invalid NBT JSON");
}
else
{
is.setTagCompound((NBTTagCompound)nbttag);
}
}
return is;
}
示例11: deserialize
import net.minecraft.nbt.JsonToNBT; //導入方法依賴的package包/類
public SetNBT deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn)
{
try
{
NBTTagCompound nbttagcompound = JsonToNBT.getTagFromJson(JsonUtils.getString(object, "tag"));
return new SetNBT(conditionsIn, nbttagcompound);
}
catch (NBTException nbtexception)
{
throw new JsonSyntaxException(nbtexception);
}
}
示例12: processCommand
import net.minecraft.nbt.JsonToNBT; //導入方法依賴的package包/類
/**
* Callback when the command is invoked
*/
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 1)
{
throw new WrongUsageException("commands.testfor.usage", new Object[0]);
}
else
{
Entity entity = func_175768_b(sender, args[0]);
NBTTagCompound nbttagcompound = null;
if (args.length >= 2)
{
try
{
nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
}
}
if (nbttagcompound != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
entity.writeToNBT(nbttagcompound1);
if (!NBTUtil.func_181123_a(nbttagcompound, nbttagcompound1, true))
{
throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
}
}
notifyOperators(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
}
}
示例13: deserialize
import net.minecraft.nbt.JsonToNBT; //導入方法依賴的package包/類
@Override
public NBTTagCompound deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
try
{
return JsonToNBT.getTagFromJson(json.getAsString());
} catch (NBTException e)
{
e.printStackTrace();
}
throw new JsonParseException("Failed to parse nbt");
}
示例14: execute
import net.minecraft.nbt.JsonToNBT; //導入方法依賴的package包/類
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 1)
{
throw new WrongUsageException("commands.testfor.usage", new Object[0]);
}
else
{
Entity entity = getEntity(server, sender, args[0]);
NBTTagCompound nbttagcompound = null;
if (args.length >= 2)
{
try
{
nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
}
}
if (nbttagcompound != null)
{
NBTTagCompound nbttagcompound1 = entityToNBT(entity);
if (!NBTUtil.areNBTEquals(nbttagcompound, nbttagcompound1, true))
{
throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
}
}
notifyCommandListener(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
}
}
示例15: getDeathList
import net.minecraft.nbt.JsonToNBT; //導入方法依賴的package包/類
public boolean getDeathList(EntityPlayer player, String playerName, String timestamp)
{
boolean didWork = true;
String filename = TombManyGraves.file + DeathInventoryHandler.FILE_PREFIX + "/" + playerName + "#" + timestamp + ".json";
BufferedReader reader;
try
{
reader = new BufferedReader(new FileReader(filename));
String fileData = reader.readLine();
allNBT = JsonToNBT.getTagFromJson(fileData);
if (allNBT.getKeySet().size() > 0) {
ItemStack theList = new ItemStack(ModItems.itemDeathList, 1);
theList.setTagCompound(allNBT);
EntityItem entityItem = new EntityItem(player.worldObj, player.posX, player.posY, player.posZ, theList);
player.worldObj.spawnEntityInWorld(entityItem);
}
else
{
ChatHelper.sayMessage(player.worldObj, player, playerName + " had no items upon death!");
}
reader.close();
}
catch (Exception e)
{
// e.printStackTrace();
didWork = false;
}
return didWork;
}