Search in sources :

Example 1 with MaterialVariantId

use of slimeknights.tconstruct.library.materials.definition.MaterialVariantId in project TinkersConstruct by SlimeKnights.

the class JEIPlugin method registerItemSubtypes.

@Override
public void registerItemSubtypes(ISubtypeRegistration registry) {
    // retexturable blocks
    IIngredientSubtypeInterpreter<ItemStack> tables = (stack, context) -> {
        if (context == UidContext.Ingredient) {
            return RetexturedBlockItem.getTextureName(stack);
        }
        return IIngredientSubtypeInterpreter.NONE;
    };
    registry.registerSubtypeInterpreter(TinkerTables.craftingStation.asItem(), tables);
    registry.registerSubtypeInterpreter(TinkerTables.partBuilder.asItem(), tables);
    registry.registerSubtypeInterpreter(TinkerTables.tinkerStation.asItem(), tables);
    registry.registerSubtypeInterpreter(TinkerTables.tinkersAnvil.asItem(), tables);
    registry.registerSubtypeInterpreter(TinkerTables.scorchedAnvil.asItem(), tables);
    IIngredientSubtypeInterpreter<ItemStack> toolPartInterpreter = (stack, context) -> {
        MaterialVariantId materialId = IMaterialItem.getMaterialFromStack(stack);
        if (materialId.equals(IMaterial.UNKNOWN_ID)) {
            return IIngredientSubtypeInterpreter.NONE;
        }
        return materialId.getId().toString();
    };
    // parts
    for (Item item : TinkerTags.Items.TOOL_PARTS.getValues()) {
        registry.registerSubtypeInterpreter(item, toolPartInterpreter);
    }
    // tools
    Item slimeskull = TinkerTools.slimesuit.get(ArmorSlotType.HELMET);
    registry.registerSubtypeInterpreter(slimeskull, ToolSubtypeInterpreter.ALWAYS);
    for (Item item : TinkerTags.Items.MULTIPART_TOOL.getValues()) {
        if (item != slimeskull) {
            registry.registerSubtypeInterpreter(item, ToolSubtypeInterpreter.INGREDIENT);
        }
    }
    registry.registerSubtypeInterpreter(TinkerSmeltery.copperCan.get(), (stack, context) -> CopperCanItem.getSubtype(stack));
    registry.registerSubtypeInterpreter(TinkerModifiers.creativeSlotItem.get(), (stack, context) -> {
        SlotType slotType = CreativeSlotItem.getSlot(stack);
        return slotType != null ? slotType.getName() : "";
    });
}
Also used : HeatingStructureScreen(slimeknights.tconstruct.smeltery.client.screen.HeatingStructureScreen) Item(net.minecraft.world.item.Item) MeltingFuel(slimeknights.tconstruct.library.recipe.fuel.MeltingFuel) RecipeHelper(slimeknights.mantle.recipe.helper.RecipeHelper) Config(slimeknights.tconstruct.common.config.Config) UidContext(mezz.jei.api.ingredients.subtypes.UidContext) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) SlotType(slimeknights.tconstruct.library.tools.SlotType) CastItemObject(slimeknights.tconstruct.common.registration.CastItemObject) CastingTableCategory(slimeknights.tconstruct.plugin.jei.casting.CastingTableCategory) ArmorSlotType(slimeknights.tconstruct.tools.item.ArmorSlotType) RecipeType(net.minecraft.world.item.crafting.RecipeType) VanillaRecipeCategoryUid(mezz.jei.api.constants.VanillaRecipeCategoryUid) ModList(net.minecraftforge.fml.ModList) IGuiHandlerRegistration(mezz.jei.api.registration.IGuiHandlerRegistration) IGuiContainerHandler(mezz.jei.api.gui.handlers.IGuiContainerHandler) TinkerTools(slimeknights.tconstruct.tools.TinkerTools) AlloyRecipe(slimeknights.tconstruct.library.recipe.alloying.AlloyRecipe) SeveringCategory(slimeknights.tconstruct.plugin.jei.entity.SeveringCategory) IDisplayableCastingRecipe(slimeknights.tconstruct.library.recipe.casting.IDisplayableCastingRecipe) IMaterialItem(slimeknights.tconstruct.library.tools.part.IMaterialItem) IIngredientType(mezz.jei.api.ingredients.IIngredientType) Modifier(slimeknights.tconstruct.library.modifiers.Modifier) FluidStack(net.minecraftforge.fluids.FluidStack) CastingBasinCategory(slimeknights.tconstruct.plugin.jei.casting.CastingBasinCategory) ItemStack(net.minecraft.world.item.ItemStack) MaterialIdNBT(slimeknights.tconstruct.library.tools.nbt.MaterialIdNBT) IRecipeCatalystRegistration(mezz.jei.api.registration.IRecipeCatalystRegistration) IDisplayModifierRecipe(slimeknights.tconstruct.library.recipe.modifiers.adding.IDisplayModifierRecipe) MeltingRecipe(slimeknights.tconstruct.library.recipe.melting.MeltingRecipe) EntityType(net.minecraft.world.entity.EntityType) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ModifierBookmarkIngredientRenderer(slimeknights.tconstruct.plugin.jei.modifiers.ModifierBookmarkIngredientRenderer) TinkerModifiers(slimeknights.tconstruct.tools.TinkerModifiers) IModPlugin(mezz.jei.api.IModPlugin) Container(net.minecraft.world.Container) EntityIngredientRenderer(slimeknights.tconstruct.plugin.jei.entity.EntityIngredientRenderer) IModifiableDisplay(slimeknights.tconstruct.library.tools.item.IModifiableDisplay) IModIngredientRegistration(mezz.jei.api.registration.IModIngredientRegistration) IRecipeTransferRegistration(mezz.jei.api.registration.IRecipeTransferRegistration) CopperCanItem(slimeknights.tconstruct.smeltery.item.CopperCanItem) MeltingCategory(slimeknights.tconstruct.plugin.jei.melting.MeltingCategory) Nullable(javax.annotation.Nullable) RecipeTypes(slimeknights.tconstruct.library.recipe.RecipeTypes) MelterScreen(slimeknights.tconstruct.smeltery.client.screen.MelterScreen) DefaultEntityMeltingRecipe(slimeknights.tconstruct.plugin.jei.entity.DefaultEntityMeltingRecipe) Tag(net.minecraft.tags.Tag) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId) Pattern(slimeknights.tconstruct.library.recipe.partbuilder.Pattern) IScreenWithFluidTank(slimeknights.tconstruct.smeltery.client.screen.IScreenWithFluidTank) TinkerSmeltery(slimeknights.tconstruct.smeltery.TinkerSmeltery) RetexturedBlockItem(slimeknights.mantle.item.RetexturedBlockItem) MoldingRecipe(slimeknights.tconstruct.library.recipe.molding.MoldingRecipe) ModifierIngredientHelper(slimeknights.tconstruct.plugin.jei.modifiers.ModifierIngredientHelper) ResourceLocation(net.minecraft.resources.ResourceLocation) PatternIngredientHelper(slimeknights.tconstruct.plugin.jei.partbuilder.PatternIngredientHelper) EntityIngredientHelper(slimeknights.tconstruct.plugin.jei.entity.EntityIngredientHelper) FluidAttributes(net.minecraftforge.fluids.FluidAttributes) EntityMeltingRecipeCategory(slimeknights.tconstruct.plugin.jei.entity.EntityMeltingRecipeCategory) Registry(net.minecraft.core.Registry) IIngredientManager(mezz.jei.api.runtime.IIngredientManager) CreativeSlotItem(slimeknights.tconstruct.tools.item.CreativeSlotItem) IDisplayPartBuilderRecipe(slimeknights.tconstruct.library.recipe.partbuilder.IDisplayPartBuilderRecipe) ModifierEntry(slimeknights.tconstruct.library.modifiers.ModifierEntry) MeltingFuelHandler(slimeknights.tconstruct.plugin.jei.melting.MeltingFuelHandler) PartBuilderCategory(slimeknights.tconstruct.plugin.jei.partbuilder.PartBuilderCategory) EntityMeltingRecipe(slimeknights.tconstruct.library.recipe.entitymelting.EntityMeltingRecipe) IMaterial(slimeknights.tconstruct.library.materials.definition.IMaterial) TinkerTables(slimeknights.tconstruct.tables.TinkerTables) TinkerTags(slimeknights.tconstruct.common.TinkerTags) IRecipeCategoryRegistration(mezz.jei.api.registration.IRecipeCategoryRegistration) Collectors(java.util.stream.Collectors) List(java.util.List) FoundryCategory(slimeknights.tconstruct.plugin.jei.melting.FoundryCategory) RecipeManager(net.minecraft.world.item.crafting.RecipeManager) IIngredientSubtypeInterpreter(mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter) ISubtypeRegistration(mezz.jei.api.registration.ISubtypeRegistration) MaterialRecipe(slimeknights.tconstruct.library.recipe.material.MaterialRecipe) VanillaTypes(mezz.jei.api.constants.VanillaTypes) IJeiRuntime(mezz.jei.api.runtime.IJeiRuntime) AbstractContainerScreen(net.minecraft.client.gui.screens.inventory.AbstractContainerScreen) SeveringRecipe(slimeknights.tconstruct.library.recipe.modifiers.severing.SeveringRecipe) JeiPlugin(mezz.jei.api.JeiPlugin) ImmutableList(com.google.common.collect.ImmutableList) Minecraft(net.minecraft.client.Minecraft) ItemLike(net.minecraft.world.level.ItemLike) IRecipeRegistration(mezz.jei.api.registration.IRecipeRegistration) Fluid(net.minecraft.world.level.material.Fluid) TinkerMaterials(slimeknights.tconstruct.shared.TinkerMaterials) SerializationTags(net.minecraft.tags.SerializationTags) PatternIngredientRenderer(slimeknights.tconstruct.plugin.jei.partbuilder.PatternIngredientRenderer) TinkerFluids(slimeknights.tconstruct.fluids.TinkerFluids) MaterialItemList(slimeknights.tconstruct.plugin.jei.partbuilder.MaterialItemList) SmelteryCompat(slimeknights.tconstruct.smeltery.data.SmelteryCompat) Recipe(net.minecraft.world.item.crafting.Recipe) ModifierRecipeCategory(slimeknights.tconstruct.plugin.jei.modifiers.ModifierRecipeCategory) Comparator(java.util.Comparator) Collections(java.util.Collections) TinkerStationTransferInfo(slimeknights.tconstruct.plugin.jei.transfer.TinkerStationTransferInfo) Item(net.minecraft.world.item.Item) IMaterialItem(slimeknights.tconstruct.library.tools.part.IMaterialItem) CopperCanItem(slimeknights.tconstruct.smeltery.item.CopperCanItem) RetexturedBlockItem(slimeknights.mantle.item.RetexturedBlockItem) CreativeSlotItem(slimeknights.tconstruct.tools.item.CreativeSlotItem) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId) ItemStack(net.minecraft.world.item.ItemStack) SlotType(slimeknights.tconstruct.library.tools.SlotType) ArmorSlotType(slimeknights.tconstruct.tools.item.ArmorSlotType)

Example 2 with MaterialVariantId

use of slimeknights.tconstruct.library.materials.definition.MaterialVariantId in project TinkersConstruct by SlimeKnights.

the class MaterialRenderInfoLoader method onReloadSafe.

@Override
public void onReloadSafe(ResourceManager manager) {
    // first, we need to fetch all relevant JSON files
    int trim = FOLDER.length() + 1;
    Map<MaterialVariantId, MaterialRenderInfo> map = new HashMap<>();
    for (ResourceLocation location : manager.listResources(FOLDER, (loc) -> loc.endsWith(".json"))) {
        // clean up ID by trimming off the extension and folder
        String path = location.getPath();
        String localPath = path.substring(trim, path.length() - 5);
        // locate variant as a subfolder, and create final ID
        String variant = "";
        int slashIndex = localPath.lastIndexOf('/');
        if (slashIndex >= 0) {
            variant = localPath.substring(slashIndex + 1);
            localPath = localPath.substring(0, slashIndex);
        }
        MaterialVariantId id = MaterialVariantId.create(location.getNamespace(), localPath, variant);
        // read in the JSON data
        try (Resource resource = manager.getResource(location);
            InputStream inputstream = resource.getInputStream();
            Reader reader = new BufferedReader(new InputStreamReader(inputstream, StandardCharsets.UTF_8))) {
            MaterialRenderInfoJson json = GSON.fromJson(reader, MaterialRenderInfoJson.class);
            if (json == null) {
                log.error("Couldn't load data file {} from {} as it's null or empty", id, location);
            } else {
                // parse it into material render info
                MaterialRenderInfo old = map.put(id, loadRenderInfo(id, json));
                if (old != null) {
                    throw new IllegalStateException("Duplicate data file ignored with ID " + id);
                }
            }
        } catch (IllegalArgumentException | IOException | JsonParseException jsonparseexception) {
            log.error("Couldn't parse data file {} from {}", id, location, jsonparseexception);
        }
    }
    // store the list immediately, otherwise it is not in place in time for models to load
    this.renderInfos = map;
    log.debug("Loaded material render infos: {}", Util.toIndentedStringList(map.keySet()));
    log.info("{} material render infos loaded", map.size());
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Resource(net.minecraft.server.packs.resources.Resource) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId) ResourceLocation(net.minecraft.resources.ResourceLocation) BufferedReader(java.io.BufferedReader)

Example 3 with MaterialVariantId

use of slimeknights.tconstruct.library.materials.definition.MaterialVariantId in project TinkersConstruct by SlimeKnights.

the class MaterialIdNBT method readFromNBT.

/**
 * Parses the material list from NBT
 * @param nbt  NBT instance
 * @return  MaterialNBT instance
 */
public static MaterialIdNBT readFromNBT(@Nullable Tag nbt) {
    if (nbt == null || nbt.getId() != Tag.TAG_LIST) {
        return EMPTY;
    }
    ListTag listNBT = (ListTag) nbt;
    if (listNBT.getElementType() != Tag.TAG_STRING) {
        return EMPTY;
    }
    List<MaterialVariantId> materials = listNBT.stream().map(Tag::getAsString).map(MaterialVariantId::tryParse).filter(Objects::nonNull).collect(Collectors.toList());
    return new MaterialIdNBT(materials);
}
Also used : MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId) ListTag(net.minecraft.nbt.ListTag)

Example 4 with MaterialVariantId

use of slimeknights.tconstruct.library.materials.definition.MaterialVariantId in project TinkersConstruct by SlimeKnights.

the class MaterialRecipeSerializer method fromNetworkSafe.

@Nullable
@Override
protected MaterialRecipe fromNetworkSafe(ResourceLocation recipeId, FriendlyByteBuf buffer) {
    String group = buffer.readUtf(Short.MAX_VALUE);
    Ingredient ingredient = Ingredient.fromNetwork(buffer);
    int value = buffer.readInt();
    int needed = buffer.readInt();
    MaterialVariantId materialId = MaterialVariantId.parse(buffer.readUtf(Short.MAX_VALUE));
    ItemOutput leftover = ItemOutput.read(buffer);
    return new MaterialRecipe(recipeId, group, ingredient, value, needed, materialId, leftover);
}
Also used : ItemOutput(slimeknights.mantle.recipe.helper.ItemOutput) Ingredient(net.minecraft.world.item.crafting.Ingredient) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId) Nullable(javax.annotation.Nullable)

Example 5 with MaterialVariantId

use of slimeknights.tconstruct.library.materials.definition.MaterialVariantId in project TinkersConstruct by SlimeKnights.

the class MaterialRecipeSerializer method fromJson.

@Override
public MaterialRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
    String group = GsonHelper.getAsString(json, "group", "");
    Ingredient ingredient = Ingredient.fromJson(JsonHelper.getElement(json, "ingredient"));
    int value = GsonHelper.getAsInt(json, "value", 1);
    int needed = GsonHelper.getAsInt(json, "needed", 1);
    MaterialVariantId materialId = MaterialVariantId.fromJson(json, "material");
    ItemOutput leftover = EMPTY;
    if (value > 1 && json.has("leftover")) {
        leftover = ItemOutput.fromJson(json.get("leftover"));
    }
    return new MaterialRecipe(recipeId, group, ingredient, value, needed, materialId, leftover);
}
Also used : ItemOutput(slimeknights.mantle.recipe.helper.ItemOutput) Ingredient(net.minecraft.world.item.crafting.Ingredient) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId)

Aggregations

MaterialVariantId (slimeknights.tconstruct.library.materials.definition.MaterialVariantId)15 ResourceLocation (net.minecraft.resources.ResourceLocation)5 MaterialId (slimeknights.tconstruct.library.materials.definition.MaterialId)5 Nullable (javax.annotation.Nullable)4 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)4 Component (net.minecraft.network.chat.Component)3 TextComponent (net.minecraft.network.chat.TextComponent)3 IMaterialRegistry (slimeknights.tconstruct.library.materials.IMaterialRegistry)3 IMaterial (slimeknights.tconstruct.library.materials.definition.IMaterial)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 Registry (net.minecraft.core.Registry)2 ListTag (net.minecraft.nbt.ListTag)2 Ingredient (net.minecraft.world.item.crafting.Ingredient)2 ItemOutput (slimeknights.mantle.recipe.helper.ItemOutput)2 ModifierEntry (slimeknights.tconstruct.library.modifiers.ModifierEntry)2 PartRequirement (slimeknights.tconstruct.library.tools.definition.PartRequirement)2 MaterialNBT (slimeknights.tconstruct.library.tools.nbt.MaterialNBT)2 TooltipKey (slimeknights.tconstruct.library.utils.TooltipKey)2 Multimap (com.google.common.collect.Multimap)1