Search in sources :

Example 1 with ICoreItem

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

the class RepairHandler method onAnvilUpdate.

@SubscribeEvent
public static void onAnvilUpdate(AnvilUpdateEvent event) {
    if (event.getLeft().getItem() instanceof ICoreItem) {
        MaterialInstance material = MaterialInstance.from(event.getRight());
        PartData part = PartData.from(event.getRight());
        if (material != null) {
            handleGearRepair(event, material);
        } else if (part != null && part.get() instanceof UpgradePart) {
            handleUpgradeApplication(event, part);
        }
    }
}
Also used : PartData(net.silentchaos512.gear.gear.part.PartData) UpgradePart(net.silentchaos512.gear.gear.part.UpgradePart) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with ICoreItem

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

the class GearData method getStatModifiers.

public static StatModifierMap getStatModifiers(ItemStack stack, ICoreItem item, PartDataList parts) {
    GearType gearType = item.getGearType();
    StatModifierMap stats = new StatModifierMap();
    for (ItemStat stat : ItemStats.allStatsOrderedExcluding(item.getExcludedStats(stack))) {
        StatGearKey itemKey = StatGearKey.of(stat, gearType);
        for (PartData part : parts) {
            for (StatInstance mod : part.getStatModifiers(itemKey, stack)) {
                StatInstance modCopy = StatInstance.of(mod.getValue(), mod.getOp(), itemKey);
                stats.put(modCopy.getKey(), modCopy);
            }
        }
    }
    return stats;
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 3 with ICoreItem

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

the class GearData method getStat.

public static float getStat(ItemStack stack, IItemStat stat, boolean calculateIfMissing) {
    CompoundTag tags = getData(stack, NBT_ROOT_PROPERTIES).getCompound(NBT_STATS);
    String key = stat.getStatId().toString();
    if (tags.contains(key)) {
        return tags.getFloat(key);
    }
    if (calculateIfMissing) {
        // Stat is missing, notify server to recalculate
        Level level = SilentGear.PROXY.getClientLevel();
        if (level != null && GearHelper.isValidGear(stack) && ((ICoreItem) stack.getItem()).getRelevantStats(stack).contains(stat)) {
            SilentGear.LOGGER.debug("Sending recalculate stats packet for item with missing {} stat: {}", stat.getStatId(), stack.getHoverName().getString());
            Network.channel.sendToServer(new RecalculateStatsPacket(level, stack, stat));
            // Prevent the packet from being spammed...
            putStatInNbtIfMissing(stack, stat);
        }
    }
    return stat.getDefaultValue();
}
Also used : RecalculateStatsPacket(net.silentchaos512.gear.network.RecalculateStatsPacket) Level(net.minecraft.world.level.Level) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 4 with ICoreItem

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

the class GearGenerator method randomizeParts.

public static ItemStack randomizeParts(ItemStack stack, int tier) {
    if (!(stack.getItem() instanceof ICoreItem)) {
        throw new RuntimeException("Called GearGenerator.randomizeParts on non-gear");
    }
    ICoreItem item = (ICoreItem) stack.getItem();
    GearType gearType = item.getGearType();
    PartDataList parts = PartDataList.of();
    for (PartType partType : item.getRequiredParts()) {
        getRandomPart(gearType, partType, tier).ifPresent(parts::add);
    }
    if (parts.isEmpty()) {
        return ItemStack.EMPTY;
    }
    ItemStack result = stack.copy();
    parts.forEach(p -> p.onAddToGear(result));
    GearData.writeConstructionParts(result, parts);
    // Apply some random upgrades?
    if (item instanceof ICoreTool && tier > 1 && SilentGear.RANDOM.nextFloat() < 0.2f * tier + 0.1f) {
        getRandomPart(gearType, PartType.TIP, tier).ifPresent(part -> GearData.addUpgradePart(result, part));
    }
    GearData.recalculateStats(result, null);
    return result;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) ICoreTool(net.silentchaos512.gear.api.item.ICoreTool) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 5 with ICoreItem

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

the class GearHelper method getDisplayName.

public static Component getDisplayName(ItemStack gear) {
    PartData part = GearData.getPrimaryPart(gear);
    if (part == null)
        return new TranslatableComponent(gear.getDescriptionId());
    Component partName = part.getMaterialName(gear);
    if (TimedEvents.isAprilFools()) {
        partName = partName.copy().append(new TextComponent(" & Knuckles"));
    }
    Component gearName = new TranslatableComponent(gear.getDescriptionId() + ".nameProper", partName);
    Component result = gearName;
    if (gear.getItem() instanceof ICoreTool) {
        ICoreItem item = (ICoreItem) gear.getItem();
        if (item.requiresPartOfType(PartType.ROD) && GearData.getPartOfType(gear, PartType.ROD) == null) {
            result = new TranslatableComponent(gear.getDescriptionId() + ".noRod", gearName);
        } else if (item.requiresPartOfType(PartType.CORD) && GearData.getPartOfType(gear, PartType.CORD) == null) {
            result = new TranslatableComponent(gear.getDescriptionId() + ".unstrung", gearName);
        }
    }
    // Prefixes
    for (Component t : getNamePrefixes(gear, GearData.getConstructionParts(gear))) {
        result = t.copy().append(new TextComponent(" ")).append(result);
    }
    return result;
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ICoreTool(net.silentchaos512.gear.api.item.ICoreTool) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) TextComponent(net.minecraft.network.chat.TextComponent) Component(net.minecraft.network.chat.Component)

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