本文整理了Java中net.minecraft.util.JsonUtils.getJsonObject()
方法的一些代码示例,展示了JsonUtils.getJsonObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonUtils.getJsonObject()
方法的具体详情如下:
包路径:net.minecraft.util.JsonUtils
类名称:JsonUtils
方法名:getJsonObject
暂无
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
public static ItemStack getResult( JsonObject json, JsonContext context, String name )
{
JsonObject resultObject = JsonUtils.getJsonObject( json, name );
if( resultObject.has( "part" ) )
{
return getPart( resultObject );
}
else if( resultObject.has( "item" ) )
{
return CraftingHelper.getItemStack( resultObject, context );
}
else
{
throw new JsonSyntaxException( "Result has no 'part' or 'item' property." );
}
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
for( Map.Entry<String, JsonElement> entry : JsonUtils.getJsonObject( json, "key" ).entrySet() )
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
String mode = JsonUtils.getString( json, "mode" );
JsonObject ingredients = JsonUtils.getJsonObject( json, "ingredients" );
if( ingredients.has( "top" ) )
top = CraftingHelper.getIngredient( JsonUtils.getJsonObject( ingredients, "top" ), ctx ).getMatchingStacks();
if( ingredients.has( "bottom" ) )
bottom = CraftingHelper.getIngredient( JsonUtils.getJsonObject( ingredients, "bottom" ), ctx ).getMatchingStacks();
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
@Override
public void register( JsonObject json, JsonContext ctx )
{
// TODO only primary for now
JsonObject result = JsonUtils.getJsonObject( json, "result" );
ItemStack primary = PartRecipeFactory.getResult( result, ctx, "primary" );
ItemStack[] input = CraftingHelper.getIngredient( json.get( "input" ), ctx ).getMatchingStacks();
int turns = 5;
if( json.has( "turns" ) )
{
turns = JsonUtils.getInt( json, "turns" );
}
final IGrinderRegistry reg = AEApi.instance().registries().grinder();
for( int i = 0; i < input.length; ++i )
{
final IGrinderRecipeBuilder builder = reg.builder();
builder.withOutput( primary );
builder.withInput( input[i] );
builder.withTurns( turns );
reg.addRecipe( builder.build() );
}
}
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
public static <K, V> Map<K, V> mapFromObjectArray(JsonArray jsonArray, String keyName, String valueName, Function<JsonElement, K> parseKey,
Function<JsonElement, V> parseValue) {
Map<K, V> ret = new HashMap<>();
for (JsonElement element : jsonArray) {
JsonObject entry = JsonUtils.getJsonObject(element, "");
ret.put(parseKey.apply(entry.get(keyName)), parseValue.apply(entry.get(valueName)));
}
return ret;
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
private static Tuple<String, Map<String, String>> getBlockNameAndProperties(JsonObject stateJson) {
Map<String, String> properties = new HashMap<>();
if (JsonUtils.hasField(stateJson, "properties")) {
JsonUtils.getJsonObject(stateJson, "properties").entrySet().forEach(p -> properties.put(p.getKey(), p.getValue().getAsString()));
}
return new Tuple<>(JsonUtils.getString(stateJson, "name"), properties);
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
public static PropertyState getPropertyState(IBlockState state, JsonObject parent, String elementName) {
JsonObject jsonProperty = JsonUtils.getJsonObject(parent, elementName);
if (jsonProperty.entrySet().isEmpty()) {
throw new JsonParseException("Expected at least one property defined for " + elementName + " in " + parent.toString());
}
Entry<String, JsonElement> propJson = jsonProperty.entrySet().iterator().next();
String propName = propJson.getKey();
String propValue = propJson.getValue().getAsString();
return BlockTools.getPropertyState(state.getBlock(), state.getBlock().getBlockState(), propName, propValue);
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public void parse(JsonObject json) {
JsonArray plantables = JsonUtils.getJsonArray(json, "soils");
for (JsonElement t : plantables) {
soilBlocks.add(JsonHelper.getBlockStateMatcher(JsonUtils.getJsonObject(t, "")));
}
}
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public void parse(JsonObject json) {
JsonArray saplings = JsonUtils.getJsonArray(json, "saplings");
for (JsonElement e : saplings) {
JsonObject saplingDefinition = JsonUtils.getJsonObject(e, "");
TreeFarmRegistry.saplings.add(new Sapling(JsonHelper.getItemStackMatcher(JsonUtils.getJsonObject(saplingDefinition, "sapling")),
saplingDefinition.has("right_click") && JsonUtils.getBoolean(saplingDefinition, "right_click")));
}
}
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public void parse(JsonObject json) {
JsonArray soils = JsonUtils.getJsonArray(json, "soils");
for (JsonElement t : soils) {
soilBlocks.add(JsonHelper.getBlockStateMatcher(JsonUtils.getJsonObject(t, "")));
}
}
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
private Map<String, FactionTradeListTemplate> parseTradeLists(JsonArray tradeLists) {
Map<String, FactionTradeListTemplate> ret = new HashMap<>();
for (JsonElement tradeListElement : tradeLists) {
JsonObject tradeList = JsonUtils.getJsonObject(tradeListElement, "trade_list");
String name = JsonUtils.getString(tradeList, "name");
JsonArray tradesArray = JsonUtils.getJsonArray(tradeList, "trades");
List<FactionTradeTemplate> trades = parseTrades(tradesArray);
ret.put(name, new FactionTradeListTemplate(name, trades));
}
return ret;
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public void parse(JsonObject json) {
JsonArray tillables = JsonUtils.getJsonArray(json, "tillable_mapping");
for (JsonElement t : tillables) {
JsonObject tillableMapping = JsonUtils.getJsonObject(t, "");
BlockStateMatcher tillableState = JsonHelper.getBlockStateMatcher(tillableMapping, "tillable");
IBlockState tilledState = JsonHelper.getBlockState(tillableMapping, "tilled");
tillableBlocks.put(tillableState, tilledState);
soilBlocks.add(JsonHelper.getBlockStateMatcher(tillableMapping, "tilled"));
}
}
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public void parse(JsonObject json) {
JsonArray treeScanners = JsonUtils.getJsonArray(json, "tree_scanners");
for (JsonElement ts : treeScanners) {
JsonObject treeScanner = JsonUtils.getJsonObject(ts, "");
switch (JsonUtils.getString(treeScanner, "type")) {
case "default":
default:
DefaultSearchParser.parse(treeScanner);
}
}
}
代码示例来源:origin: ForestryMC/ForestryMC
@Override
public BookCategory deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
JsonObject object = json.getAsJsonObject();
String name = JsonUtils.getString(object, "name");
ItemStack stack = JsonUtil.deserializeItemStack(JsonUtils.getJsonObject(object, "icon"), ItemStack.EMPTY);
BookCategory category = new BookCategory(name);
category.setStack(stack);
return category;
}
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
public static TableOfContentsElement parse(JsonObject elementJson) {
JsonArray contents = JsonUtils.getJsonArray(elementJson, "items");
ArrayList<TableOfContentsItem> tocItems = new ArrayList<>();
for (JsonElement e : contents) {
JsonObject contentItem = JsonUtils.getJsonObject(e, "");
tocItems.add(new TableOfContentsItem(JsonUtils.getString(contentItem, "text"), JsonUtils.getString(contentItem, "category_link")));
}
return new TableOfContentsElement(tocItems);
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
private FactionNpcDefault parseDefaults(JsonObject json) {
JsonObject defaults = JsonUtils.getJsonObject(json, "defaults");
return new FactionNpcDefault(getAttributes(defaults), getExperienceDrop(defaults).orElse(0),
getCanSwim(defaults).orElse(true), getCanBreakDoors(defaults).orElse(true), getEquipment(defaults),
getAdditionalAttributes(defaults), getEnabled(defaults).orElse(true));
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
private OwnedNpcDefault parseDefaults(JsonObject json) {
JsonObject defaults = JsonUtils.getJsonObject(json, "defaults");
return new OwnedNpcDefault(getTargetList(defaults), getAttributes(defaults), getExperienceDrop(defaults).orElse(0),
getCanSwim(defaults).orElse(true), getCanBreakDoors(defaults).orElse(true), getEquipment(defaults));
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
private List<FactionTradeTemplate> parseTrades(JsonArray trades) {
List<FactionTradeTemplate> ret = new ArrayList<>();
for (JsonElement tradeElement : trades) {
JsonObject trade = JsonUtils.getJsonObject(tradeElement, "trade");
int refillFrequency = JsonUtils.getInt(trade, "refill_frequency");
int maxTrades = JsonUtils.getInt(trade, "max_trades");
List<ItemStack> input = JsonHelper.getItemStacks(JsonUtils.getJsonArray(trade, "input"));
List<ItemStack> output = JsonHelper.getItemStacks(JsonUtils.getJsonArray(trade, "output"));
ret.add(new FactionTradeTemplate(input, output, refillFrequency, maxTrades));
}
return ret;
}
}
代码示例来源:origin: Direwolf20-MC/BuildingGadgets
@Override
public IRecipe parse(final JsonContext context, final JsonObject json) {
final String group = JsonUtils.getString(json, "group", "");
final CraftingHelper.ShapedPrimer primer = parseShaped(context, json);
final ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
return new ConstructionPasteRecipeHandler(group.isEmpty() ? null : new ResourceLocation(group), result, primer);
}
代码示例来源:origin: MrCrayfish/MrCrayfishFurnitureMod
@Override
public IRecipe parse(final JsonContext context, final JsonObject json)
{
final String group = JsonUtils.getString(json, "group", "");
final NonNullList<Ingredient> ingredients = RecipeUtil.parseShapeless(context, json);
final ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
return new RecipeCuttingShapeless(group.isEmpty() ? null : new ResourceLocation(group), ingredients, result);
}
}
内容来源于网络,如有侵权,请联系作者删除!