本文整理汇总了Java中net.minecraft.util.JsonUtils类的典型用法代码示例。如果您正苦于以下问题:Java JsonUtils类的具体用法?Java JsonUtils怎么用?Java JsonUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonUtils类属于net.minecraft.util包,在下文中一共展示了JsonUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
@Override
public IRecipe parse(JsonContext context, JsonObject json)
{
String group = JsonUtils.getString(json, "group", "");
NonNullList<Ingredient> ings = NonNullList.create();
for(JsonElement ele : JsonUtils.getJsonArray(json, "ingredients"))
ings.add(CraftingHelper.getIngredient(ele, context));
if(ings.isEmpty())
throw new JsonParseException("No ingredients for shapeless recipe");
if(ings.size() > 9)
throw new JsonParseException("Too many ingredients for shapeless recipe");
ItemStack itemstack = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
return new RecipeTorchGun(group, itemstack, ings);
}
示例2: parse
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
int clamp = JsonUtils.getInt(json, "clamp");
boolean combining = JsonUtils.getBoolean(json, "combining");
JsonArray upgradeList = JsonUtils.getJsonArray(json, "upgrades");
Map<Ingredient, Double> upgrades = new LinkedHashMap<>();
int n = 0;
for (JsonElement element : upgradeList) {
if (element.isJsonObject()) {
JsonObject upgrade = element.getAsJsonObject();
double amount = JsonUtils.getFloat(upgrade, "amount");
Ingredient ingredient = CraftingHelper.getIngredient(upgrade.get("ingredient"), context);
upgrades.put(ingredient, amount);
} else {
throw new JsonSyntaxException("Expected " + n + " to be a JsonObject, was " + JsonUtils.toString(json));
}
n++;
}
return new RandoresForgeUpgradeRecipe(clamp, combining, upgrades);
}
示例3: readPoolName
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
public static String readPoolName(JsonObject json)
{
LootTableContext ctx = ForgeHooks.getLootTableContext();
ctx.resetPoolCtx();
if (json.has("name"))
return JsonUtils.getString(json, "name");
if (ctx.custom)
return "custom#" + json.hashCode(); //We don't care about custom ones modders shouldn't be editing them!
ctx.poolCount++;
if (!ctx.vanilla)
throw new JsonParseException("Loot Table \"" + ctx.name.toString() + "\" Missing `name` entry for pool #" + (ctx.poolCount - 1));
return ctx.poolCount == 1 ? "main" : "pool" + (ctx.poolCount - 1);
}
示例4: readLootEntryName
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
public static String readLootEntryName(JsonObject json, String type)
{
LootTableContext ctx = ForgeHooks.getLootTableContext();
ctx.entryCount++;
if (json.has("entryName"))
return ctx.validateEntryName(JsonUtils.getString(json, "entryName"));
if (ctx.custom)
return "custom#" + json.hashCode(); //We don't care about custom ones modders shouldn't be editing them!
String name = null;
if ("item".equals(type))
name = JsonUtils.getString(json, "name");
else if ("loot_table".equals(type))
name = JsonUtils.getString(json, "name");
else if ("empty".equals(type))
name = "empty";
return ctx.validateEntryName(name);
}
示例5: initTarget
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
private void initTarget(JsonElement p_148027_1_) throws JsonException
{
if (JsonUtils.isString(p_148027_1_))
{
this.addFramebuffer(p_148027_1_.getAsString(), this.mainFramebufferWidth, this.mainFramebufferHeight);
}
else
{
JsonObject jsonobject = JsonUtils.getJsonObject(p_148027_1_, "target");
String s = JsonUtils.getString(jsonobject, "name");
int i = JsonUtils.getInt(jsonobject, "width", this.mainFramebufferWidth);
int j = JsonUtils.getInt(jsonobject, "height", this.mainFramebufferHeight);
if (this.mapFramebuffers.containsKey(s))
{
throw new JsonException(s + " is already defined");
}
this.addFramebuffer(s, i, j);
}
}
示例6: deserialize
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
public SetAttributes deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn)
{
JsonArray jsonarray = JsonUtils.getJsonArray(object, "modifiers");
SetAttributes.Modifier[] asetattributes$modifier = new SetAttributes.Modifier[jsonarray.size()];
int i = 0;
for (JsonElement jsonelement : jsonarray)
{
asetattributes$modifier[i++] = SetAttributes.Modifier.deserialize(JsonUtils.getJsonObject(jsonelement, "modifier"), deserializationContext);
}
if (asetattributes$modifier.length == 0)
{
throw new JsonSyntaxException("Invalid attribute modifiers array; cannot be empty");
}
else
{
return new SetAttributes(conditionsIn, asetattributes$modifier);
}
}
示例7: parseMapVariants
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
protected Map<String, VariantList> parseMapVariants(JsonDeserializationContext deserializationContext, JsonObject object)
{
Map<String, VariantList> map = Maps.<String, VariantList>newHashMap();
if (object.has("variants"))
{
JsonObject jsonobject = JsonUtils.getJsonObject(object, "variants");
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
map.put(entry.getKey(), (VariantList)deserializationContext.deserialize((JsonElement)entry.getValue(), VariantList.class));
}
}
return map;
}
示例8: deserialize
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
public BlockPart deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
Vector3f vector3f = this.parsePositionFrom(jsonobject);
Vector3f vector3f1 = this.parsePositionTo(jsonobject);
BlockPartRotation blockpartrotation = this.parseRotation(jsonobject);
Map<EnumFacing, BlockPartFace> map = this.parseFacesCheck(p_deserialize_3_, jsonobject);
if (jsonobject.has("shade") && !JsonUtils.isBoolean(jsonobject, "shade"))
{
throw new JsonParseException("Expected shade to be a Boolean");
}
else
{
boolean flag = JsonUtils.getBoolean(jsonobject, "shade", true);
return new BlockPart(vector3f, vector3f1, map, blockpartrotation, flag);
}
}
示例9: parsePosition
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
private Vector3f parsePosition(JsonObject p_178251_1_, String p_178251_2_)
{
JsonArray jsonarray = JsonUtils.getJsonArray(p_178251_1_, p_178251_2_);
if (jsonarray.size() != 3)
{
throw new JsonParseException("Expected 3 " + p_178251_2_ + " values, found: " + jsonarray.size());
}
else
{
float[] afloat = new float[3];
for (int i = 0; i < afloat.length; ++i)
{
afloat[i] = JsonUtils.getFloat(jsonarray.get(i), p_178251_2_ + "[" + i + "]");
}
return new Vector3f(afloat[0], afloat[1], afloat[2]);
}
}
示例10: jsonToFactory
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
public static ChunkProviderSettings.Factory jsonToFactory(String p_177865_0_)
{
if (p_177865_0_.isEmpty())
{
return new ChunkProviderSettings.Factory();
}
else
{
try
{
return (ChunkProviderSettings.Factory)JsonUtils.gsonDeserialize(JSON_ADAPTER, p_177865_0_, ChunkProviderSettings.Factory.class);
}
catch (Exception var2)
{
return new ChunkProviderSettings.Factory();
}
}
}
示例11: deserialize
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
public LootFunction deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "function");
ResourceLocation resourcelocation = new ResourceLocation(JsonUtils.getString(jsonobject, "function"));
LootFunction.Serializer<?> serializer;
try
{
serializer = LootFunctionManager.getSerializerForName(resourcelocation);
}
catch (IllegalArgumentException var8)
{
throw new JsonSyntaxException("Unknown function \'" + resourcelocation + "\'");
}
return serializer.deserialize(jsonobject, p_deserialize_3_, (LootCondition[])JsonUtils.deserializeClass(jsonobject, "conditions", new LootCondition[0], p_deserialize_3_, LootCondition[].class));
}
示例12: parseRotation
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
@Nullable
private BlockPartRotation parseRotation(JsonObject object)
{
BlockPartRotation blockpartrotation = null;
if (object.has("rotation"))
{
JsonObject jsonobject = JsonUtils.getJsonObject(object, "rotation");
Vector3f vector3f = this.parsePosition(jsonobject, "origin");
vector3f.scale(0.0625F);
EnumFacing.Axis enumfacing$axis = this.parseAxis(jsonobject);
float f = this.parseAngle(jsonobject);
boolean flag = JsonUtils.getBoolean(jsonobject, "rescale", false);
blockpartrotation = new BlockPartRotation(vector3f, enumfacing$axis, f, flag);
}
return blockpartrotation;
}
示例13: deserialize
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
public ServerStatusResponse.PlayerCountData deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "players");
ServerStatusResponse.PlayerCountData serverstatusresponse$playercountdata = new ServerStatusResponse.PlayerCountData(JsonUtils.getInt(jsonobject, "max"), JsonUtils.getInt(jsonobject, "online"));
if (JsonUtils.isJsonArray(jsonobject, "sample"))
{
JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "sample");
if (jsonarray.size() > 0)
{
GameProfile[] agameprofile = new GameProfile[jsonarray.size()];
for (int i = 0; i < agameprofile.length; ++i)
{
JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonarray.get(i), "player[" + i + "]");
String s = JsonUtils.getString(jsonobject1, "id");
agameprofile[i] = new GameProfile(UUID.fromString(s), JsonUtils.getString(jsonobject1, "name"));
}
serverstatusresponse$playercountdata.setPlayers(agameprofile);
}
}
return serverstatusresponse$playercountdata;
}
示例14: deserialize
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
public static LootEntryItem deserialize(JsonObject object, JsonDeserializationContext deserializationContext, int weightIn, int qualityIn, LootCondition[] conditionsIn)
{
Item item = JsonUtils.getItem(object, "name");
LootFunction[] alootfunction;
if (object.has("functions"))
{
alootfunction = (LootFunction[])JsonUtils.deserializeClass(object, "functions", deserializationContext, LootFunction[].class);
}
else
{
alootfunction = new LootFunction[0];
}
return new LootEntryItem(item, weightIn, qualityIn, alootfunction, conditionsIn);
}
示例15: deserializeSounds
import net.minecraft.util.JsonUtils; //导入依赖的package包/类
private List<Sound> deserializeSounds(JsonObject object)
{
List<Sound> list = Lists.<Sound>newArrayList();
if (object.has("sounds"))
{
JsonArray jsonarray = JsonUtils.getJsonArray(object, "sounds");
for (int i = 0; i < jsonarray.size(); ++i)
{
JsonElement jsonelement = jsonarray.get(i);
if (JsonUtils.isString(jsonelement))
{
String s = JsonUtils.getString(jsonelement, "sound");
list.add(new Sound(s, 1.0F, 1.0F, 1, Sound.Type.FILE, false));
}
else
{
list.add(this.deserializeSound(JsonUtils.getJsonObject(jsonelement, "sound")));
}
}
}
return list;
}