diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0c85a1f..c30b486 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/ladysnake/ratsmischief/common/item/RatItem.java b/src/main/java/ladysnake/ratsmischief/common/item/RatItem.java index 9194a6f..55370e0 100644 --- a/src/main/java/ladysnake/ratsmischief/common/item/RatItem.java +++ b/src/main/java/ladysnake/ratsmischief/common/item/RatItem.java @@ -166,10 +166,10 @@ public RatEntity getRatFromItem(World world, ItemStack ratItemStack, Vec3d spawn @Override public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - NbtCompound ratTag = getRatTag(stack, world); - MutableText ratType = Text.translatable("type.ratsmischief." + getRatType(stack).name().toLowerCase()); + var ratTag = getRatTag(stack, world); + var ratType = Text.translatable("type.ratsmischief." + getRatType(stack).name().toLowerCase()); - Style style = EMPTY.withColor(Formatting.DARK_GRAY); + var style = EMPTY.withColor(Formatting.DARK_GRAY); if (ratTag.getString("RatType").equals(RatEntity.Type.GOLD.name())) { style = EMPTY.withColor(Formatting.GOLD); } @@ -182,8 +182,8 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List too } // potion genes - Identifier potionId = new Identifier(ratTag.getString("PotionGene")); - StatusEffect statusEffect = Registry.STATUS_EFFECT.get(potionId); + var potionId = new Identifier(ratTag.getString("PotionGene")); + var statusEffect = Registry.STATUS_EFFECT.get(potionId); if (statusEffect != null) { tooltip.add(Text.translatable("item.ratsmischief.rat.tooltip.potion").setStyle(EMPTY.withColor(Formatting.GRAY)).append(MialeeText.withColor(Text.translatable(statusEffect.getTranslationKey()).setStyle(EMPTY), statusEffect.getColor()))); } diff --git a/src/main/java/ladysnake/ratsmischief/common/item/RatPouchItem.java b/src/main/java/ladysnake/ratsmischief/common/item/RatPouchItem.java index 207f487..4011f1d 100644 --- a/src/main/java/ladysnake/ratsmischief/common/item/RatPouchItem.java +++ b/src/main/java/ladysnake/ratsmischief/common/item/RatPouchItem.java @@ -13,24 +13,23 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; +import static net.minecraft.text.Style.EMPTY; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; import net.minecraft.util.TypedActionResult; +import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; +import xyz.amymialee.mialeemisc.util.MialeeText; import java.util.List; import java.util.function.Predicate; -import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -import static net.minecraft.text.Style.EMPTY; - public class RatPouchItem extends Item { private static final Predicate CLOSEST_RAT_PREDICATE = (ratEntity) -> ratEntity.isTamed(); private final int size; @@ -90,7 +89,7 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han @Override public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { - NbtList NbtList = user.getStackInHand(hand).getOrCreateSubNbt(RatsMischief.MOD_ID).getList("rats", NbtType.COMPOUND); + NbtList NbtList = user.getStackInHand(hand).getOrCreateSubNbt(RatsMischief.MOD_ID).getList("rats", NbtElement.COMPOUND_TYPE); if (NbtList.size() < this.size && entity instanceof RatEntity && ((RatEntity) entity).getOwnerUuid() != null && ((RatEntity) entity).getOwnerUuid().equals(user.getUuid())) { NbtCompound NbtCompound = new NbtCompound(); @@ -109,26 +108,40 @@ public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity @Override public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - NbtList NbtList = stack.getOrCreateSubNbt(RatsMischief.MOD_ID).getList("rats", NbtType.COMPOUND); + var NbtList = stack.getOrCreateSubNbt(RatsMischief.MOD_ID).getList("rats", NbtElement.COMPOUND_TYPE); tooltip.add(Text.translatable("item.ratsmischief.rat_pouch.tooltip.capacity", NbtList.size(), this.size).setStyle(EMPTY.withColor(Formatting.GRAY))); - for (NbtElement ratTag : NbtList) { - MutableText ratType = Text.translatable("type.ratsmischief." + ((NbtCompound) ratTag).getString("RatType").toLowerCase()); - - Style style = EMPTY.withColor(Formatting.DARK_GRAY); + for (var ratTag : NbtList) { + var style = EMPTY.withColor(Formatting.DARK_GRAY); if (((NbtCompound) ratTag).getString("RatType").equals(RatEntity.Type.GOLD.name())) { style = EMPTY.withColor(Formatting.GOLD); } + var ratType = Text.translatable("type.ratsmischief." + ((NbtCompound) ratTag).getString("RatType").toLowerCase()).setStyle(style); + + // name + var text = ratType; if (((NbtCompound) ratTag).contains("CustomName")) { - Matcher matcher = Pattern.compile("\\{\"text\":\"(.+)\"\\}").matcher(((NbtCompound) ratTag).getString("CustomName")); + var matcher = Pattern.compile("\\{\"text\":\"(.+)\"\\}").matcher(((NbtCompound) ratTag).getString("CustomName")); if (matcher.find()) { - String name = matcher.group(1); - tooltip.add(Text.literal(name).append(" (").append(ratType).append(")").setStyle(style)); + var name = matcher.group(1); + text = Text.literal(name).append(" (").append(ratType).append(")"); } - } else { - tooltip.add(ratType.setStyle(style)); } + + // spy + if (((NbtCompound) ratTag).getBoolean("Spy")) { + text = text.append(" (").append(Text.translatable("item.ratsmischief.rat.tooltip.spy").setStyle(EMPTY.withColor(Formatting.DARK_GREEN))).append(")"); + } + + // potion genes + var potionId = new Identifier(((NbtCompound) ratTag).getString("PotionGene")); + var statusEffect = Registry.STATUS_EFFECT.get(potionId); + if (statusEffect != null) { + text = text.append(" (").append(Text.translatable("item.ratsmischief.rat.tooltip.potion").setStyle(EMPTY.withColor(Formatting.GRAY)).append(MialeeText.withColor(Text.translatable(statusEffect.getTranslationKey()).setStyle(EMPTY), statusEffect.getColor()))).append(")"); + } + + tooltip.add(text); } super.appendTooltip(stack, world, tooltip, context);