use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class GearData method removeExcessParts.
public static void removeExcessParts(ItemStack gear, PartType partType) {
// Mostly just to correct https://github.com/SilentChaos512/Silent-Gear/issues/242
PartDataList parts = getConstructionParts(gear);
List<PartData> partsOfType = new ArrayList<>(parts.getPartsOfType(partType));
int maxCount = partType.getMaxPerItem(GearHelper.getType(gear));
int removed = 0;
while (partsOfType.size() > maxCount) {
PartData toRemove = partsOfType.get(0);
partsOfType.remove(toRemove);
parts.remove(toRemove);
toRemove.onRemoveFromGear(gear);
++removed;
SilentGear.LOGGER.debug("Removed excess part '{}' from '{}'", toRemove.getDisplayName(gear).getString(), gear.getHoverName().getString());
}
if (removed > 0) {
writeConstructionParts(gear, parts);
}
}
use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class GearData method getPartOfType.
/**
* Gets the first part in the construction parts list that is of the given type.
*
* @param stack The gear item
* @param type The part type
* @return The first part of the given type, or null if there is none
*/
@Nullable
public static PartData getPartOfType(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);
PartData part = PartData.read(nbt);
if (part != null && part.getType() == type) {
return part;
}
}
return null;
}
use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class GearElytraItem method supportsPart.
@Override
public boolean supportsPart(ItemStack gear, PartData part) {
PartType type = part.getType();
boolean canAdd = part.get().canAddToGear(gear, part);
boolean supported = (requiresPartOfType(part.getType()) && canAdd) || canAdd;
return (type == PartType.MAIN && supported) || type == PartType.LINING || supported;
}
use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class SetPartsFunction method run.
@Override
protected ItemStack run(ItemStack stack, LootContext context) {
if (!(stack.getItem() instanceof ICoreItem))
return stack;
ItemStack result = stack.copy();
List<PartData> parts = LazyPartData.createPartList(this.parts);
parts.forEach(p -> p.onAddToGear(result));
GearData.writeConstructionParts(result, parts);
GearData.recalculateStats(result, null);
return result;
}
use of net.silentchaos512.gear.gear.part.PartData in project Silent-Gear by SilentChaos512.
the class GearClientHelper method tooltipListParts.
public static void tooltipListParts(ItemStack gear, List<Component> tooltip, Collection<PartData> parts, GearTooltipFlag flag) {
TextListBuilder builder = new TextListBuilder();
for (PartData part : parts) {
if (part.get().isVisible()) {
int partNameColor = Color.blend(part.getColor(gear), Color.VALUE_WHITE, 0.25f) & 0xFFFFFF;
MutableComponent partNameText = TextUtil.withColor(part.getDisplayName(gear).copy(), partNameColor);
builder.add(flag.isAdvanced() ? partNameText.append(TextUtil.misc("spaceBrackets", part.getType().getName()).withStyle(ChatFormatting.DARK_GRAY)) : partNameText);
// List materials for compound parts
if (part.get() instanceof CompoundPart) {
builder.indent();
for (IMaterialInstance material : CompoundPartItem.getMaterials(part.getItem())) {
int nameColor = material.getNameColor(part.getType(), GearType.ALL);
builder.add(TextUtil.withColor(material.getDisplayNameWithModifiers(part.getType(), ItemStack.EMPTY), nameColor));
}
builder.unindent();
}
}
}
tooltip.addAll(builder.build());
}
Aggregations