diff --git a/README.MD b/README.MD index 9650ebe..9dfaede 100644 --- a/README.MD +++ b/README.MD @@ -1,63 +1,13 @@ -# **AnimalRPs mod** +# AnimalRP port to Fabric -## **Animal listing** -1. Bee - Doubleclicking shift you will float (levitation 5 for 1 second), allowing for better movement up hills as example. **Your superfoods are all flowers.** -2. Cat - You take significantly less damage when falling (5 hearts). You can still die, don't count on your cat-powers catching you every time. **Your superfood is all types of eatable fish.** -3. Fox - You do more damage to mobs (25%). **Your superfoods are glow berries and apples.** -4. Dog - You get speed 2 when doing damage. **Your superfood are uncooked meats.** -5. Cow - When you hit a mob, there's a 30% chance of slowing them down. Works on players aswell. **Your superfoods are apples, golden apples, and carrots.** -## **Interactions** -1. headpats - You can also rightclick to headpat a animal. -2. kiss -3. bite -4. scratch -5. hug -6. cuddle -7. boop -8. nuzzle -## **Chat** -Chat while you are a animal is very different. When you speak, your words will become furry-ified and every time you talk you'll have animal sounds come out of you. You can disable this via /chatmodoff, and turn it back on via /chatmodon. +Order of importance: +TODO: -If you do not want to see these chat changes, run /disableanimalchat. This will disable them for you, and you only. - -## **Superfoods** -Superfoods are items that when eaten, give you stackable **Speed II** and insane amounts of saturation (9.4 points) and hunger (4 points). - -## **How to add a new animal?** - -1. Create a new class in animals/MyCoolAnimal.java -2. Use this template -``` -public class MyCoolAnimal extends Animal { - TextDestroyer destroyer = new TextDestroyer(new String[]{ - "I'm Cool!" - }, new String[][]{ - {"g", "z"} - }); - - public MyCoolAnimal() { - super("coolanimal", "awsome!", "#00ff00"); - this.moodSounds.put(Mood.HAPPY, Sound.ENTITY_FOX_EAT); - this.moodSounds.put(Mood.CUTE, Sound.ENTITY_FOX_SLEEP); - this.moodSounds.put(Mood.SAD, Sound.ENTITY_FOX_SNIFF); - this.moodSounds.put(Mood.STRESSED, Sound.ENTITY_FOX_AGGRO); - this.moodSounds.put(Mood.ANGRY, Sound.ENTITY_FOX_BITE); - - this.superfoods.add(Material.POTATO); - } - - @Override - public String chatTransformations(String message) { - return this.destroyer.destroy(message); - } -} -``` -3. Change the info in the TextDestroyer initialization -4. Change the info in the super() call, it is written as "name", "catchphrase", "color". -5. Change the moodSounds and implement all sounds for the moods. -6. Add superfoods (foods that the animal likes) \ No newline at end of file +- [ ] Database +- [ ] Player leashing +- [No] Cooldowns +- [No] Emotes +- [x] Bee +- [x] Cat +- [x] Dog +- [x] Fox \ No newline at end of file diff --git a/build.gradle b/build.gradle index 97c78e9..3f79d18 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation include("eu.pb4:placeholder-api:2.5.1+1.21.3") + modImplementation include("eu.pb4:placeholder-api:2.4.1+1.21") // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" diff --git a/gradle.properties b/gradle.properties index a6eb3db..38ca5f0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,14 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.4 -yarn_mappings=1.21.4+build.7 -loader_version=0.16.9 +minecraft_version=1.21.1 +yarn_mappings=1.21.1+build.3 +loader_version=0.16.4 # Mod Properties -mod_version=2.0.0 +mod_version=1.0.0 maven_group=ovh.sad.animalrp archives_base_name=animal-rp # Dependencies -fabric_version=0.114.0+1.21.4 +fabric_version=0.103.0+1.21.1 diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index 390139d..7992ed5 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -1,37 +1,24 @@ package ovh.sad.animalrp; -import eu.pb4.placeholders.api.*; -import eu.pb4.placeholders.api.parsers.NodeParser; -import eu.pb4.placeholders.api.parsers.TagParser; -import eu.pb4.placeholders.api.parsers.TextParserV1; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; -import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; -import net.fabricmc.fabric.api.event.player.UseEntityCallback; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.sound.SoundCategory; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; -import ovh.sad.animalrp.animals.*; -import ovh.sad.animalrp.commands.InfoCommand; +import ovh.sad.animalrp.animals.Animal; +import ovh.sad.animalrp.animals.Cat; +import ovh.sad.animalrp.animals.Dog; +import ovh.sad.animalrp.animals.Fox; +import ovh.sad.animalrp.animals.Bee; import ovh.sad.animalrp.commands.InteractionCommand; import ovh.sad.animalrp.commands.NoChatCommand; import ovh.sad.animalrp.commands.TfCommand; -import ovh.sad.animalrp.util.HashmapStore; import ovh.sad.animalrp.util.Mood; +import eu.pb4.placeholders.api.PlaceholderContext; +import eu.pb4.placeholders.api.PlaceholderHandler; +import eu.pb4.placeholders.api.PlaceholderResult; +import eu.pb4.placeholders.api.Placeholders; import java.util.HashMap; -import java.util.Map; import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -39,6 +26,7 @@ import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + public class AnimalRP implements ModInitializer { public static ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); @@ -48,39 +36,12 @@ public class AnimalRP implements ModInitializer { public static final String MOD_ID = "animal-rp"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); - - private static final Map lastPetTimes = new ConcurrentHashMap<>(); - private static final long COOLDOWN_MS = 1000; - public static final NodeParser parser = TagParser.DEFAULT; - - public static Text parseText(String text) { - return AnimalRP.parser.parseNode(text).toText(); - } @Override public void onInitialize() { - - String catAscii = """ - - |\\ _,,,---,,_ -ZZZzz /,`.-'`' -. ;-;;,_ - |,4- ) )-,_. ,\\ ( `'-' - '---''(_/--' `-'\\_) - """; - LOGGER.info(catAscii); - LOGGER.info("furry animal mod for fabric"); - LOGGER.info("by @fucksophie - est. Sept 2024, improvements Mar 2025"); animals.put("cat", new Cat()); animals.put("dog", new Dog()); animals.put("fox", new Fox()); animals.put("bee", new Bee()); - animals.put("cow", new Cow()); - - HashmapStore.get("users.json").forEach((k, v) -> { - users.put(UUID.fromString(k), animals.get(v)); - }); - HashmapStore.get("nochat.json").forEach((k, v) -> { - noChat.put(UUID.fromString(k), Boolean.valueOf(v)); - }); Placeholders.register(Identifier.of("animalrp", "animalcolor"), new PlaceholderHandler() { @Override @@ -88,68 +49,22 @@ ZZZzz /,`.-'`' -. ;-;;,_ if (!ctx.hasPlayer()) return PlaceholderResult.invalid("No player!"); Animal animal = users.get(ctx.player().getUuid()); - if (animal == null) + if(animal == null) return PlaceholderResult.value(""); - if (noChat.get(ctx.player().getUuid()) != null) - return PlaceholderResult.value(""); - return PlaceholderResult.value(animal.color); + return PlaceholderResult.value(""); } }); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { (new TfCommand()).Command(dispatcher, registryAccess, environment); (new NoChatCommand()).Command(dispatcher, registryAccess, environment); - (new InfoCommand()).Command(dispatcher, registryAccess, environment); - (new InteractionCommand("headpats", Mood.HAPPY, "%s petted you! %s", "You petted %s! %s")) - .Command(dispatcher, registryAccess, environment); - (new InteractionCommand("kiss", Mood.CUTE, "%s kissed you.. 0////0 %s", "You kissed %s.. 0////0 %s")) - .Command(dispatcher, registryAccess, environment); - (new InteractionCommand("bite", Mood.ANGRY, "%s bit you!! Σ(っ゚Д゚)っ %s", "You bit %s! (○`д´)ノシ %s")) - .Command(dispatcher, registryAccess, environment); - (new InteractionCommand("scratch", Mood.ANGRY, "%s SCRATCHES YOU! Ow! %s", - "You channel your inner evil, and scratch %s! %s")) - .Command(dispatcher, registryAccess, environment); - (new InteractionCommand("hug", Mood.HAPPY, "%s hugs you! How heartwarming. %s", - "You hug %s! How heartwarming. %s")).Command(dispatcher, registryAccess, environment); - (new InteractionCommand("cuddle", Mood.CUTE, "%s cuddles with you. %s", - "You and %s start cuddling. How cute! %s")).Command(dispatcher, registryAccess, environment); - (new InteractionCommand("boop", Mood.CUTE, "%s boops your nose! %s", "You boop %s's nose! %s")) - .Command(dispatcher, registryAccess, environment); - (new InteractionCommand("nuzzle", Mood.CUTE, "%s nuzzles you! %s", "You nuzzle %s! %s")) - .Command(dispatcher, registryAccess, environment); - }); - ServerLifecycleEvents.SERVER_STOPPING.register((server) -> { - executor.shutdownNow(); - }); - UseEntityCallback.EVENT.register((attacker, world, hand , attackeee, ehr) -> { - if(!(attackeee instanceof PlayerEntity)) { - return ActionResult.PASS; - } - PlayerEntity attackee = (PlayerEntity) attackeee; - - Animal attackerAnimal = AnimalRP.users.get(attacker.getUuid()); - if(attackerAnimal == null) return ActionResult.PASS; - Animal attackeeAnimal = AnimalRP.users.get(attackee.getUuid()); - if(attackeeAnimal == null) return ActionResult.PASS; - - UUID attackerId = attacker.getUuid(); - long currentTime = System.currentTimeMillis(); - - if (lastPetTimes.getOrDefault(attackerId, 0L) + COOLDOWN_MS > currentTime) { - return ActionResult.PASS; - } - - lastPetTimes.put(attackerId, currentTime); - - MinecraftServer server = attacker.getServer(); - if (server != null) { - server.execute(() -> { - server.getCommandManager().executeWithPrefix(attacker.getCommandSource((ServerWorld) world), "headpats " + attackee.getName().getString()); - }); - } - System.out.println(attackee.getNameForScoreboard() + " was rightclicked by " + attacker.getNameForScoreboard()); - return ActionResult.PASS; + (new InteractionCommand("headpats", Mood.HAPPY, "%s petted you! %s", "You petted %s! %s")).Command(dispatcher, registryAccess, environment); + (new InteractionCommand("kiss", Mood.CUTE, "%s kissed you.. 0////0 %s", "You kissed %s.. 0////0 %s")).Command(dispatcher, registryAccess, environment); + (new InteractionCommand("bite", Mood.ANGRY, "%s bit you!! Σ(っ゚Д゚)っ %s", "You bit %s! (○`д´)ノシ %s")).Command(dispatcher, registryAccess, environment); + (new InteractionCommand("scratch", Mood.ANGRY, "%s SCRATCHES YOU! Ow! %s", "You channel your inner evil, and scratch %s! %s")).Command(dispatcher, registryAccess, environment); + (new InteractionCommand("hug", Mood.HAPPY, "%s hugs you! How heartwarming. %s", "You hug %s! How heartwarming. %s")).Command(dispatcher, registryAccess, environment); + (new InteractionCommand("cuddle", Mood.CUTE, "%s cuddles with you. %s", "You and %s start cuddling. How cute! %s")).Command(dispatcher, registryAccess, environment); }); } } \ No newline at end of file diff --git a/src/main/java/ovh/sad/animalrp/animals/Animal.java b/src/main/java/ovh/sad/animalrp/animals/Animal.java index b796ba4..7ee5cfc 100644 --- a/src/main/java/ovh/sad/animalrp/animals/Animal.java +++ b/src/main/java/ovh/sad/animalrp/animals/Animal.java @@ -14,10 +14,6 @@ public abstract class Animal { public HashMap moodSounds = new HashMap(); public ArrayList superfoods = new ArrayList(); - public String toString() { - return this.name; - } - Animal(String name, String catchphrase, String color) { this.name = name; this.catchphrase = catchphrase; diff --git a/src/main/java/ovh/sad/animalrp/animals/Bee.java b/src/main/java/ovh/sad/animalrp/animals/Bee.java index 4c52127..ea08109 100644 --- a/src/main/java/ovh/sad/animalrp/animals/Bee.java +++ b/src/main/java/ovh/sad/animalrp/animals/Bee.java @@ -11,22 +11,17 @@ import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.component.DataComponentTypes; -import net.minecraft.component.type.ConsumableComponent; -import net.minecraft.component.type.ConsumableComponents; import net.minecraft.component.type.FoodComponent; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.item.consume.ApplyEffectsConsumeEffect; -import net.minecraft.item.consume.ConsumeEffect; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; -import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; -import org.jetbrains.annotations.NotNull; +import net.minecraft.util.TypedActionResult; import ovh.sad.animalrp.AnimalRP; import ovh.sad.animalrp.util.Mood; import ovh.sad.animalrp.util.TextDestroyer; @@ -38,13 +33,13 @@ public class Bee extends Animal { } - private static final Item[] _allFlowers = { Items.ALLIUM, Items.AZURE_BLUET, Items.BLUE_ORCHID, + private static Item[] _allFlowers = { Items.ALLIUM, Items.AZURE_BLUET, Items.BLUE_ORCHID, Items.CORNFLOWER, Items.DANDELION, Items.LILY_OF_THE_VALLEY, Items.OXEYE_DAISY, Items.POPPY, Items.TORCHFLOWER, Items.ORANGE_TULIP, Items.PINK_TULIP, Items.RED_TULIP, Items.WHITE_TULIP }; - public static final List allFlowers = Arrays.asList(_allFlowers); - public static HashMap inARow = new HashMap<>(); - + public static List allFlowers = Arrays.asList(_allFlowers); + public static Identifier beeFoodKey = Identifier.of("animalrp", "bee_food"); + public static HashMap inARow = new HashMap(); TextDestroyer destroyer = new TextDestroyer(new String[] { ">_<", "*buzz*", ";3", ":3", "εწз", " ≧◠◡◠≦ ", "*stings you*", "*humms*", @@ -64,7 +59,7 @@ public class Bee extends Animal { ArrayList sneakers = new ArrayList(); - public static @NotNull Boolean isItemARP(ItemStack is) { + public static Boolean isItemARP(ItemStack is) { return (allFlowers.contains(is.getItem()) && is.get(DataComponentTypes.FOOD) != null); } @@ -75,27 +70,24 @@ public class Bee extends Animal { this.moodSounds.put(Mood.SAD, SoundEvents.ENTITY_BEE_HURT); this.moodSounds.put(Mood.STRESSED, SoundEvents.ENTITY_BEE_STING); this.moodSounds.put(Mood.ANGRY, SoundEvents.ENTITY_BEE_LOOP_AGGRESSIVE); - - this.superfoods.addAll(allFlowers); - UseItemCallback.EVENT.register((player, world, hand) -> { Animal animal = AnimalRP.users.get(player.getUuid()); ItemStack item = player.getStackInHand(hand); if (item == null) // air interact - return ActionResult.PASS; + return TypedActionResult.pass(item); if (!allFlowers.contains(item.getItem())) { // not a flower - return ActionResult.PASS; + return TypedActionResult.pass(item); } - boolean incorrect = false; + Boolean incorrect = false; if (animal == null) { incorrect = true; } else { - if (!animal.name.equals(this.name)) { + if (animal.name != this.name) { incorrect = true; } } @@ -104,33 +96,31 @@ public class Bee extends Animal { if (Bee.isItemARP(item)) { item.remove(DataComponentTypes.FOOD); - return ActionResult.PASS; + return TypedActionResult.pass(item); } - return ActionResult.PASS; + return TypedActionResult.pass(item); } if (Bee.isItemARP(item)) { // correct animal, but foodkey already set - return ActionResult.PASS; + return TypedActionResult.pass(item); } - FoodComponent food = new FoodComponent.Builder() + .statusEffect(new StatusEffectInstance(StatusEffects.SPEED, 20 * 4, 1, true, true, true), 1) .alwaysEdible() + .nutrition(4) + .saturationModifier(9.4f) .build(); - - ConsumableComponent consumable = ConsumableComponents.food() - .build(); item.set(DataComponentTypes.FOOD, food); - item.set(DataComponentTypes.CONSUMABLE, consumable); - return ActionResult.PASS; + return TypedActionResult.pass(item); }); } // Called from the FoodEating mixin. // Called only if the player is a animal and a bee. - public void onEat(ServerPlayerEntity player, @NotNull ItemStack item) { + public void onEat(ServerPlayerEntity player, ItemStack item) { if (!allFlowers.contains(item.getItem())) { // not a flower return; } @@ -164,11 +154,11 @@ public class Bee extends Animal { } // Called from the 'Sneaking' mixin. - public void onSneak(@NotNull ServerPlayerEntity player, boolean status) { + public void onSneak(ServerPlayerEntity player, boolean status) { Animal animal = AnimalRP.users.get(player.getUuid()); if (animal == null) return; - if (!animal.name.equals(this.name)) + if (animal.name != this.name) return; Block type = player.getWorld().getBlockState(player.getBlockPos().down()).getBlock(); diff --git a/src/main/java/ovh/sad/animalrp/animals/Cow.java b/src/main/java/ovh/sad/animalrp/animals/Cow.java deleted file mode 100644 index b92958e..0000000 --- a/src/main/java/ovh/sad/animalrp/animals/Cow.java +++ /dev/null @@ -1,63 +0,0 @@ -package ovh.sad.animalrp.animals; - -import java.util.Random; - -import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Items; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.sound.SoundEvents; -import ovh.sad.animalrp.AnimalRP; -import ovh.sad.animalrp.util.Mood; -import ovh.sad.animalrp.util.TextDestroyer; - -public class Cow extends Animal { - TextDestroyer destroyer = new TextDestroyer(new String[] { - "Moo!", "Moooo~", - "Moo?", "Mooooo!", "MooMoo" - }, new String[][] { - { "you", "moo" }, - { "o", "oo" }, - { "i", "ii" }, - { "a", "aa" }, - { "e", "ee" } - }); - Random rand = new Random(); - - public Cow() { - super("cow", "Moo!", "#a52a2a"); - this.moodSounds.put(Mood.HAPPY, SoundEvents.ENTITY_COW_AMBIENT); - this.moodSounds.put(Mood.CUTE, SoundEvents.ENTITY_COW_STEP); - this.moodSounds.put(Mood.SAD, SoundEvents.ENTITY_COW_HURT); - this.moodSounds.put(Mood.STRESSED, SoundEvents.ENTITY_COW_HURT); - this.moodSounds.put(Mood.ANGRY, SoundEvents.ENTITY_COW_DEATH); - - this.superfoods.add(Items.APPLE); - this.superfoods.add(Items.GOLDEN_APPLE); - this.superfoods.add(Items.CARROT); - - ServerLivingEntityEvents.AFTER_DAMAGE.register((entity, source, baseDmg, dmg, blocked) -> { - if (!(source.getSource() instanceof ServerPlayerEntity damaged)) return; - if (entity instanceof PlayerEntity) return; - - Animal animal = AnimalRP.users.get(damaged.getUuid()); - - if (animal == null || !animal.name.equals(this.name)) { - return; - } - - if (rand.nextFloat() < 0.3) { - entity.removeStatusEffect(StatusEffects.SLOWNESS); - entity.addStatusEffect( - new StatusEffectInstance(StatusEffects.SLOWNESS, 20, 2, true, true, true)); - } - }); - } - - @Override - public String chatTransformations(String message) { - return this.destroyer.destroy(message); - } -} diff --git a/src/main/java/ovh/sad/animalrp/animals/Dog.java b/src/main/java/ovh/sad/animalrp/animals/Dog.java index 7e78e23..dfd7eab 100644 --- a/src/main/java/ovh/sad/animalrp/animals/Dog.java +++ b/src/main/java/ovh/sad/animalrp/animals/Dog.java @@ -34,7 +34,7 @@ public class Dog extends Animal { if (animal == null) return ActionResult.PASS; - if (!animal.name.equals(this.name)) + if (animal.name != this.name) return ActionResult.PASS; player.removeStatusEffect(StatusEffects.SPEED); player.addStatusEffect( diff --git a/src/main/java/ovh/sad/animalrp/animals/Fox.java b/src/main/java/ovh/sad/animalrp/animals/Fox.java index c000626..bbe79bd 100644 --- a/src/main/java/ovh/sad/animalrp/animals/Fox.java +++ b/src/main/java/ovh/sad/animalrp/animals/Fox.java @@ -3,11 +3,10 @@ package ovh.sad.animalrp.animals; import java.util.Random; import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; -import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Items; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundEvents; import ovh.sad.animalrp.AnimalRP; import ovh.sad.animalrp.util.Mood; @@ -42,16 +41,19 @@ public class Fox extends Animal { this.superfoods.add(Items.GLOW_BERRIES); ServerLivingEntityEvents.AFTER_DAMAGE.register((entity, source, baseDmg, dmg, blocked) -> { - if(!(source.getSource() instanceof ServerPlayerEntity damager)) return; + if(!(source.getSource() instanceof ServerPlayerEntity)) return; if(entity instanceof PlayerEntity) return; + Entity victim = entity; + ServerPlayerEntity damager = (ServerPlayerEntity) source.getSource(); + Animal animal = AnimalRP.users.get(damager.getUuid()); if (animal == null || !animal.name.equals(this.name)) { return; } - entity.damage((ServerWorld) entity.getWorld(), entity.getDamageSources().playerAttack(damager), dmg * 0.25F); + victim.damage(victim.getDamageSources().playerAttack(damager), dmg * 0.25F); }); } diff --git a/src/main/java/ovh/sad/animalrp/commands/InfoCommand.java b/src/main/java/ovh/sad/animalrp/commands/InfoCommand.java deleted file mode 100644 index 10628a5..0000000 --- a/src/main/java/ovh/sad/animalrp/commands/InfoCommand.java +++ /dev/null @@ -1,35 +0,0 @@ -package ovh.sad.animalrp.commands; - -import java.util.UUID; - -import com.mojang.brigadier.CommandDispatcher; - -import eu.pb4.placeholders.api.TextParserUtils; -import eu.pb4.placeholders.api.parsers.TagParser; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; -import ovh.sad.animalrp.AnimalRP; -import ovh.sad.animalrp.animals.Animal; -import ovh.sad.animalrp.util.HashmapStore; - -public class InfoCommand { - public void Command(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, - CommandManager.RegistrationEnvironment environment) { - dispatcher.register(CommandManager.literal("rpinfo").executes(context -> { - context.getSource().sendFeedback(() -> AnimalRP.parseText("AnimalRPs is a mod that adds animals to Minecraft."), false); - context.getSource().sendFeedback(() -> AnimalRP.parseText("Usage of this mod is very simple."), false); - context.getSource().sendFeedback(() -> AnimalRP.parseText("- To select a animal, use: /tf"), false); - context.getSource().sendFeedback(() -> AnimalRP.parseText("- To turn off animals, use: /tf off"), false); - context.getSource().sendFeedback(() -> AnimalRP.parseText("- Don't want the chat changes? Use: /disableanimalchat."), false); - context.getSource().sendFeedback(Text::empty, false); - context.getSource().sendFeedback(() -> AnimalRP.parseText("- To see what the animals do, visit: https://git.sad.ovh/sophie/animalrpfabric"), false); - context.getSource().sendFeedback(() -> AnimalRP.parseText("- To pet someone, rightclick on them (they must be a animal!)"), false); - context.getSource().sendFeedback(Text::empty, false); - context.getSource().sendFeedback(() -> AnimalRP.parseText("To see available animals, run /tf"), false); - return 0; - })); - } - -} \ No newline at end of file diff --git a/src/main/java/ovh/sad/animalrp/commands/InteractionCommand.java b/src/main/java/ovh/sad/animalrp/commands/InteractionCommand.java index 5129bce..8eeff06 100644 --- a/src/main/java/ovh/sad/animalrp/commands/InteractionCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/InteractionCommand.java @@ -2,6 +2,7 @@ package ovh.sad.animalrp.commands; import com.mojang.brigadier.CommandDispatcher; +import eu.pb4.placeholders.api.TextParserUtils; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.entity.Entity; @@ -9,6 +10,7 @@ import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.sound.SoundCategory; +import net.minecraft.text.Text; import ovh.sad.animalrp.AnimalRP; import ovh.sad.animalrp.animals.Animal; import ovh.sad.animalrp.util.Mood; @@ -26,6 +28,7 @@ public class InteractionCommand { this.mood = mood; } + @SuppressWarnings("deprecation") public void Command(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { dispatcher.register(CommandManager.literal(this.command) @@ -35,18 +38,17 @@ public class InteractionCommand { if (!(sender instanceof ServerPlayerEntity)) { context.getSource().sendFeedback( - () -> AnimalRP.parseText("I'm sorry console."), false); + () -> Text.literal("I'm sorry console.").withColor(8421504), false); return 0; } - ServerPlayerEntity player = context.getSource().getPlayerOrThrow(); + ServerPlayerEntity player = context.getSource().getPlayer(); Animal aplayer = AnimalRP.users.get(player.getUuid()); if (aplayer == null) { context.getSource().sendFeedback( - () -> AnimalRP.parseText("Only animals can interact with other animals :("), - false); + () -> Text.literal("Only animals can interact with other animals :(").withColor(8421504), false); return 0; } @@ -54,29 +56,26 @@ public class InteractionCommand { if (splayer.getName() == player.getName()) { context.getSource().sendFeedback( - () -> AnimalRP.parseText("You can't " + this.command + " yourself."), - false); + () -> Text.literal("You can't " + this.command + " yourself.").withColor(8421504), false); return 0; } Animal asplayer = AnimalRP.users.get(splayer.getUuid()); if (asplayer == null) { context.getSource().sendFeedback( - () -> AnimalRP.parseText(""+splayer.getName() + " is not an animal! :("), - false); + () -> Text.literal(splayer.getName() + " is not an animal! :(").withColor(8421504), false); return 0; } - splayer.sendMessage(AnimalRP.parseText( + splayer.sendMessage(TextParserUtils.formatText( String.format(this.toThem, - "" + player.getName().getString() + "", + "" + player.getName().getString() + "", "" + aplayer.catchphrase))); - player.sendMessage(AnimalRP.parseText( + player.sendMessage(TextParserUtils.formatText( String.format(this.toYou, - "" + splayer.getName().getString() + "", + "" + splayer.getName().getString() + "", "" + asplayer.catchphrase))); - player.getWorld().playSound(splayer, splayer.getBlockPos(), - asplayer.moodSounds.get(this.mood), SoundCategory.PLAYERS, 1F, + player.getWorld().playSound(splayer, splayer.getBlockPos(), asplayer.moodSounds.get(this.mood), SoundCategory.PLAYERS, 1F, 1); return 1; }))); diff --git a/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java b/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java index b27d0df..fc1050d 100644 --- a/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java @@ -9,27 +9,22 @@ import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; import ovh.sad.animalrp.AnimalRP; -import ovh.sad.animalrp.util.HashmapStore; public class NoChatCommand { public void Command(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { dispatcher.register(CommandManager.literal("disableanimalchat").executes(context -> { - UUID userUuid = context.getSource().getEntityOrThrow().getUuid(); + UUID userUuid = context.getSource().getEntity().getUuid(); - Boolean isDisabled = AnimalRP.noChat.get(context.getSource().getEntityOrThrow().getUuid()); - if (isDisabled == null) - isDisabled = false; - if (isDisabled) { - context.getSource().sendFeedback( - () -> AnimalRP.parseText("AnimalRP's chat modifications are now enabled for you."), - false); + Boolean isDisabled = AnimalRP.noChat.get(context.getSource().getEntity().getUuid()); + if(isDisabled == null) isDisabled = false; + if(isDisabled) { // + context.getSource().sendFeedback(() -> Text.literal("AnimalRP's chat modifications are now enabled for you.").withColor(65280), false); AnimalRP.noChat.remove(userUuid); } else { - context.getSource().sendFeedback(() -> AnimalRP.parseText("AnimalRP's chat modifications are now disabled for you."), false); + context.getSource().sendFeedback(() -> Text.literal("AnimalRP's chat modifications are now disabled for you.").withColor(16711680), false); AnimalRP.noChat.put(userUuid, true); } - HashmapStore.save("nochat.json", AnimalRP.noChat); return 0; })); diff --git a/src/main/java/ovh/sad/animalrp/commands/TfCommand.java b/src/main/java/ovh/sad/animalrp/commands/TfCommand.java index 32cdfa5..3a6222e 100644 --- a/src/main/java/ovh/sad/animalrp/commands/TfCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/TfCommand.java @@ -9,62 +9,64 @@ import net.minecraft.command.CommandRegistryAccess; import net.minecraft.entity.Entity; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import ovh.sad.animalrp.AnimalRP; import ovh.sad.animalrp.animals.Animal; -import ovh.sad.animalrp.util.HashmapStore; public class TfCommand { public void Command(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { dispatcher.register(CommandManager.literal("tf") - .executes(context -> { - classicError(context.getSource(), false); - return 1; - }) .then(CommandManager.argument("animal", StringArgumentType.string()) .executes(context -> { - final Entity entity = context.getSource().getEntityOrThrow(); + final Entity entity = context.getSource().getEntity(); final String animalString = StringArgumentType.getString(context, "animal"); + System.out.println(animalString); + System.out.println(animalString.length()); Animal animal = AnimalRP.animals.get(animalString); if (animalString.equals("off")) { if (AnimalRP.users.get(entity.getUuid()) == null) { context.getSource().sendFeedback( - () -> AnimalRP.parseText("You do not have a animal set."), false); + () -> Text.literal("You do not have a animal set."), false); return 0; } AnimalRP.users.remove(entity.getUuid()); context.getSource().sendFeedback( - () -> AnimalRP.parseText("You no longer have a animal set."), false); - HashmapStore.save("users.json", AnimalRP.users); + () -> Text.literal("You no longer have a animal set."), false); return 0; } - if(animal == null) { - classicError(context.getSource(), true); + if (animal == null) { + classicError(context.getSource()); return 0; } AnimalRP.users.put(entity.getUuid(), animal); context.getSource() .sendFeedback( - () -> AnimalRP.parseText("You are now an " + animalString + "! "+animal.catchphrase), + () -> Text.literal("You are now an " + animalString + "! ") + .append(Text.literal(animal.catchphrase) + .formatted(Formatting.ITALIC).withColor( + Integer.parseInt(animal.color.substring(1), + 16))), false); - HashmapStore.save("users.json", AnimalRP.users); return 1; }))); } - void classicError(ServerCommandSource source, Boolean showInvalidAnimal) { - StringBuilder options = new StringBuilder("Your options are: "); - + void classicError(ServerCommandSource source) { + MutableText options = Text.literal("Your options are: "); for (Entry entry : AnimalRP.animals.entrySet()) { - options.append(" ").append(entry.getKey()).append(""); + options.append(Text.literal(entry.getKey() + " ") + .withColor(Integer.parseInt(entry.getValue().color.substring(1), 16))); } - if(showInvalidAnimal) source.sendFeedback(() -> AnimalRP.parseText("Invalid animal!"), false); - source.sendFeedback(() -> AnimalRP.parseText(options.toString()), false); - source.sendFeedback(() -> AnimalRP.parseText("Use /tf off to disable the changes."), false); + source.sendFeedback(() -> Text.literal("Invalid animal!").withColor(16711680), false); + source.sendFeedback(() -> options, false); + source.sendFeedback(() -> Text.literal("Use /tf off to disable the changes."), false); } } \ No newline at end of file diff --git a/src/main/java/ovh/sad/animalrp/mixin/DecoratedMessage.java b/src/main/java/ovh/sad/animalrp/mixin/DecoratedMessage.java index c7dc504..2650ea0 100644 --- a/src/main/java/ovh/sad/animalrp/mixin/DecoratedMessage.java +++ b/src/main/java/ovh/sad/animalrp/mixin/DecoratedMessage.java @@ -27,9 +27,8 @@ public abstract class DecoratedMessage { @ModifyVariable(method = "handleDecoratedMessage", at = @At(value = "HEAD"), argsOnly = true) public @NotNull SignedMessage modifyChatMessageSentByPlayers(@NotNull SignedMessage original) { - if (AnimalRP.noChat.get(player.getUuid()) != null) - return original; - + if(AnimalRP.noChat.get(player.getUuid()) != null) return original; + Animal animal = AnimalRP.users.get(player.getUuid()); if (animal == null) return original; @@ -37,7 +36,7 @@ public abstract class DecoratedMessage { player.getWorld().playSound(player, player.getBlockPos(), animal.moodSounds.get(Mood.HAPPY), SoundCategory.PLAYERS, 10F, 1); } - + return original .withUnsignedContent(Text.literal(animal.chatTransformations(original.getContent().getString()))); } diff --git a/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java b/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java index ea26245..3b76714 100644 --- a/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java +++ b/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java @@ -1,6 +1,5 @@ package ovh.sad.animalrp.mixin; -import net.minecraft.item.Item; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -18,20 +17,19 @@ import ovh.sad.animalrp.AnimalRP; import ovh.sad.animalrp.animals.Animal; import ovh.sad.animalrp.animals.Bee; -@Mixin(value = Item.class) -public class FoodEating { - @Inject(method = "finishUsing", at = @At("HEAD")) - public void finishUsing(ItemStack stack, World world, LivingEntity user, CallbackInfoReturnable cfr) { - if(world.isClient()) return; +@Mixin(value = LivingEntity.class) +public class FoodEating { + @Inject(method = "eatFood", at = @At("HEAD")) + public void eatFood(World world, ItemStack stack, FoodComponent foodComponent, CallbackInfoReturnable cfr) { + LivingEntity entity = (LivingEntity) (Object) this; + if(entity.getType().equals(EntityType.PLAYER)) { + ServerPlayerEntity player = (ServerPlayerEntity) entity; - if (user.getType().equals(EntityType.PLAYER)) { - ServerPlayerEntity player = (ServerPlayerEntity) user; + Animal animal = AnimalRP.users.get(player.getUuid()); - Animal animal = AnimalRP.users.get(player.getUuid()); - - if (animal != null) { - if (animal.name.equals("bee")) { - ((Bee) animal).onEat(player, stack); + if (animal != null) { + if(animal.name == "bee") { + ((Bee)animal).onEat(player, stack); } if (animal.superfoods.contains(stack.getItem())) { player.getHungerManager().add(4, 9.4f); diff --git a/src/main/java/ovh/sad/animalrp/mixin/Sneaking.java b/src/main/java/ovh/sad/animalrp/mixin/Sneaking.java index bb290a0..b0ed500 100644 --- a/src/main/java/ovh/sad/animalrp/mixin/Sneaking.java +++ b/src/main/java/ovh/sad/animalrp/mixin/Sneaking.java @@ -16,9 +16,9 @@ public class Sneaking { @Inject(method = "setSneaking", at = @At("HEAD")) public void setSneaking(boolean sneaking, CallbackInfo info) { Entity entity = (Entity) (Object) this; - if (entity.getType() == EntityType.PLAYER) { - Bee bee = (Bee) AnimalRP.animals.get("bee"); - bee.onSneak((ServerPlayerEntity) entity, sneaking); + if(entity.getType() == EntityType.PLAYER) { + Bee bee = (Bee)AnimalRP.animals.get("bee"); + bee.onSneak((ServerPlayerEntity)entity, sneaking); } } } diff --git a/src/main/java/ovh/sad/animalrp/util/Cooldown.java b/src/main/java/ovh/sad/animalrp/util/Cooldown.java new file mode 100644 index 0000000..a92c524 --- /dev/null +++ b/src/main/java/ovh/sad/animalrp/util/Cooldown.java @@ -0,0 +1,35 @@ +package ovh.sad.animalrp.util; + +import com.google.gson.JsonObject; + +public class Cooldown { + public long timeCreated; + public Integer length; + public String type; + + public long getTime() { + return this.timeCreated - (System.currentTimeMillis() - this.length); + } + + public boolean isExpired() { + return this.getTime() <= 0; + } + + public JsonObject toJson() { + JsonObject obj = new JsonObject(); + obj.addProperty("timeCreated", this.timeCreated); + obj.addProperty("length", this.length); + obj.addProperty("type", this.type); + + return obj; + } + + public static Cooldown fromJson(JsonObject obj) { + Cooldown cldn = new Cooldown(); + cldn.timeCreated = obj.get("timeCreated").getAsLong(); + cldn.length = obj.get("length").getAsInt(); + cldn.type = obj.get("type").getAsString(); + + return cldn; + } +} \ No newline at end of file diff --git a/src/main/java/ovh/sad/animalrp/util/HashmapStore.java b/src/main/java/ovh/sad/animalrp/util/HashmapStore.java deleted file mode 100644 index 725134f..0000000 --- a/src/main/java/ovh/sad/animalrp/util/HashmapStore.java +++ /dev/null @@ -1,65 +0,0 @@ -package ovh.sad.animalrp.util; - -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; - -import com.google.gson.Gson; -import com.google.gson.JsonIOException; -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; - -import net.fabricmc.loader.api.FabricLoader; -import ovh.sad.animalrp.AnimalRP; - -public class HashmapStore { - static public Gson gson = new Gson(); - static public Path folder = FabricLoader.getInstance().getConfigDir().resolve(AnimalRP.MOD_ID).toAbsolutePath(); - - @SuppressWarnings("unchecked") - static public HashMap get(String name) { - Path filePath = folder.resolve(name); - if (!Files.exists(filePath)) { - return new HashMap(); - } - try { - return gson.fromJson(new FileReader(filePath.toString()), HashMap.class); - } catch (JsonSyntaxException | JsonIOException | FileNotFoundException e) { - e.printStackTrace(); - return new HashMap(); - } - - } - - @SuppressWarnings("unchecked") - static public void save(String name, @SuppressWarnings("rawtypes") HashMap hashmap) { - if (!Files.exists(folder)) { - try { - Files.createDirectory(folder); - } catch (IOException e) { - e.printStackTrace(); - } - } - Path filePath = folder.resolve(name); - if (!Files.exists(filePath)) - try { - Files.createFile(filePath); - } catch (IOException e) { - e.printStackTrace(); - } - - JsonObject jsobj = new JsonObject(); - hashmap.forEach((a, b) -> { - jsobj.addProperty(a.toString(), b.toString()); - }); - - try { - Files.write(filePath, gson.toJson(jsobj).getBytes()); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/ovh/sad/animalrp/util/Mood.java b/src/main/java/ovh/sad/animalrp/util/Mood.java index 5e78720..f6db956 100644 --- a/src/main/java/ovh/sad/animalrp/util/Mood.java +++ b/src/main/java/ovh/sad/animalrp/util/Mood.java @@ -1,5 +1,5 @@ package ovh.sad.animalrp.util; public enum Mood { - HAPPY, SAD, STRESSED, ANGRY, CUTE + HAPPY,SAD,STRESSED,ANGRY,CUTE } \ No newline at end of file diff --git a/src/main/java/ovh/sad/animalrp/util/TextDestroyer.java b/src/main/java/ovh/sad/animalrp/util/TextDestroyer.java index b6cbdea..da08032 100644 --- a/src/main/java/ovh/sad/animalrp/util/TextDestroyer.java +++ b/src/main/java/ovh/sad/animalrp/util/TextDestroyer.java @@ -20,25 +20,23 @@ public class TextDestroyer { Random y = new Random(); for (String word : words) { - if ((word.startsWith("[") && word.endsWith("]")) || word.startsWith("@")) { + if((word.startsWith("[") && word.endsWith("]")) || word.startsWith("@")) { out.add(word); continue; } - - if (y.nextBoolean()) { + + if(y.nextBoolean()){ out.add(word); continue; - } - ; + }; - for (String[] replacing : this.replaces) { + for(String[] replacing: this.replaces) { word = word.replace(replacing[0], replacing[1]); } out.add(word); - - if (y.nextDouble() < 0.12) - out.add(this.expressions[y.nextInt(this.expressions.length)]); + + if(y.nextDouble() < 0.12) out.add(this.expressions[y.nextInt(this.expressions.length)]); } return String.join(" ", out); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9b72fa0..e62a05f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -3,13 +3,13 @@ "id": "animal-rp", "version": "${version}", "name": "Animal RP", - "description": "furry minecraft mod", + "description": "This is an example description! Tell everyone what your mod is about!", "authors": [ - "sophie" + "Me!" ], "contact": { - "homepage": "https://sad.ovh", - "sources": "https://git.sad.ovh/sophie/animalrpfabric" + "homepage": "https://fabricmc.net/", + "sources": "https://github.com/FabricMC/fabric-example-mod" }, "license": "CC0-1.0", "icon": "assets/animal-rp/icon.png", @@ -24,7 +24,7 @@ ], "depends": { "fabricloader": ">=0.16.4", - "minecraft": "~1.21.4", + "minecraft": "~1.21.1", "java": ">=21", "fabric-api": "*" },