Search in sources :

Example 11 with ICoreItem

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

the class RandomGearCommand method run.

private static int run(CommandContext<CommandSourceStack> context, Collection<ServerPlayer> players, ResourceLocation itemId, int tier) throws CommandSyntaxException {
    Item item = ForgeRegistries.ITEMS.getValue(itemId);
    if (!(item instanceof ICoreItem)) {
        context.getSource().sendFailure(new TranslatableComponent("command.silentgear.randomGear.invalidItem"));
        return 0;
    }
    for (ServerPlayer player : players) {
        ItemStack stack = GearGenerator.create((ICoreItem) item, tier);
        if (!stack.isEmpty()) {
            context.getSource().sendSuccess(new TranslatableComponent("commands.give.success.single", 1, stack.getDisplayName(), player.getDisplayName()), true);
            PlayerUtils.giveItem(player, stack.copy());
        }
    }
    return 1;
}
Also used : Item(net.minecraft.world.item.Item) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ServerPlayer(net.minecraft.server.level.ServerPlayer) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 12 with ICoreItem

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

the class SetDamageCommand method run.

private static int run(CommandContext<CommandSourceStack> context, int amount) throws CommandSyntaxException {
    ServerPlayer playerMP = context.getSource().getPlayerOrException();
    ItemStack stack = playerMP.getMainHandItem();
    if (stack.isDamageableItem()) {
        // amount of -1 indicates "max" value
        int correctedAmount = amount < 0 ? getMaxDamage(stack) : amount;
        int clamped = Mth.clamp(correctedAmount, 0, getMaxDamage(stack));
        stack.setDamageValue(clamped);
        if (stack.getItem() instanceof ICoreItem) {
            GearData.recalculateStats(stack, playerMP);
        }
        return 1;
    } else {
        Component msg = TextUtil.translate("command", "set_damage.notDamageable", stack.getHoverName());
        context.getSource().sendFailure(msg);
        return 0;
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack) Component(net.minecraft.network.chat.Component)

Example 13 with ICoreItem

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

the class ModGiftLootTables method accept.

@Override
public void accept(BiConsumer<ResourceLocation, LootTable.Builder> p_accept_1_) {
    p_accept_1_.accept(ModItems.BLUEPRINT_PACKAGE.get().getDefaultLootTable(), LootTable.lootTable().withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.ROD_BLUEPRINT))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.PICKAXE_BLUEPRINT))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.SHOVEL_BLUEPRINT))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.AXE_BLUEPRINT))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.KNIFE_BLUEPRINT))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.SWORD_BLUEPRINT).setWeight(11)).add(LootItem.lootTableItem(ModItems.KATANA_BLUEPRINT).setWeight(5)).add(LootItem.lootTableItem(ModItems.MACHETE_BLUEPRINT).setWeight(7)).add(LootItem.lootTableItem(ModItems.SPEAR_BLUEPRINT).setWeight(8))).withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.SHIELD_BLUEPRINT))));
    for (Item item : Registration.getItems(item -> item instanceof ICoreItem)) {
        p_accept_1_.accept(SilentGear.getId("random_gear/" + NameUtils.from(item).getPath()), LootTable.lootTable().withPool(LootPool.lootPool().add(LootItem.lootTableItem(item).setWeight(3).apply(SelectGearTierLootFunction.builder(1))).add(LootItem.lootTableItem(item).setWeight(5).apply(SelectGearTierLootFunction.builder(2))).add(LootItem.lootTableItem(item).setWeight(2).apply(SelectGearTierLootFunction.builder(3)))));
    }
    // FIXME
    p_accept_1_.accept(SilentGear.getId("test/ldf_mallet"), LootTable.lootTable().withPool(LootPool.lootPool().add(LootItem.lootTableItem(ModItems.HAMMER).apply(SetPartsFunction.builder(ImmutableList.of(new LazyPartData(SilentGear.getId("main/diamond")), new LazyPartData(SilentGear.getId("main/diamond")), new LazyPartData(SilentGear.getId("main/emerald")), new LazyPartData(SilentGear.getId("rod/blaze")), new LazyPartData(SilentGear.getId("tip/redstone"))))).apply(() -> setName(new TextComponent("Loliberty Defense Force Mallet"))).apply(() -> setLore(ImmutableList.of(new TextComponent("Standard Issue"), new TextComponent("Protectors of Free Speech")))))));
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) Item(net.minecraft.world.item.Item) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) LootItem(net.minecraft.world.level.storage.loot.entries.LootItem) LazyPartData(net.silentchaos512.gear.gear.part.LazyPartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem)

Example 14 with ICoreItem

use of net.silentchaos512.gear.api.item.ICoreItem 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 15 with ICoreItem

use of net.silentchaos512.gear.api.item.ICoreItem 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)

Aggregations

ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)25 ItemStack (net.minecraft.world.item.ItemStack)16 PartData (net.silentchaos512.gear.gear.part.PartData)12 PartType (net.silentchaos512.gear.api.part.PartType)10 PartDataList (net.silentchaos512.gear.api.part.PartDataList)7 Component (net.minecraft.network.chat.Component)5 TextComponent (net.minecraft.network.chat.TextComponent)5 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)5 ArrayList (java.util.ArrayList)4 GearType (net.silentchaos512.gear.api.item.GearType)4 ResourceLocation (net.minecraft.resources.ResourceLocation)3 Item (net.minecraft.world.item.Item)3 IPartData (net.silentchaos512.gear.api.part.IPartData)3 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)3 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)3 StackList (net.silentchaos512.lib.collection.StackList)3 CompoundTag (net.minecraft.nbt.CompoundTag)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 Level (net.minecraft.world.level.Level)2 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)2