Search in sources :

Example 21 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class GearData method hasPartOfType.

/**
 * Check if the gear item has at least one part of the given type.
 *
 * @param stack The gear item
 * @param type  The part type
 * @return True if and only if the construction parts include a part of the given type
 */
public static boolean hasPartOfType(ItemStack stack, PartType type) {
    CompoundTag tags = getData(stack, NBT_ROOT_CONSTRUCTION);
    ListTag tagList = tags.getList(NBT_CONSTRUCTION_PARTS, Tag.TAG_COMPOUND);
    for (int i = 0; i < tagList.size(); ++i) {
        CompoundTag nbt = tagList.getCompound(i);
        String key = nbt.getString("ID");
        IGearPart part = PartManager.get(key);
        if (part != null && part.getType() == type) {
            return true;
        }
    }
    return false;
}
Also used : IGearPart(net.silentchaos512.gear.api.part.IGearPart) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 22 with PartType

use of net.silentchaos512.gear.api.part.PartType 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 23 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class GearHelper method getExamplePartsFromRecipe.

public static Collection<IPartData> getExamplePartsFromRecipe(GearType gearType, Iterable<Ingredient> ingredients) {
    Map<PartType, IPartData> map = new LinkedHashMap<>();
    PartType.MAIN.makeCompoundPart(gearType, Const.Materials.EXAMPLE).ifPresent(p -> map.put(PartType.MAIN, p));
    for (Ingredient ingredient : ingredients) {
        if (ingredient instanceof IGearIngredient) {
            PartType type = ((IGearIngredient) ingredient).getPartType();
            type.makeCompoundPart(gearType, Const.Materials.EXAMPLE).ifPresent(p -> map.put(type, p));
        }
    }
    return map.values();
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) IGearIngredient(net.silentchaos512.gear.crafting.ingredient.IGearIngredient) Ingredient(net.minecraft.world.item.crafting.Ingredient) IGearIngredient(net.silentchaos512.gear.crafting.ingredient.IGearIngredient) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 24 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class GearHelper method createSampleItem.

private static ItemStack createSampleItem(ICoreItem item, int tier) {
    ItemStack result = GearGenerator.create(item, tier);
    if (result.isEmpty()) {
        Collection<IPartData> parts = new ArrayList<>();
        for (PartType partType : item.getRequiredParts()) {
            partType.makeCompoundPart(item.getGearType(), Const.Materials.EXAMPLE).ifPresent(parts::add);
        }
        result = item.construct(parts);
    }
    GearData.setExampleTag(result, true);
    return result;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 25 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class SyncMaterialCraftingItemsPacket method decode.

public static SyncMaterialCraftingItemsPacket decode(FriendlyByteBuf buffer) {
    SyncMaterialCraftingItemsPacket packet = new SyncMaterialCraftingItemsPacket();
    int count = buffer.readVarInt();
    for (int i = 0; i < count; ++i) {
        packet.craftingItems.put(buffer.readResourceLocation(), Ingredient.fromNetwork(buffer));
    }
    int subCount = buffer.readVarInt();
    for (int i = 0; i < subCount; ++i) {
        Map<PartType, Ingredient> map = new HashMap<>();
        ResourceLocation id = buffer.readResourceLocation();
        int mapCount = buffer.readByte();
        for (int j = 0; j < mapCount; ++j) {
            PartType type = PartType.get(buffer.readResourceLocation());
            Ingredient ingredient = Ingredient.fromNetwork(buffer);
            map.put(type, ingredient);
        }
        packet.partSubs.put(id, map);
    }
    return packet;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) Ingredient(net.minecraft.world.item.crafting.Ingredient) ResourceLocation(net.minecraft.resources.ResourceLocation)

Aggregations

PartType (net.silentchaos512.gear.api.part.PartType)37 ItemStack (net.minecraft.world.item.ItemStack)14 PartData (net.silentchaos512.gear.gear.part.PartData)14 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)13 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)10 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)10 TextComponent (net.minecraft.network.chat.TextComponent)9 ResourceLocation (net.minecraft.resources.ResourceLocation)9 GearType (net.silentchaos512.gear.api.item.GearType)9 PartDataList (net.silentchaos512.gear.api.part.PartDataList)9 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)9 Component (net.minecraft.network.chat.Component)8 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)8 IPartData (net.silentchaos512.gear.api.part.IPartData)8 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)8 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)7 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)7 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 MutableComponent (net.minecraft.network.chat.MutableComponent)5