Skip to content

Commit

Permalink
bag info
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyMialee committed Nov 2, 2023
1 parent 6555328 commit 4bb078f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions src/main/java/ladysnake/ratsmischief/common/item/RatItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ public RatEntity getRatFromItem(World world, ItemStack ratItemStack, Vec3d spawn

@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> 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);
}
Expand All @@ -182,8 +182,8 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> 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())));
}
Expand Down
45 changes: 29 additions & 16 deletions src/main/java/ladysnake/ratsmischief/common/item/RatPouchItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<RatEntity> CLOSEST_RAT_PREDICATE = (ratEntity) -> ratEntity.isTamed();
private final int size;
Expand Down Expand Up @@ -90,7 +89,7 @@ public TypedActionResult<ItemStack> 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();
Expand All @@ -109,26 +108,40 @@ public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity

@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> 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);
Expand Down

0 comments on commit 4bb078f

Please sign in to comment.