net.minecraft.util.JsonUtils.getString()方法的使用及代码示例

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

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

JsonUtils.getString介绍

暂无

代码示例

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

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

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

@Nullable
private EnumFacing parseCullFace( JsonObject object )
{
  String s = JsonUtils.getString( object, "cullface", "" );
  return EnumFacing.byName( s );
}

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

public static ItemPredicate deserialize( JsonObject jsonobject )
{
  if( jsonobject.has( "part" ) )
  {
    return new PartItemPredicate( JsonUtils.getString( jsonobject, "part" ) );
  }
  else
  {
    return ItemPredicate.ANY;
  }
}

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

@Override
public IRecipe parse( JsonContext context, JsonObject json )
{
  String type = JsonUtils.getString( json, "type" );
  if( type.contains( "shaped" ) )
  {
    return shapedFactory( context, json );
  }
  else if( type.contains( "shapeless" ) )
  {
    return shapelessFactory( context, json );
  }
  else
  {
    throw new JsonSyntaxException( "Applied Energistics 2 was given a custom recipe that it does not know how to handle!\n" + "Type should either be '" + AppEng.MOD_ID + ":shapeless' or '" + AppEng.MOD_ID + ":shaped', got '" + type + "'!" );
  }
}

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

private static ShapedOreRecipe shapedFactory( JsonContext context, JsonObject json )
  String group = JsonUtils.getString( json, "group", "" );
  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() )

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

private void register( JsonObject json )
{
  if( json == null || json.isJsonNull() )
  {
    throw new JsonSyntaxException( "Json cannot be null" );
  }
  String type = this.ctx.appendModId( JsonUtils.getString( json, "type" ) );
  if( type.isEmpty() )
  {
    throw new JsonSyntaxException( "Recipe type can not be an empty string" );
  }
  IAERecipeFactory factory = this.factories.get( new ResourceLocation( type ) );
  if( factory == null )
  {
    throw new JsonSyntaxException( "Unknown recipe type: " + type );
  }
  factory.register( json, 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: 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

String mode = JsonUtils.getString( json, "mode" );

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

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

代码示例来源:origin: ForestryMC/ForestryMC

@Override
  public SetSpeciesNBT deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn) {
    String speciesUid = JsonUtils.getString(object, "speciesUid");
    return new SetSpeciesNBT(conditionsIn, speciesUid);
  }
}

代码示例来源:origin: CoFH/CoFHCore

@Nonnull
@Override
public Ingredient parse(JsonContext context, JsonObject json) {
  String fluidName = JsonUtils.getString(json, "fluid");
  return new FluidIngredient(fluidName);
}

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

public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) {
  String uid = JsonUtils.getString(json, "uid");
  IAllele allele = AlleleManager.alleleRegistry.getAllele(uid);
  if (allele == null) {
    throw new JsonSyntaxException("Unknown allele '" + uid + "'");
  } else {
    return new Instance(allele);
  }
}

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

@Override
public void parse(JsonObject json) {
  String name = JsonUtils.getString(json, "name");
  int time = JsonUtils.getInt(json, "time");
  Set<String> dependencies = getDependencies(json);
  Set<Ingredient> resources = getResources(json);
  researchGoals.put(name, new ResearchGoal(name, dependencies, resources, time));
}

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

相关文章