Search in sources :

Example 1 with RepairKitItem

use of net.silentchaos512.gear.item.RepairKitItem in project Silent-Gear by SilentChaos512.

the class SGearJeiPlugin method registerRecipes.

@Override
public void registerRecipes(IRecipeRegistration reg) {
    assert Minecraft.getInstance().level != null;
    RecipeManager recipeManager = Minecraft.getInstance().level.getRecipeManager();
    // Repair kit hints
    for (RepairKitItem item : Registration.getItems(RepairKitItem.class)) {
        String itemName = NameUtils.fromItem(item).getPath();
        reg.addRecipes(Collections.singleton(new ShapelessRecipe(SilentGear.getId(itemName + "_fill_hint"), "", new ItemStack(item), NonNullList.of(Ingredient.EMPTY, Ingredient.of(item), PartMaterialIngredient.of(PartType.MAIN), PartMaterialIngredient.of(PartType.MAIN), PartMaterialIngredient.of(PartType.MAIN)))), VanillaRecipeCategoryUid.CRAFTING);
        reg.addRecipes(Collections.singleton(new ShapelessRecipe(SilentGear.getId(itemName + "_fill_hint_frag"), "", new ItemStack(item), NonNullList.of(Ingredient.EMPTY, Ingredient.of(item), Ingredient.of(ModItems.FRAGMENT), Ingredient.of(ModItems.FRAGMENT), Ingredient.of(ModItems.FRAGMENT)))), VanillaRecipeCategoryUid.CRAFTING);
    }
    reg.addRecipes(recipeManager.getRecipes().stream().filter(SGearJeiPlugin::isGearCraftingRecipe).collect(Collectors.toList()), GEAR_CRAFTING);
    // Compounders
    reg.addRecipes(recipeManager.getRecipes().stream().filter(r -> r.getType() == CompoundingRecipe.COMPOUNDING_FABRIC_TYPE).collect(Collectors.toList()), Const.COMPOUNDING_FABRIC);
    reg.addRecipes(recipeManager.getRecipes().stream().filter(r -> r.getType() == CompoundingRecipe.COMPOUNDING_GEM_TYPE).collect(Collectors.toList()), Const.COMPOUNDING_GEM);
    reg.addRecipes(recipeManager.getRecipes().stream().filter(r -> r.getType() == CompoundingRecipe.COMPOUNDING_METAL_TYPE).collect(Collectors.toList()), Const.COMPOUNDING_METAL);
    for (int i = 2; i <= 4; ++i) {
        reg.addRecipes(Collections.singleton(CompoundingRecipe.makeExample(Const.FABRIC_COMPOUNDER_INFO, i, new FabricCompoundingRecipe(SilentGear.getId("fabric_example_" + i)))), Const.COMPOUNDING_FABRIC);
        reg.addRecipes(Collections.singleton(CompoundingRecipe.makeExample(Const.GEM_COMPOUNDER_INFO, i, new GemCompoundingRecipe(SilentGear.getId("gem_example_" + i)))), Const.COMPOUNDING_GEM);
        reg.addRecipes(Collections.singleton(CompoundingRecipe.makeExample(Const.METAL_COMPOUNDER_INFO, i, new MetalCompoundingRecipe(SilentGear.getId("metal_example_" + i)))), Const.COMPOUNDING_METAL);
    }
    // Grading
    reg.addRecipes(Collections.singleton(new MaterialGraderRecipeCategory.GraderRecipe()), Const.GRADING);
    // Salvaging
    reg.addRecipes(recipeManager.getRecipes().stream().filter(r -> r.getType() == SalvagingRecipe.SALVAGING_TYPE).collect(Collectors.toList()), Const.SALVAGING);
    addInfoPage(reg, CraftingItems.RED_CARD_UPGRADE);
    addInfoPage(reg, CraftingItems.SPOON_UPGRADE);
    for (Item item : Registration.getItems(item -> item instanceof ICoreTool)) {
        addInfoPage(reg, item);
    }
}
Also used : GemCompoundingRecipe(net.silentchaos512.gear.crafting.recipe.compounder.GemCompoundingRecipe) MetalCompoundingRecipe(net.silentchaos512.gear.crafting.recipe.compounder.MetalCompoundingRecipe) FabricCompoundingRecipe(net.silentchaos512.gear.crafting.recipe.compounder.FabricCompoundingRecipe) ICoreTool(net.silentchaos512.gear.api.item.ICoreTool) RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) Item(net.minecraft.world.item.Item) FragmentItem(net.silentchaos512.gear.item.FragmentItem) CustomMaterialItem(net.silentchaos512.gear.item.CustomMaterialItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with RepairKitItem

use of net.silentchaos512.gear.item.RepairKitItem in project Silent-Gear by SilentChaos512.

the class FillRepairKitRecipe method assemble.

@Override
public ItemStack assemble(CraftingContainer inv) {
    StackList list = StackList.from(inv);
    ItemStack repairKit = list.uniqueOfType(RepairKitItem.class).copy();
    repairKit.setCount(1);
    RepairKitItem repairKitItem = (RepairKitItem) repairKit.getItem();
    for (ItemStack mat : list.allMatches(FillRepairKitRecipe::isRepairMaterial)) {
        if (!repairKitItem.addMaterial(repairKit, mat)) {
            // Repair kit is too full to accept more materials
            return ItemStack.EMPTY;
        }
    }
    return repairKit;
}
Also used : RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) StackList(net.silentchaos512.lib.collection.StackList) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with RepairKitItem

use of net.silentchaos512.gear.item.RepairKitItem in project Silent-Gear by SilentChaos512.

the class QuickRepairRecipe method matches.

@Override
public boolean matches(CraftingContainer inv, Level worldIn) {
    // Need 1 gear, 1 repair kit, and optional materials
    ItemStack gear = ItemStack.EMPTY;
    boolean foundKit = false;
    float repairKitEfficiency = Config.Common.missingRepairKitEfficiency.get().floatValue();
    List<ItemStack> materials = new ArrayList<>();
    for (int i = 0; i < inv.getContainerSize(); ++i) {
        ItemStack stack = inv.getItem(i);
        if (!stack.isEmpty()) {
            // noinspection ChainOfInstanceofChecks
            if (stack.getItem() instanceof ICoreItem) {
                if (!gear.isEmpty()) {
                    return false;
                }
                gear = stack;
            } else if (stack.getItem() instanceof RepairKitItem) {
                if (foundKit) {
                    return false;
                }
                foundKit = true;
                repairKitEfficiency = getKitEfficiency(stack);
            } else if (MaterialManager.from(stack) != null) {
                materials.add(stack);
            } else {
                return false;
            }
        }
    }
    if (gear.isEmpty() || repairKitEfficiency < 0.1E-9)
        return false;
    for (ItemStack stack : materials) {
        if (!ModRecipes.isRepairMaterial(gear, stack)) {
            return false;
        }
    }
    return true;
}
Also used : RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) ArrayList(java.util.ArrayList) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 4 with RepairKitItem

use of net.silentchaos512.gear.item.RepairKitItem in project Silent-Gear by SilentChaos512.

the class QuickRepairRecipe method getRemainingItems.

@Override
public NonNullList<ItemStack> getRemainingItems(CraftingContainer inv) {
    NonNullList<ItemStack> list = NonNullList.withSize(inv.getContainerSize(), ItemStack.EMPTY);
    StackList stackList = StackList.from(inv);
    ItemStack gear = stackList.uniqueMatch(s -> s.getItem() instanceof ICoreItem);
    ItemStack repairKit = stackList.uniqueMatch(s -> s.getItem() instanceof RepairKitItem);
    for (int i = 0; i < list.size(); ++i) {
        ItemStack stack = inv.getItem(i);
        if (stack.getItem() instanceof RepairKitItem) {
            repairWithLooseMaterials(gear, repairKit, stackList.allMatches(mat -> ModRecipes.isRepairMaterial(gear, mat)));
            RepairKitItem item = (RepairKitItem) stack.getItem();
            ItemStack copy = stack.copy();
            item.removeRepairMaterials(copy, item.getRepairMaterials(gear, copy, RepairContext.Type.QUICK));
            list.set(i, copy);
        } else if (stack.hasContainerItem()) {
            list.set(i, stack.getContainerItem());
        }
    }
    return list;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) GearData(net.silentchaos512.gear.util.GearData) ForgeHooks(net.minecraftforge.common.ForgeHooks) RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) MaterialManager(net.silentchaos512.gear.gear.material.MaterialManager) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) CustomRecipe(net.minecraft.world.item.crafting.CustomRecipe) ArrayList(java.util.ArrayList) Const(net.silentchaos512.gear.util.Const) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) Config(net.silentchaos512.gear.config.Config) StackList(net.silentchaos512.lib.collection.StackList) NonNullList(net.minecraft.core.NonNullList) RepairContext(net.silentchaos512.gear.gear.part.RepairContext) ForgeRegistryEntry(net.minecraftforge.registries.ForgeRegistryEntry) ItemStats(net.silentchaos512.gear.api.stats.ItemStats) RecipeSerializer(net.minecraft.world.item.crafting.RecipeSerializer) Collection(java.util.Collection) List(java.util.List) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) ModRecipes(net.silentchaos512.gear.init.ModRecipes) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) StackList(net.silentchaos512.lib.collection.StackList) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 5 with RepairKitItem

use of net.silentchaos512.gear.item.RepairKitItem in project Silent-Gear by SilentChaos512.

the class QuickRepairRecipe method assemble.

@Override
public ItemStack assemble(CraftingContainer inv) {
    StackList list = StackList.from(inv);
    ItemStack gear = list.uniqueOfType(ICoreItem.class).copy();
    ItemStack repairKit = list.uniqueOfType(RepairKitItem.class);
    Collection<ItemStack> mats = list.allMatches(mat -> ModRecipes.isRepairMaterial(gear, mat));
    // Repair with materials first
    repairWithLooseMaterials(gear, repairKit, mats);
    // Then use repair kit, if necessary
    if (gear.getDamageValue() > 0 && repairKit.getItem() instanceof RepairKitItem) {
        RepairKitItem item = (RepairKitItem) repairKit.getItem();
        int value = item.getDamageToRepair(gear, repairKit, RepairContext.Type.QUICK);
        if (value > 0) {
            gear.setDamageValue(gear.getDamageValue() - Math.round(value));
        }
    }
    GearData.incrementRepairCount(gear, 1);
    GearData.recalculateStats(gear, ForgeHooks.getCraftingPlayer());
    return gear;
}
Also used : RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) StackList(net.silentchaos512.lib.collection.StackList) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

RepairKitItem (net.silentchaos512.gear.item.RepairKitItem)7 ItemStack (net.minecraft.world.item.ItemStack)6 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)3 StackList (net.silentchaos512.lib.collection.StackList)3 ArrayList (java.util.ArrayList)2 JsonObject (com.google.gson.JsonObject)1 Collection (java.util.Collection)1 List (java.util.List)1 NonNullList (net.minecraft.core.NonNullList)1 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 CraftingContainer (net.minecraft.world.inventory.CraftingContainer)1 Item (net.minecraft.world.item.Item)1 CustomRecipe (net.minecraft.world.item.crafting.CustomRecipe)1 RecipeSerializer (net.minecraft.world.item.crafting.RecipeSerializer)1 Level (net.minecraft.world.level.Level)1 ForgeHooks (net.minecraftforge.common.ForgeHooks)1 ForgeRegistryEntry (net.minecraftforge.registries.ForgeRegistryEntry)1 ICoreTool (net.silentchaos512.gear.api.item.ICoreTool)1 ItemStats (net.silentchaos512.gear.api.stats.ItemStats)1