2025-11-24 22:52:51 +03:00

118 lines
4.4 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.google.common.collect.Lists
* com.mojang.serialization.Codec
*/
package net.minecraft.world.item.component;
import com.google.common.collect.Lists;
import com.mojang.serialization.Codec;
import java.util.List;
import java.util.function.Consumer;
import net.minecraft.ChatFormatting;
import net.minecraft.core.component.DataComponentGetter;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.component.TooltipDisplay;
import net.minecraft.world.item.component.TooltipProvider;
public final class ChargedProjectiles
implements TooltipProvider {
public static final ChargedProjectiles EMPTY = new ChargedProjectiles(List.of());
public static final Codec<ChargedProjectiles> CODEC = ItemStack.CODEC.listOf().xmap(ChargedProjectiles::new, projectiles -> projectiles.items);
public static final StreamCodec<RegistryFriendlyByteBuf, ChargedProjectiles> STREAM_CODEC = ItemStack.STREAM_CODEC.apply(ByteBufCodecs.list()).map(ChargedProjectiles::new, projectiles -> projectiles.items);
private final List<ItemStack> items;
private ChargedProjectiles(List<ItemStack> items) {
this.items = items;
}
public static ChargedProjectiles of(ItemStack itemStack) {
return new ChargedProjectiles(List.of(itemStack.copy()));
}
public static ChargedProjectiles of(List<ItemStack> items) {
return new ChargedProjectiles(List.copyOf(Lists.transform(items, ItemStack::copy)));
}
public boolean contains(Item item) {
for (ItemStack projectile : this.items) {
if (!projectile.is(item)) continue;
return true;
}
return false;
}
public List<ItemStack> getItems() {
return Lists.transform(this.items, ItemStack::copy);
}
public boolean isEmpty() {
return this.items.isEmpty();
}
/*
* Enabled force condition propagation
* Lifted jumps to return sites
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ChargedProjectiles)) return false;
ChargedProjectiles projectiles = (ChargedProjectiles)obj;
if (!ItemStack.listMatches(this.items, projectiles.items)) return false;
return true;
}
public int hashCode() {
return ItemStack.hashStackList(this.items);
}
public String toString() {
return "ChargedProjectiles[items=" + String.valueOf(this.items) + "]";
}
@Override
public void addToTooltip(Item.TooltipContext context, Consumer<Component> consumer, TooltipFlag flag, DataComponentGetter components) {
ItemStack current = null;
int count = 0;
for (ItemStack projectile : this.items) {
if (current == null) {
current = projectile;
count = 1;
continue;
}
if (ItemStack.matches(current, projectile)) {
++count;
continue;
}
ChargedProjectiles.addProjectileTooltip(context, consumer, current, count);
current = projectile;
count = 1;
}
if (current != null) {
ChargedProjectiles.addProjectileTooltip(context, consumer, current, count);
}
}
private static void addProjectileTooltip(Item.TooltipContext context, Consumer<Component> consumer, ItemStack projectile, int count) {
if (count == 1) {
consumer.accept(Component.translatable("item.minecraft.crossbow.projectile.single", projectile.getDisplayName()));
} else {
consumer.accept(Component.translatable("item.minecraft.crossbow.projectile.multiple", count, projectile.getDisplayName()));
}
TooltipDisplay projectileDisplay = projectile.getOrDefault(DataComponents.TOOLTIP_DISPLAY, TooltipDisplay.DEFAULT);
projectile.addDetailsToTooltip(context, projectileDisplay, null, TooltipFlag.NORMAL, line -> consumer.accept(Component.literal(" ").append((Component)line).withStyle(ChatFormatting.GRAY)));
}
}