Search in sources :

Example 16 with ArmorItem

use of net.minecraft.item.ArmorItem in project ChaosAwakens by ChaosAwakens.

the class CAItemModelGenerator method generate.

private void generate(final Collection<RegistryObject<Item>> items) {
    final ModelFile parentGenerated = getExistingFile(mcLoc("item/generated"));
    final ExistingModelFile parentHandheld = getExistingFile(mcLoc("item/handheld"));
    final ExistingModelFile parentTemplateSpawnEgg = getExistingFile(mcLoc("item/template_spawn_egg"));
    for (RegistryObject<Item> item : items) {
        String name = item.getId().getPath();
        if (name.startsWith("enchanted"))
            name = name.substring(name.indexOf("_") + 1);
        /*
             *  Skip elements that have no texture at assets/chaosawakens/textures/item
             *  or already have an existing model at assets/chaosawakens/models/item
             */
        ChaosAwakens.LOGGER.info(item.getId());
        if (item.getId().getPath().contains("_spawn_egg")) {
            getBuilder(item.getId().getPath()).parent(parentGenerated).texture("layer0", ItemModelProvider.ITEM_FOLDER + "/spawn_eggs/" + name.replaceAll("_spawn_egg", ""));
        } else {
            if (!existingFileHelper.exists(new ResourceLocation(ChaosAwakens.MODID, "item/" + name), TEXTURE) || existingFileHelper.exists(new ResourceLocation(ChaosAwakens.MODID, "item/" + name), MODEL))
                continue;
            getBuilder(item.getId().getPath()).parent(item.get().getMaxDamage(ItemStack.EMPTY) > 0 && !(item.get() instanceof ArmorItem) ? parentHandheld : parentGenerated).texture("layer0", ItemModelProvider.ITEM_FOLDER + "/" + name);
        }
    }
}
Also used : Item(net.minecraft.item.Item) ArmorItem(net.minecraft.item.ArmorItem) ArmorItem(net.minecraft.item.ArmorItem) ExistingModelFile(net.minecraftforge.client.model.generators.ModelFile.ExistingModelFile) ExistingModelFile(net.minecraftforge.client.model.generators.ModelFile.ExistingModelFile) ModelFile(net.minecraftforge.client.model.generators.ModelFile) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 17 with ArmorItem

use of net.minecraft.item.ArmorItem in project Fabric-Tutorial-1.18.1 by Tutorials-By-Kaupenjoe.

the class ModArmorItem method hasCorrectArmorOn.

private boolean hasCorrectArmorOn(ArmorMaterial material, PlayerEntity player) {
    ArmorItem boots = ((ArmorItem) player.getInventory().getArmorStack(0).getItem());
    ArmorItem leggings = ((ArmorItem) player.getInventory().getArmorStack(1).getItem());
    ArmorItem breastplate = ((ArmorItem) player.getInventory().getArmorStack(2).getItem());
    ArmorItem helmet = ((ArmorItem) player.getInventory().getArmorStack(3).getItem());
    return helmet.getMaterial() == material && breastplate.getMaterial() == material && leggings.getMaterial() == material && boots.getMaterial() == material;
}
Also used : ArmorItem(net.minecraft.item.ArmorItem)

Example 18 with ArmorItem

use of net.minecraft.item.ArmorItem in project ChocolateQuestRepoured by TeamChocoQuest.

the class RecipesArmorDyes method getCraftingResult.

@Override
public ItemStack getCraftingResult(CraftingInventory inv) {
    ItemStack itemstack = ItemStack.EMPTY;
    int[] aint = new int[3];
    int i = 0;
    int j = 0;
    ArmorItem itemarmor = null;
    for (int k = 0; k < inv.getSizeInventory(); ++k) {
        ItemStack itemstack1 = inv.getStackInSlot(k);
        if (!itemstack1.isEmpty()) {
            if (itemstack == ItemStack.EMPTY && itemstack1.getItem() instanceof ItemArmorDyable) {
                itemarmor = (ArmorItem) itemstack1.getItem();
                itemstack = itemstack1.copy();
                itemstack.setCount(1);
                if (itemarmor.hasColor(itemstack1)) {
                    int l = itemarmor.getColor(itemstack);
                    float f = (l >> 16 & 255) / 255.0F;
                    float f1 = (l >> 8 & 255) / 255.0F;
                    float f2 = (l & 255) / 255.0F;
                    i = (int) (i + Math.max(f, Math.max(f1, f2)) * 255.0F);
                    aint[0] = (int) (aint[0] + f * 255.0F);
                    aint[1] = (int) (aint[1] + f1 * 255.0F);
                    aint[2] = (int) (aint[2] + f2 * 255.0F);
                    ++j;
                }
            } else if (DyeUtils.isDye(itemstack1)) {
                float[] afloat = DyeUtils.colorFromStack(itemstack1).get().getColorComponentValues();
                int l1 = (int) (afloat[0] * 255.0F);
                int i2 = (int) (afloat[1] * 255.0F);
                int j2 = (int) (afloat[2] * 255.0F);
                i += Math.max(l1, Math.max(i2, j2));
                aint[0] += l1;
                aint[1] += i2;
                aint[2] += j2;
                ++j;
            } else {
                return ItemStack.EMPTY;
            }
        }
    }
    if (itemarmor == null) {
        return ItemStack.EMPTY;
    } else {
        int i1 = aint[0] / j;
        int j1 = aint[1] / j;
        int k1 = aint[2] / j;
        float f3 = (float) i / (float) j;
        float f4 = Math.max(i1, Math.max(j1, k1));
        i1 = (int) (i1 * f3 / f4);
        j1 = (int) (j1 * f3 / f4);
        k1 = (int) (k1 * f3 / f4);
        int k2 = (i1 << 8) + j1;
        k2 = (k2 << 8) + k1;
        itemarmor.setColor(itemstack, k2);
        return itemstack;
    }
}
Also used : ArmorItem(net.minecraft.item.ArmorItem) ItemStack(net.minecraft.item.ItemStack) ItemArmorDyable(team.cqr.cqrepoured.item.armor.ItemArmorDyable)

Example 19 with ArmorItem

use of net.minecraft.item.ArmorItem in project WarDance by Jackiecrazy.

the class CombatUtils method updateItems.

public static void updateItems(List<? extends String> interpretC, List<? extends String> interpretA, List<? extends String> interpretU) {
    DEFAULTMELEE = new MeleeInfo(CombatConfig.defaultMultiplierPostureAttack, CombatConfig.defaultMultiplierPostureDefend, false, CombatConfig.shieldCooldown, CombatConfig.barrierSize, StealthConfig.distract, StealthConfig.unaware);
    combatList = new HashMap<>();
    armorStats = new HashMap<>();
    shieldStat = new HashMap<>();
    unarmed = new ArrayList<>();
    for (String s : interpretC) {
        String[] val = s.split(",");
        String name = val[0];
        double attack = CombatConfig.defaultMultiplierPostureAttack;
        double defend = CombatConfig.defaultMultiplierPostureDefend;
        boolean shield = false;
        if (val.length > 1)
            try {
                attack = Float.parseFloat(val[1].trim());
            } catch (NumberFormatException ignored) {
                WarDance.LOGGER.warn("attack data for config entry " + s + " is not properly formatted, replacing with default values.");
            }
        if (val.length > 2)
            try {
                defend = Float.parseFloat(val[2].trim());
            } catch (NumberFormatException ignored) {
                WarDance.LOGGER.warn("defense data for config entry " + s + " is not properly formatted, replacing with default values.");
            }
        if (val.length > 3)
            shield = Boolean.parseBoolean(val[3].trim());
        int pTime = CombatConfig.shieldCooldown;
        float pCount = CombatConfig.barrierSize;
        double distract = StealthConfig.distract, unaware = StealthConfig.unaware;
        if (shield) {
            try {
                pTime = Integer.parseInt(val[4].trim());
                pCount = Float.parseFloat(val[5].trim());
            } catch (Exception e) {
                WarDance.LOGGER.warn("additional data for shield config entry " + s + " is not properly formatted, replacing with default values.");
            }
        } else {
            try {
                distract = Double.parseDouble(val[4].trim());
                unaware = Double.parseDouble(val[5].trim());
            } catch (Exception e) {
                WarDance.LOGGER.warn("additional data for weapon config entry " + s + " is not properly formatted, replacing with default values.");
            }
        }
        ResourceLocation key = null;
        try {
            key = new ResourceLocation(name);
        } catch (Exception e) {
            WarDance.LOGGER.warn(name + " is not a proper item name, it will not be registered.");
        }
        // System.out.print("\""+key+"\",\n");
        if (ForgeRegistries.ITEMS.containsKey(key)) {
            final Item item = ForgeRegistries.ITEMS.getValue(key);
            combatList.put(item, new MeleeInfo(attack, defend, shield, pTime, pCount, distract, unaware));
            if (shield) {
                final AttributeModifier downtimeM = new AttributeModifier(main, "extra downtime", pTime, AttributeModifier.Operation.ADDITION);
                final AttributeModifier barrierM = new AttributeModifier(main, "barrier bonus", pCount, AttributeModifier.Operation.ADDITION);
                final AttributeModifier downtimeO = new AttributeModifier(off, "extra downtime", pTime, AttributeModifier.Operation.ADDITION);
                final AttributeModifier barrierO = new AttributeModifier(off, "barrier bonus", pCount, AttributeModifier.Operation.ADDITION);
                shieldStat.put(item, new AttributeModifier[] { downtimeM, barrierM, downtimeO, barrierO });
            }
        }
    // System.out.print("\"" + name+ "\", ");
    }
    for (String s : interpretA) {
        String[] val = s.split(",");
        String name = val[0];
        double absorption = 0, deflection = 0, shatter = 0, stealth = 0;
        try {
            absorption = Double.parseDouble(val[1]);
            deflection = Double.parseDouble(val[2]);
            shatter = Double.parseDouble(val[3]);
            stealth = Double.parseDouble(val[4]);
        } catch (Exception ignored) {
            WarDance.LOGGER.warn("armor data for config entry " + s + " is not properly formatted, filling in zeros.");
        }
        ResourceLocation key = null;
        try {
            key = new ResourceLocation(name);
        } catch (Exception e) {
            WarDance.LOGGER.warn(name + " is not a proper item name, it will not be registered.");
        }
        if (ForgeRegistries.ITEMS.containsKey(key) && (ForgeRegistries.ITEMS.getValue(key)) instanceof ArmorItem) {
            final Item armor = ForgeRegistries.ITEMS.getValue(key);
            UUID touse = WarAttributes.MODIFIERS[((ArmorItem) armor).getSlot().getIndex()];
            armorStats.put(armor, new AttributeModifier[] { new AttributeModifier(touse, "war dance modifier", absorption, AttributeModifier.Operation.ADDITION), new AttributeModifier(touse, "war dance modifier", deflection, AttributeModifier.Operation.ADDITION), new AttributeModifier(touse, "war dance modifier", shatter, AttributeModifier.Operation.ADDITION), new AttributeModifier(touse, "war dance modifier", stealth, AttributeModifier.Operation.ADDITION) });
        }
    // System.out.print("\"" + name+ "\", ");
    }
    for (String name : interpretU) {
        ResourceLocation key = null;
        try {
            key = new ResourceLocation(name);
        } catch (Exception e) {
            WarDance.LOGGER.warn(name + " is not a proper item name, it will not be registered.");
        }
        if (ForgeRegistries.ITEMS.containsKey(key)) {
            unarmed.add(ForgeRegistries.ITEMS.getValue(key));
        }
    }
}
Also used : AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) Item(net.minecraft.item.Item) ArmorItem(net.minecraft.item.ArmorItem) ArmorItem(net.minecraft.item.ArmorItem)

Example 20 with ArmorItem

use of net.minecraft.item.ArmorItem in project Mekanism by mekanism.

the class ToolsItemModelProvider method registerModels.

@Override
protected void registerModels() {
    // Shields
    addShieldModel(ToolsItems.BRONZE_SHIELD, Mekanism.rl("block/block_bronze"));
    addShieldModel(ToolsItems.LAPIS_LAZULI_SHIELD, mcLoc("block/lapis_block"));
    addShieldModel(ToolsItems.OSMIUM_SHIELD, Mekanism.rl("block/block_osmium"));
    addShieldModel(ToolsItems.REFINED_GLOWSTONE_SHIELD, Mekanism.rl("block/block_refined_glowstone"));
    addShieldModel(ToolsItems.REFINED_OBSIDIAN_SHIELD, Mekanism.rl("block/block_refined_obsidian"));
    addShieldModel(ToolsItems.STEEL_SHIELD, Mekanism.rl("block/block_steel"));
    // Armor items are generated textures, all other tools module items are handheld
    for (IItemProvider itemProvider : ToolsItems.ITEMS.getAllItems()) {
        Item item = itemProvider.getItem();
        if (item instanceof ItemMekanismShield) {
            // Skip shields, we manually handle them above
            continue;
        }
        ResourceLocation texture;
        if (isVanilla(itemProvider)) {
            texture = itemTexture(itemProvider);
        } else {
            String name = itemProvider.getName();
            int index = name.lastIndexOf('_');
            texture = modLoc("item/" + name.substring(0, index) + '/' + name.substring(index + 1));
        }
        if (item instanceof ArmorItem) {
            generated(itemProvider, texture);
        } else {
            handheld(itemProvider, texture);
        }
    }
}
Also used : Item(net.minecraft.item.Item) ArmorItem(net.minecraft.item.ArmorItem) ArmorItem(net.minecraft.item.ArmorItem) ResourceLocation(net.minecraft.util.ResourceLocation) ItemMekanismShield(mekanism.tools.common.item.ItemMekanismShield) IItemProvider(mekanism.api.providers.IItemProvider)

Aggregations

ArmorItem (net.minecraft.item.ArmorItem)28 ItemStack (net.minecraft.item.ItemStack)16 ResourceLocation (net.minecraft.util.ResourceLocation)7 Item (net.minecraft.item.Item)6 Inject (org.spongepowered.asm.mixin.injection.Inject)6 ArrayList (java.util.ArrayList)4 Color (java.awt.Color)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 PlayerInventory (net.minecraft.entity.player.PlayerInventory)2 ElytraItem (net.minecraft.item.ElytraItem)2 ToolItem (net.minecraft.item.ToolItem)2 TranslatableText (net.minecraft.text.TranslatableText)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 Ability (online.kingdomkeys.kingdomkeys.ability.Ability)2 IKeychain (online.kingdomkeys.kingdomkeys.api.item.IKeychain)2 IPlayerCapabilities (online.kingdomkeys.kingdomkeys.capability.IPlayerCapabilities)2 KKAccessoryItem (online.kingdomkeys.kingdomkeys.item.KKAccessoryItem)2 KKPotionItem (online.kingdomkeys.kingdomkeys.item.KKPotionItem)2 KeybladeItem (online.kingdomkeys.kingdomkeys.item.KeybladeItem)2