use of net.silentchaos512.gear.api.part.PartDataList in project Silent-Gear by SilentChaos512.
the class GearData method addUpgradePart.
/**
* Add an upgrade part to the gear item. Depending on the upgrade, this may replace an existing
* part.
* <p>
* TODO: Should we return something to indicate if the upgrade cannot be applied or replaces an
* existing upgrade?
*
* @param gear The gear item
* @param part The upgrade part
*/
public static void addUpgradePart(ItemStack gear, PartData part) {
if (!GearHelper.isGear(gear))
return;
PartDataList parts = getConstructionParts(gear);
// Make sure the upgrade is valid for the gear type
if (!part.get().canAddToGear(gear, part))
return;
// Only one allowed of this type? Remove existing if needed.
if (part.get().replacesExistingInPosition(part)) {
parts.removeIf(p -> p.getType() == part.getType());
}
// Allow the part to make additional changes if needed
part.onAddToGear(gear);
// Other upgrades allow no exact duplicates, but any number of total upgrades
for (PartData partInList : parts) {
if (partInList.get() == part.get()) {
return;
}
}
parts.add(part);
writeConstructionParts(gear, parts);
}
use of net.silentchaos512.gear.api.part.PartDataList in project Silent-Gear by SilentChaos512.
the class GearData method addPart.
public static void addPart(ItemStack gear, PartData part) {
PartDataList parts = getConstructionParts(gear);
parts.add(part);
writeConstructionParts(gear, parts);
part.onAddToGear(gear);
}
use of net.silentchaos512.gear.api.part.PartDataList 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;
}
use of net.silentchaos512.gear.api.part.PartDataList 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;
}
use of net.silentchaos512.gear.api.part.PartDataList in project Silent-Gear by SilentChaos512.
the class TraitHelper method getTraits.
/**
* Gets a Map of Traits and levels from the parts, used to calculate trait levels and should not
* be used in most cases. Consider using {@link #getTraitLevel(ItemStack, ResourceLocation)} or
* {@link #hasTrait(ItemStack, ResourceLocation)} when appropriate.
*
* @param gear The item
* @param gearType The gear type
* @param parts The list of all parts used in constructing the gear.
* @return A Map of Traits to their levels
*/
public static Map<ITrait, Integer> getTraits(ItemStack gear, GearType gearType, PartDataList parts) {
if (parts.isEmpty() || (!gear.isEmpty() && GearHelper.isBroken(gear)))
return ImmutableMap.of();
Map<ITrait, Integer> result = new LinkedHashMap<>();
for (PartData part : parts) {
PartGearKey key = PartGearKey.of(gearType, part);
for (TraitInstance inst : part.getTraits(key, gear)) {
if (inst.conditionsMatch(key, gear, parts)) {
ITrait trait = inst.getTrait();
// Get the highest value in any part
result.merge(trait, inst.getLevel(), Integer::max);
}
}
}
ITrait[] keys = result.keySet().toArray(new ITrait[0]);
cancelTraits(result, keys);
MinecraftForge.EVENT_BUS.post(new GetTraitsEvent(gear, parts, result));
return result;
}
Aggregations