use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.
the class ForgeItemTagsProvider method addColored.
private void addColored(Consumer<Tag.Named<Item>> consumer, Tag.Named<Item> group, String pattern) {
String prefix = group.getName().getPath().toUpperCase(Locale.ENGLISH) + '_';
for (DyeColor color : DyeColor.values()) {
ResourceLocation key = new ResourceLocation("minecraft", pattern.replace("{color}", color.getName()));
Tag.Named<Item> tag = getForgeItemTag(prefix + color.getName());
Item item = ForgeRegistries.ITEMS.getValue(key);
if (item == null || item == Items.AIR)
throw new IllegalStateException("Unknown vanilla item: " + key.toString());
tag(tag).add(item);
consumer.accept(tag);
}
}
use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.
the class CraftingHelper method getCondition.
public static ICondition getCondition(JsonObject json) {
ResourceLocation type = new ResourceLocation(GsonHelper.getAsString(json, "type"));
IConditionSerializer<?> serializer = conditions.get(type);
if (serializer == null)
throw new JsonSyntaxException("Unknown condition type: " + type.toString());
return serializer.read(json);
}
use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.
the class CraftingHelper method register.
public static IConditionSerializer<?> register(IConditionSerializer<?> serializer) {
ResourceLocation key = serializer.getID();
if (conditions.containsKey(key))
throw new IllegalStateException("Duplicate recipe condition serializer: " + key);
conditions.put(key, serializer);
return serializer;
}
use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.
the class CraftingHelper method write.
public static <T extends Ingredient> void write(FriendlyByteBuf buffer, T ingredient) {
// I wonder if there is a better way generic wise...
@SuppressWarnings("unchecked") IIngredientSerializer<T> serializer = (IIngredientSerializer<T>) ingredient.getSerializer();
ResourceLocation key = ingredients.inverse().get(serializer);
if (key == null)
throw new IllegalArgumentException("Tried to serialize unregistered Ingredient: " + ingredient + " " + serializer);
if (serializer != VanillaIngredientSerializer.INSTANCE) {
// Marker to know there is a custom ingredient
buffer.writeVarInt(-1);
buffer.writeResourceLocation(key);
}
serializer.write(buffer, ingredient);
}
use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.
the class CraftingHelper method getItemStack.
public static ItemStack getItemStack(JsonObject json, boolean readNBT, boolean disallowsAirInRecipe) {
String itemName = GsonHelper.getAsString(json, "item");
ResourceLocation itemKey = new ResourceLocation(itemName);
if (!ForgeRegistries.ITEMS.containsKey(itemKey))
throw new JsonSyntaxException("Unknown item '" + itemName + "'");
Item item = ForgeRegistries.ITEMS.getValue(itemKey);
if (disallowsAirInRecipe && item == Items.AIR)
throw new JsonSyntaxException("Invalid item: " + itemName);
if (readNBT && json.has("nbt")) {
// Lets hope this works? Needs test
try {
JsonElement element = json.get("nbt");
CompoundTag nbt;
if (element.isJsonObject())
nbt = TagParser.parseTag(GSON.toJson(element));
else
nbt = TagParser.parseTag(GsonHelper.convertToString(element, "nbt"));
CompoundTag tmp = new CompoundTag();
if (nbt.contains("ForgeCaps")) {
tmp.put("ForgeCaps", nbt.get("ForgeCaps"));
nbt.remove("ForgeCaps");
}
tmp.put("tag", nbt);
tmp.putString("id", itemName);
tmp.putInt("Count", GsonHelper.getAsInt(json, "count", 1));
return ItemStack.of(tmp);
} catch (CommandSyntaxException e) {
throw new JsonSyntaxException("Invalid NBT Entry: " + e.toString());
}
}
return new ItemStack(item, GsonHelper.getAsInt(json, "count", 1));
}
Aggregations