net.minecraft.util.JsonUtils类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中net.minecraft.util.JsonUtils类的一些代码示例,展示了JsonUtils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonUtils类的具体详情如下:
包路径:net.minecraft.util.JsonUtils
类名称:JsonUtils

JsonUtils介绍

暂无

代码示例

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

private static ShapedOreRecipe shapedFactory( JsonContext context, JsonObject json )
  String group = JsonUtils.getString( json, "group", "" );
  for( Map.Entry<String, JsonElement> entry : JsonUtils.getJsonObject( json, "key" ).entrySet() )
  JsonArray patternJ = JsonUtils.getJsonArray( json, "pattern" );
  for( int x = 0; x < pattern.length; ++x )
    String line = JsonUtils.getString( patternJ.get( x ), "pattern[" + x + "]" );
    if( x > 0 && pattern[0].length() != line.length() )
  primer.width = pattern[0].length();
  primer.height = pattern.length;
  primer.mirrored = JsonUtils.getBoolean( json, "mirrored", true );
  primer.input = NonNullList.withSize( primer.width * primer.height, net.minecraft.item.crafting.Ingredient.EMPTY );

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

private static ItemStack getPart( JsonObject resultObject )
{
  String ingredient = JsonUtils.getString( resultObject, "part" );
  Object result = AEApi.instance().registries().recipes().resolveItem( AppEng.MOD_ID, ingredient );
  if( result instanceof ResolverResult )
  {
    ResolverResult resolverResult = (ResolverResult) result;
    Item item = Item.getByNameOrId( AppEng.MOD_ID + ":" + resolverResult.itemName );
    if( item == null )
    {
      AELog.warn( "item was null for " + resolverResult.itemName + " ( " + ingredient + " )!" );
      throw new JsonSyntaxException( "Got a null item for " + resolverResult.itemName + " ( " + ingredient + " ). This should never happen!" );
    }
    return new ItemStack( item, JsonUtils.getInt( resultObject, "count", 1 ), resolverResult.damageValue, resolverResult.compound );
  }
  else
  {
    throw new JsonSyntaxException( "Couldn't find the resulting item in AE. This means AE was provided a recipe that it shouldn't be handling.\n" + "Was looking for : '" + ingredient + "'." );
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

JsonObject json = JsonUtils.fromJson( GSON, reader, JsonObject.class );
if( json.has( "conditions" ) && !CraftingHelper.processConditions( JsonUtils.getJsonArray( json, "conditions" ), this.ctx ) )

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
  public BooleanSupplier parse( JsonContext jsonContext, JsonObject jsonObject )
  {
    final boolean result;

    if( JsonUtils.isString( jsonObject, JSON_MATERIAL_KEY ) )
    {
      final String material = JsonUtils.getString( jsonObject, JSON_MATERIAL_KEY );
      final Object item = Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, material );

      result = item != null;
    }
    else
    {
      result = false;
    }

    return () -> result;

  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
  public BooleanSupplier parse( JsonContext jsonContext, JsonObject jsonObject )
  {
    final boolean result;

    if( JsonUtils.isJsonArray( jsonObject, JSON_FEATURES_KEY ) )
    {
      final JsonArray features = JsonUtils.getJsonArray( jsonObject, JSON_FEATURES_KEY );

      result = Stream.of( features )
          .allMatch( p -> AEConfig.instance().isFeatureEnabled( AEFeature.valueOf( p.getAsString().toUpperCase( Locale.ENGLISH ) ) ) );
    }
    else if( JsonUtils.isString( jsonObject, JSON_FEATURES_KEY ) )
    {
      final String featureName = JsonUtils.getString( jsonObject, JSON_FEATURES_KEY ).toUpperCase( Locale.ENGLISH );
      final AEFeature feature = AEFeature.valueOf( featureName );

      result = AEConfig.instance().isFeatureEnabled( feature );
    }
    else
    {
      result = false;
    }

    return () -> result;
  }
}

代码示例来源: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: 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

private static ShapelessOreRecipe shapelessFactory( 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" );
    }

    return new ShapelessOreRecipe( group.isEmpty() ? null : new ResourceLocation( group ), ings, getResult( json, context ) );
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

private String parseTexture( JsonObject object )
{
  return JsonUtils.getString( object, "texture" );
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

@Override
public void parse(JsonObject json) {
  JsonArray fruits = JsonUtils.getJsonArray(json, "fruits");
  for (JsonElement e : fruits) {
    JsonObject fruit = JsonUtils.getJsonObject(e, "");
    parseFruit(fruit);
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

protected int parseTintIndex( JsonObject object )
{
  return JsonUtils.getInt( object, "tintindex", -1 );
}

代码示例来源: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

@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

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: Vazkii/Botania

@Override
  public BooleanSupplier parse(JsonContext context, JsonObject json) {
    boolean value = JsonUtils.getBoolean(json , "value", true);
    return () -> ConfigHandler.fluxfieldEnabled == value;
  }
}

代码示例来源:origin: SleepyTrousers/EnderIO

@Override
public @Nonnull Potion deserialize(@Nonnull JsonObject object, @Nonnull JsonDeserializationContext deserializationContext,
  @Nonnull LootCondition[] conditionsIn) {
 return new Potion(conditionsIn, JsonUtils.getString(object, "name"), JsonUtils.getBoolean(object, "splash"));
}

代码示例来源: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

@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

try {
    reader = Files.newBufferedReader(fPath);
    JsonObject[] json = JsonUtils.fromJson(GSON, reader, JsonObject[].class);
    LOAD_CONSTANTS.invoke(ctx, new Object[] {json});
try {
  reader = Files.newBufferedReader(file);
  JsonObject json = JsonUtils.fromJson(GSON, reader, JsonObject.class);
  String type = ctx.appendModId(JsonUtils.getString(json, "type"));
  if (type.equals(AncientWarfareCore.MOD_ID + ":research_recipe") || type.equals(AncientWarfareCore.MOD_ID + ":shapeless_research_recipe")) {
    ResearchRecipeBase recipe = factory.parse(ctx, json);

代码示例来源:origin: PenguinSquad/Harvest-Festival

public MultipleOf deserialize(JsonObject json, JsonDeserializationContext context) {
    return new MultipleOf(JsonUtils.getInt(json, "of", 0), JsonUtils.getBoolean(json, "reverse", false));
  }
}

相关文章