use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.
the class PartGearKey method fromNetwork.
public static PartGearKey fromNetwork(FriendlyByteBuf buf) {
GearType gearType = GearType.get(buf.readUtf());
PartType partType = Objects.requireNonNull(PartType.get(buf.readResourceLocation()));
return of(gearType, partType);
}
use of net.silentchaos512.gear.api.item.GearType 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.item.GearType 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.item.GearType 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();
}
use of net.silentchaos512.gear.api.item.GearType 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