use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class GearData method getTier.
/**
* Gets the tier of the gear item. The tier is the same as the main part with the highest tier.
*
* @param gear The gear item
* @return The gear tier
*/
public static int getTier(ItemStack gear) {
if (!GearHelper.isGear(gear))
return -1;
CompoundTag data = getData(gear, NBT_ROOT_CONSTRUCTION);
if (!data.contains(NBT_TIER)) {
List<PartData> parts = getConstructionParts(gear).getMains();
int max = 0;
for (PartData part : parts) {
if (part.getTier() > max) {
max = part.getTier();
}
}
data.putInt(NBT_TIER, max);
}
return data.getInt(NBT_TIER);
}
use of net.silentchaos512.gear.gear.part.PartData 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.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class GearHelper method isEquivalent.
/**
* Check if both gear items are made of the same parts.
*
* @param gear1 First item
* @param gear2 Second item
* @return True only if all parts are identical
*/
public static boolean isEquivalent(ItemStack gear1, ItemStack gear2) {
if (!GearHelper.isGear(gear1) || !GearHelper.isGear(gear2) || gear1.getItem() != gear2.getItem()) {
return false;
}
List<PartData> parts1 = GearData.getConstructionParts(gear1);
List<PartData> parts2 = GearData.getConstructionParts(gear2);
if (parts1.size() != parts2.size()) {
return false;
}
if (parts1.isEmpty()) {
return true;
}
for (PartData part1 : parts1) {
for (PartData part2 : parts2) {
if (part1.equals(part2)) {
parts2.remove(part2);
break;
}
}
}
return parts2.isEmpty();
}
use of net.silentchaos512.gear.gear.part.PartData 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;
}
use of net.silentchaos512.gear.gear.part.PartData 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