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

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

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

JsonUtils.getInt介绍

暂无

代码示例

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

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

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

public WorldTime deserialize(JsonObject json, JsonDeserializationContext context) {
    return new WorldTime(JsonUtils.getInt(json, "min", 0), JsonUtils.getInt(json, "max", 23999));
  }
}

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

public ConditionTime deserialize(JsonObject json, JsonDeserializationContext context) {
    return new ConditionTime(JsonUtils.getInt(json, "from", 0), JsonUtils.getInt(json, "to", 24000));
  }
}

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

public Between deserialize(JsonObject json, JsonDeserializationContext context) {
    return new Between(JsonUtils.getInt(json, "from", 0), JsonUtils.getInt(json, "to", 0));
  }
}

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

public Between100 deserialize(JsonObject json, JsonDeserializationContext context) {
    return new Between100(JsonUtils.getInt(json, "from", 0), JsonUtils.getInt(json, "to", 0));
  }
}

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

public static ICrop parse(BlockStateMatcher stateMatcher, JsonObject properties) {
    return new CropTall(stateMatcher, JsonUtils.getInt(properties, "height"));
  }
}

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

public static ImageElement parse(JsonObject elementJson) {
  return new ImageElement(JsonUtils.getString(elementJson, "path"), JsonUtils.getInt(elementJson, "width"),
      JsonUtils.getInt(elementJson, "height"));
}

代码示例来源:origin: TeamLapen/Vampirism

@Override
public SetItemBloodCharge deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn) {
  if (object.has("charge")) {
    int value = JsonUtils.getInt(object, "charge");
    return new SetItemBloodCharge(conditionsIn, Math.max(0, value), -1, -1);
  } else if (object.has("min_charge") && object.has("max_charge")) {
    int l = JsonUtils.getInt(object, "min_charge");
    int u = JsonUtils.getInt(object, "max_charge");
    return new SetItemBloodCharge(conditionsIn, -1, Math.max(0, l), Math.max(0, u));
  } else {
    throw new JsonSyntaxException("Need charge property for vampirism:set_item_blood_charge");
  }
}

代码示例来源:origin: joshiejack/Mariculture

public RodStrength deserialize(JsonObject json, JsonDeserializationContext context) {
    return new RodStrength(JsonUtils.getInt(json, "strength", 1));
  }
}

代码示例来源:origin: CyclopsMC/EvilCraft

@Override
public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) {
  JsonElement jsonElement = json.get("min_entities");
  int minEntities = 0;
  if (jsonElement != null && !jsonElement.isJsonNull()) {
    minEntities = JsonUtils.getInt(json, "min_entities");
  }
  return new Instance(getId(), minEntities, EntityPredicate.deserialize(json.get("entity")));
}

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

public static void parse(JsonObject treeScanner) {
  Predicate<IBlockState> trunkMatcher = JsonHelper.getBlockStateMatcher(treeScanner, "trunks", "trunk");
  Predicate<IBlockState> leafMatcher = JsonHelper.getBlockStateMatcher(treeScanner, "leaves", "leaf");
  int maxLeafDistance = JsonUtils.getInt(treeScanner, "max_leaf_distance");
  DefaultTreeScanner.INextPositionGetter nextPosGetter = parseNextPositionGetter(treeScanner);
  Optional<DefaultTreeScanner> currentScanner = treeScanners.stream().filter(m -> m instanceof DefaultTreeScanner && ((DefaultTreeScanner) m).getTrunkMatcher().hashCode() == trunkMatcher.hashCode()).map(m -> (DefaultTreeScanner) m).findFirst();
  if (currentScanner.isPresent()) {
    currentScanner.get().addLeafMatcher(leafMatcher);
  } else {
    registerTreeScanner(new DefaultTreeScanner(trunkMatcher, leafMatcher, nextPosGetter, maxLeafDistance));
  }
}

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

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

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

@Nonnull
  @Override
  public Ingredient parse(JsonContext context, JsonObject json) {
    String name = JsonUtils.getString(json, "fluid");
    int amount = JsonUtils.getInt(json, "amount", 1000);
    Fluid fluid = FluidRegistry.getFluid(name);
    if (fluid == null)
      throw new JsonSyntaxException("Fluid with name " + name + " could not be found");
    return new IngredientFluidStack(fluid, amount);
  }
}

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

@Override
  public Ingredient parse(JsonContext context, JsonObject json) {
    String name = JsonUtils.getString(json, "name");
    int amount = JsonUtils.getInt(json, "amount", 1);
    for (MetaItem<?> item : MetaItems.ITEMS) {
      MetaItem<?>.MetaValueItem value = item.getItem(name);
      if (value != null) {
        return Ingredient.fromStacks(value.getStackForm(amount));
      }
    }
    return Ingredient.EMPTY;
  }
}

代码示例来源:origin: SquidDev-CC/plethora

@Nonnull
  @Override
  public Ingredient parse(JsonContext context, JsonObject json) {
    ResourceLocation enchantmentId = new ResourceLocation(JsonUtils.getString(json, "id"));
    int level = JsonUtils.getInt(json, "level", 1);
    if (!Enchantment.REGISTRY.containsKey(enchantmentId)) {
      throw new JsonSyntaxException("Unknown enchantment '" + enchantmentId + "'");
    }
    Enchantment enchantment = Enchantment.REGISTRY.getObject(enchantmentId);
    return new IngredientEnchanted(enchantment, level);
  }
}

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

public static void registerIngredients() {
  CraftingHelper.register(new ResourceLocation(AncientWarfareCore.MOD_ID, "item_count"), (IIngredientFactory) (c, j) -> new IngredientCount(CraftingHelper.getItemStack(j, c)));
  CraftingHelper.register(new ResourceLocation(AncientWarfareCore.MOD_ID, "ore_dict_count"), (IIngredientFactory) (c, j) -> new IngredientOreCount(JsonUtils.getString(j, "ore"), JsonUtils.getInt(j, "count", 1)));
  CraftingHelper.register(new ResourceLocation(AncientWarfareCore.MOD_ID, "item_nbt_relaxed"), (IIngredientFactory) (c, j) -> new IngredientNBTRelaxed(CraftingHelper.getItemStack(j, c)));
}

相关文章