Search in sources :

Example 1 with IArmor

use of net.silentchaos512.gems.api.IArmor in project SilentGems by SilentChaos512.

the class GemsCommonEvents method onPlayerLoggedIn.

@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
    Greetings.greetPlayer(event.player);
    SilentGems.instance.logHelper.info("Recalculating tool and armor stats for " + event.player.getDisplayNameString());
    // Recalculate tool stats.
    for (ItemStack stack : PlayerHelper.getNonEmptyStacks(event.player)) {
        if (stack != null) {
            if (stack.getItem() instanceof ITool)
                ToolHelper.recalculateStats(stack);
            if (stack.getItem() instanceof IArmor)
                ArmorHelper.recalculateStats(stack);
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IArmor

use of net.silentchaos512.gems.api.IArmor in project SilentGems by SilentChaos512.

the class RecipeApplyToolSoul method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    ItemStack tool = StackHelper.empty();
    ItemStack soul = StackHelper.empty();
    for (int i = 0; i < inv.getSizeInventory(); ++i) {
        ItemStack stack = inv.getStackInSlot(i);
        // Found a tool or armor piece?
        if (stack.getItem() instanceof ITool || stack.getItem() instanceof IArmor) {
            if (StackHelper.isValid(tool)) {
                return StackHelper.empty();
            }
            tool = stack;
        } else // Found a soul?
        if (stack.getItem() instanceof ItemToolSoul) {
            if (StackHelper.isValid(soul)) {
                return StackHelper.empty();
            }
            soul = stack;
        }
    }
    if (StackHelper.isEmpty(tool) || StackHelper.isEmpty(soul)) {
        return StackHelper.empty();
    }
    // Does tool already have a soul?
    if (SoulManager.getSoul(tool) != null) {
        return StackHelper.empty();
    }
    // Is the soul valid?
    ToolSoul toolSoul = ModItems.toolSoul.getSoul(soul);
    if (toolSoul == null) {
        return StackHelper.empty();
    }
    ItemStack result = StackHelper.safeCopy(tool);
    // Have to change UUID to prevent soul duping.
    // result.getTagCompound().removeTag(ToolHelper.NBT_UUID);
    SoulManager.setSoul(result, toolSoul, true);
    // Apply name, if applicable.
    if (soul.hasDisplayName()) {
        String name = soul.getDisplayName();
        toolSoul.setName(name);
        result.setStackDisplayName(name);
    }
    // Recalculate stats and return.
    ToolHelper.recalculateStats(result);
    return result;
}
Also used : ItemToolSoul(net.silentchaos512.gems.item.ItemToolSoul) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ItemToolSoul(net.silentchaos512.gems.item.ItemToolSoul) ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor)

Example 3 with IArmor

use of net.silentchaos512.gems.api.IArmor in project SilentGems by SilentChaos512.

the class RecipeDecorateArmor method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    int i;
    int toolRow = 0;
    int toolCol = 0;
    ItemStack stack;
    ItemStack tool = StackHelper.empty();
    int repairValue = 0;
    // Find armor position
    for (int row = 0; row < inv.getWidth(); ++row) {
        for (int col = 0; col < inv.getHeight(); ++col) {
            stack = inv.getStackInRowAndColumn(row, col);
            if (StackHelper.isValid(stack) && stack.getItem() instanceof IArmor) {
                tool = stack;
                toolRow = row;
                toolCol = col;
            }
        }
    }
    // Found armor piece?
    if (StackHelper.isEmpty(tool)) {
        return StackHelper.empty();
    }
    // Check adjacent materials
    ItemStack west = inv.getStackInRowAndColumn(toolRow - 1, toolCol);
    ItemStack north = inv.getStackInRowAndColumn(toolRow, toolCol - 1);
    ItemStack east = inv.getStackInRowAndColumn(toolRow + 1, toolCol);
    ItemStack south = inv.getStackInRowAndColumn(toolRow, toolCol + 1);
    int validPartCount = (StackHelper.isEmpty(west) ? 0 : 1) + (StackHelper.isEmpty(north) ? 0 : 1) + (StackHelper.isEmpty(east) ? 0 : 1) + (StackHelper.isEmpty(south) ? 0 : 1);
    if (!checkIsDecorationMaterial(west) || !checkIsDecorationMaterial(north) || !checkIsDecorationMaterial(east) || !checkIsDecorationMaterial(south)) {
        return StackHelper.empty();
    }
    // Check for other pieces (invalid for armor) and get all repair values.
    EnumMaterialTier toolTier = ArmorHelper.getArmorTier(tool);
    ToolPart part;
    int partsFound = 0;
    for (i = 0; i < inv.getSizeInventory(); ++i) {
        stack = inv.getStackInSlot(i);
        if (StackHelper.isValid(stack) && !(stack.getItem() instanceof IArmor)) {
            part = ToolPartRegistry.fromDecoStack(stack);
            // Invalid part or not a part?
            if (part == null || !(part instanceof ToolPartMain)) {
                return StackHelper.empty();
            }
            // Found a part.
            ++partsFound;
            // Add to total repair value.
            repairValue += part.getRepairAmount(tool, stack);
        }
    }
    // Make sure we got no other parts.
    if (partsFound != validPartCount) {
        return StackHelper.empty();
    }
    ItemStack result = ArmorHelper.decorateArmor(tool, west, north, east, south);
    // Repair.
    ItemHelper.attemptDamageItem(result, -repairValue, SilentGems.random);
    // Recalculate stats.
    ArmorHelper.recalculateStats(result);
    ArmorHelper.incrementStatRedecorated(result, 1);
    // Change the UUID so that rendering cache updates immediately for recipe output.
    result.getTagCompound().removeTag(ToolHelper.NBT_UUID + "Most");
    result.getTagCompound().removeTag(ToolHelper.NBT_UUID + "Least");
    ToolHelper.getUUID(result);
    return result;
}
Also used : ToolPartMain(net.silentchaos512.gems.api.tool.part.ToolPartMain) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) ItemStack(net.minecraft.item.ItemStack) IArmor(net.silentchaos512.gems.api.IArmor)

Example 4 with IArmor

use of net.silentchaos512.gems.api.IArmor in project SilentGems by SilentChaos512.

the class SoulManager method writeToolSoulsToNBT.

public static void writeToolSoulsToNBT(EntityPlayer player) {
    // Find all the players tools. Find the matching souls in the map.
    int count = 0;
    for (ItemStack tool : PlayerHelper.getNonEmptyStacks(player, true, true, true, s -> s.getItem() instanceof ITool || s.getItem() instanceof IArmor)) {
        // UUID uuid = getSoulUUID(tool);
        // ToolSoul soul = toolSoulMap.get(uuid);
        ToolSoul soul = getSoul(tool);
        if (soul != null) {
            setSoul(tool, soul, false);
            ++count;
        }
    }
// SilentGems.logHelper.debug("Saved " + count + " tool(s) for " + player.getName());
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor)

Example 5 with IArmor

use of net.silentchaos512.gems.api.IArmor in project SilentGems by SilentChaos512.

the class ToolPartFlint method getColor.

@Override
public int getColor(ItemStack toolOrArmor, IPartPosition position, int animationFrame) {
    Item item = toolOrArmor.getItem();
    boolean isTextureUncolored = position == ToolPartPosition.ROD_DECO || item instanceof IArmor || item instanceof ItemGemBow || item instanceof ItemGemShield;
    return isTextureUncolored || ToolHelper.isBroken(toolOrArmor) ? COLOR : 0xFFFFFF;
}
Also used : Item(net.minecraft.item.Item) ItemGemShield(net.silentchaos512.gems.item.tool.ItemGemShield) ItemGemBow(net.silentchaos512.gems.item.tool.ItemGemBow) IArmor(net.silentchaos512.gems.api.IArmor)

Aggregations

IArmor (net.silentchaos512.gems.api.IArmor)14 ITool (net.silentchaos512.gems.api.ITool)10 ItemStack (net.minecraft.item.ItemStack)8 ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)4 UUID (java.util.UUID)2 Nullable (javax.annotation.Nullable)2 Item (net.minecraft.item.Item)2 EnumMaterialTier (net.silentchaos512.gems.api.lib.EnumMaterialTier)2 ItemGemBow (net.silentchaos512.gems.item.tool.ItemGemBow)2 ItemGemShield (net.silentchaos512.gems.item.tool.ItemGemShield)2 EnumGem (net.silentchaos512.gems.lib.EnumGem)2 LinkedHashMap (java.util.LinkedHashMap)1 Random (java.util.Random)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)1 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)1 ToolPartMain (net.silentchaos512.gems.api.tool.part.ToolPartMain)1 ItemToolSoul (net.silentchaos512.gems.item.ItemToolSoul)1