use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class ColorUtils method getBlendedColor.
public static int getBlendedColor(ICoreItem item, IPartData part, Collection<? extends IMaterialInstance> materials, int layer) {
int[] componentSums = new int[3];
int maxColorSum = 0;
int colorCount = 0;
int i = 0;
for (IMaterialInstance mat : materials) {
IMaterialDisplay model = mat.getDisplayProperties();
int color = model.getLayerColor(item.getGearType(), part, mat, layer);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
int colorWeight = (materials.size() - i) * (materials.size() - i);
for (int j = 0; j < colorWeight; ++j) {
maxColorSum += Math.max(r, Math.max(g, b));
componentSums[0] += r;
componentSums[1] += g;
componentSums[2] += b;
++colorCount;
}
++i;
}
return blendColors(componentSums, maxColorSum, colorCount);
}
use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class GearClientHelper method addInformation.
public static void addInformation(ItemStack stack, Level world, List<Component> tooltip, GearTooltipFlag flag) {
if (!(stack.getItem() instanceof ICoreItem))
return;
ICoreItem item = (ICoreItem) stack.getItem();
if (GearHelper.isBroken(stack)) {
tooltip.add(Math.min(1, tooltip.size()), TextUtil.withColor(misc("broken"), Color.FIREBRICK));
}
if (GearData.isExampleGear(stack)) {
tooltip.add(Math.min(1, tooltip.size()), TextUtil.withColor(misc("exampleOutput1"), Color.YELLOW));
tooltip.add(Math.min(2, tooltip.size()), TextUtil.withColor(misc("exampleOutput2"), Color.YELLOW));
}
PartDataList constructionParts = GearData.getConstructionParts(stack);
if (constructionParts.getMains().isEmpty()) {
tooltip.add(TextUtil.withColor(misc("invalidParts"), Color.FIREBRICK));
tooltip.add(TextUtil.withColor(misc("lockedStats"), Color.FIREBRICK));
} else if (GearData.hasLockedStats(stack)) {
tooltip.add(TextUtil.withColor(misc("lockedStats"), Color.YELLOW));
}
if (!Config.Client.vanillaStyleTooltips.get()) {
// Let parts add information if they need to
Collections.reverse(constructionParts);
for (PartData data : constructionParts) {
data.get().addInformation(data, stack, tooltip, flag);
}
}
// Traits
addTraitsInfo(stack, tooltip, flag);
if (!Config.Client.vanillaStyleTooltips.get()) {
// Stats
addStatsInfo(stack, tooltip, flag, item);
}
// Tool construction
if (KeyTracker.isDisplayConstructionDown() && flag.showConstruction) {
tooltip.add(TextUtil.withColor(misc("tooltip.construction"), Color.GOLD));
Collections.reverse(constructionParts);
tooltipListParts(stack, tooltip, constructionParts, flag);
} else if (flag.showConstruction) {
tooltip.add(TextUtil.withColor(TextUtil.misc("tooltip.construction"), Color.GOLD).append(new TextComponent(" ").append(TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_CONSTRUCTION), ChatFormatting.GRAY))));
}
}
use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class WielderEffectTrait method onUpdate.
@Override
public void onUpdate(TraitActionContext context, boolean isEquipped) {
if (!isEquipped || context.getPlayer() == null || context.getPlayer().tickCount % 10 != 0)
return;
GearType gearType = ((ICoreItem) context.getGear().getItem()).getGearType();
for (Map.Entry<String, List<PotionData>> entry : potions.entrySet()) {
String type = entry.getKey();
List<PotionData> list = entry.getValue();
applyEffects(context, gearType, type, list);
}
}
use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class StatsCommand method runInfo.
private static int runInfo(CommandContext<CommandSourceStack> context, ServerPlayer player) {
ItemStack stack = player.getMainHandItem();
if (!GearHelper.isGear(stack)) {
context.getSource().sendFailure(TextUtil.translate("command", "invalidItemType", stack.getHoverName()));
return 0;
}
context.getSource().sendSuccess(TextUtil.translate("command", "stats.info.header", player.getName(), stack.getHoverName()).withStyle(ChatFormatting.BOLD), true);
ICoreItem item = (ICoreItem) stack.getItem();
PartDataList parts = GearData.getConstructionParts(stack);
StatModifierMap stats = GearData.getStatModifiers(stack, item, parts);
for (ItemStat stat : ItemStats.allStatsOrderedExcluding((item).getExcludedStats(stack))) {
StatGearKey key = StatGearKey.of(stat, item.getGearType());
Collection<StatInstance> mods = stats.get(key);
if (!mods.isEmpty()) {
Component name = TextUtil.withColor(stat.getDisplayName(), stat.getNameColor());
Component modsText = StatModifierMap.formatText(mods, stat, 5, true);
float statValue = stat.compute(0f, true, item.getGearType(), mods);
Component valueText = TextUtil.withColor(StatInstance.of(statValue, StatInstance.Operation.AVG, key).getFormattedText(stat, 5, false), ChatFormatting.YELLOW);
context.getSource().sendSuccess(TextUtil.translate("command", "stats.info.format", name, modsText, valueText), true);
for (PartData part : parts) {
Collection<StatInstance> partMods = part.getStatModifiers(key, stack);
if (!partMods.isEmpty()) {
Component partName = part.getDisplayName(stack);
Component partModsText = StatModifierMap.formatText(partMods, stat, 5, true);
context.getSource().sendSuccess(TextUtil.translate("command", "stats.info.formatPart", partName, partModsText), true);
}
}
}
}
return 1;
}
use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.
the class CuriosCompat method getHighestTraitLevel.
public static int getHighestTraitLevel(LivingEntity entity, DataResource<ITrait> trait) {
LazyOptional<IItemHandlerModifiable> lazy = CuriosApi.getCuriosHelper().getEquippedCurios(entity);
int max = 0;
if (lazy.isPresent()) {
IItemHandlerModifiable handler = lazy.orElseThrow(IllegalStateException::new);
for (int i = 0; i < handler.getSlots(); ++i) {
ItemStack stack = handler.getStackInSlot(i);
if (stack.getItem() instanceof ICoreItem) {
max = Math.max(max, TraitHelper.getTraitLevel(stack, trait));
}
}
}
return max;
}
Aggregations