From 2d19c7719929ac7510e8537ec6f491e10f5ac0de Mon Sep 17 00:00:00 2001 From: sophie Date: Fri, 13 Sep 2024 19:44:19 +0300 Subject: [PATCH 01/11] no emotes --- src/main/java/ovh/sad/animalrp/AnimalRP.java | 5 - .../sad/animalrp/commands/EmoteCommand.java | 65 ------- .../java/ovh/sad/animalrp/util/Emote.java | 162 ------------------ 3 files changed, 232 deletions(-) delete mode 100644 src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java delete mode 100644 src/main/java/ovh/sad/animalrp/util/Emote.java diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index 2659bc9..7992ed5 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -8,11 +8,9 @@ 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.EmoteCommand; import ovh.sad.animalrp.commands.InteractionCommand; import ovh.sad.animalrp.commands.NoChatCommand; import ovh.sad.animalrp.commands.TfCommand; -import ovh.sad.animalrp.util.Emote; import ovh.sad.animalrp.util.Mood; import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderHandler; @@ -35,7 +33,6 @@ public class AnimalRP implements ModInitializer { public static HashMap users = new HashMap<>(); public static HashMap noChat = new HashMap<>(); public static HashMap animals = new HashMap<>(); - public static Emote emotes; public static final String MOD_ID = "animal-rp"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); @@ -45,7 +42,6 @@ public class AnimalRP implements ModInitializer { animals.put("dog", new Dog()); animals.put("fox", new Fox()); animals.put("bee", new Bee()); - emotes = new Emote(); Placeholders.register(Identifier.of("animalrp", "animalcolor"), new PlaceholderHandler() { @Override @@ -62,7 +58,6 @@ public class AnimalRP implements ModInitializer { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { (new TfCommand()).Command(dispatcher, registryAccess, environment); (new NoChatCommand()).Command(dispatcher, registryAccess, environment); - (new EmoteCommand()).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); diff --git a/src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java b/src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java deleted file mode 100644 index 63f15fc..0000000 --- a/src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -package ovh.sad.animalrp.commands; - -import java.util.stream.Collectors; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.StringArgumentType; - -import eu.pb4.placeholders.api.TextParserUtils; -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.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; -import ovh.sad.animalrp.AnimalRP; -import ovh.sad.animalrp.util.Emote; -import ovh.sad.animalrp.util.Emote.Emotes; - -public class EmoteCommand { - public void Command(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, - CommandManager.RegistrationEnvironment environment) { - dispatcher.register(CommandManager.literal("emote") - .then(CommandManager.argument("emote", StringArgumentType.string()) - .executes((context) -> { - Entity sender = context.getSource().getEntity(); - final String arg = StringArgumentType.getString(context, "emote"); - - if (!(sender instanceof ServerPlayerEntity)) { - context.getSource().sendFeedback( - () -> Text.literal("I'm sorry console.").withColor(8421504), false); - return 0; - } - - ServerPlayerEntity player = context.getSource().getPlayer(); - - Emote.Emotes emote; - - try { - emote = Emotes.valueOf(arg.toUpperCase()); - } catch(Exception e) { - emote = null; - } - - if(emote == null) { - this.options(context.getSource()); - return 0; - } - - if(AnimalRP.emotes.isPlayerEmoting(player.getUuid())) { - context.getSource().sendFeedback(() -> Text.literal("Stopped emoting.").withColor(8421504), false); - AnimalRP.emotes.stopEmote(player.getUuid()); - } else { - context.getSource().sendFeedback(() -> Text.literal("Emoting!").withColor(65280), false); - AnimalRP.emotes.playEmote(player.getUuid(), context.getSource().getPlayer(), emote); - } - return 1; - }))); - } - - @SuppressWarnings("deprecation") - private void options(ServerCommandSource player) { - player.sendFeedback(() -> TextParserUtils.formatText("You have " + String.join(", ", Emote.emotes.keySet().stream().map(Emote.Emotes::name).map(String::toLowerCase).collect(Collectors.toSet())) + " as options."), false); - } - -} \ No newline at end of file diff --git a/src/main/java/ovh/sad/animalrp/util/Emote.java b/src/main/java/ovh/sad/animalrp/util/Emote.java deleted file mode 100644 index 1b109bd..0000000 --- a/src/main/java/ovh/sad/animalrp/util/Emote.java +++ /dev/null @@ -1,162 +0,0 @@ -package ovh.sad.animalrp.util; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import net.minecraft.particle.DustParticleEffect; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.math.Vec3d; -import ovh.sad.animalrp.AnimalRP; - -public class Emote { - class PlayerEmote { - ServerPlayerEntity entity; - Emotes emote; - - PlayerEmote( ServerPlayerEntity entity, - Emotes emote) { - this.entity = entity; - this.emote = emote; - } - } - - public enum Emotes { - HAPPY, UWU, RAWR, LOVE, RAWR2, HAPPY2 - } - - public static HashMap emotes = new HashMap(); - private HashMap players = new HashMap(); - { - emotes.put(Emotes.HAPPY, new String[] { // Emote by PotionOfHarming! - "0010000000100", - "0101000001010", - "0000000000000", - "0000011100000" - }); - emotes.put(Emotes.UWU, new String[] { - "0101000001010", - "0010000000100", - "0000000000000", - "0000011100000" - }); - - emotes.put(Emotes.RAWR, new String[] { - "0000100", - "0100010", - "0000100", - "0100010", - "0000100", - }); - emotes.put(Emotes.RAWR2, new String[] { - "001000000010", - "010100000101", - "001000000010", - "000010101000", - "000001010000", - }); - emotes.put(Emotes.LOVE, new String[] { - "0001001000", - "0010000100", - "0100001000", - "0010000100", - "0001001000", - }); - emotes.put(Emotes.HAPPY2, new String[] { - "010011100", - "000010010", - "000010010", - "010011100" - }); - } - - public Emote() { - AnimalRP.executor.scheduleWithFixedDelay(new Runnable() { - @Override - public void run() { - Set> playerset = players.entrySet(); - - for (Iterator> iterator = playerset.iterator(); iterator.hasNext();) { - Entry value = iterator.next(); - if (value.getValue().entity.isDisconnected()) { - iterator.remove(); - } else { - drawEmote(value.getValue().entity, value.getValue().emote); - } - } - } - }, 0, 250, TimeUnit.MILLISECONDS); - } - - public void drawEmote(ServerPlayerEntity player, Emotes emote) { - List locs = getEmoteLocs(player.getPos().subtract(0, player.isSneaking() ? .5 : 0, 0), - emotes.get(emote), player.getRotationVector()); - for (Vec3d loc : locs) { - for(int i =0; i < 15; i ++) { - player.getWorld().addParticle(new DustParticleEffect(Vec3d.unpackRgb(16777215).toVector3f(), 0.5f), loc.x, - loc.y, loc.z, 0, 0, 0); - } - } - } - - public static List getEmoteLocs(Vec3d loc, String[] ttEmote, Vec3d rotationLoc) { - List> locations = new ArrayList<>(); - int y = 0; - int distance = 10; - for (String s : ttEmote) { - List emoteTextLine = textToEmote(s); - List addLocs = new ArrayList<>(); - for (int x = 0; x < emoteTextLine.size(); x++) { - float y2 = (float) y / ((float) distance / 2); - float side = (((float) emoteTextLine.get(x) / distance) - ((float) ttEmote[0].length()) / 2 / distance); - Vec3d idfk = rotationLoc.normalize(); - Vec3d rotation = new Vec3d(idfk.x, 0, idfk.y); - Vec3d rot = rotation.crossProduct(new Vec3d(0, side, 0)); - Vec3d addLoc = loc.add(rot); - Vec3d newAloc = new Vec3d(addLoc.x, loc.getY() + ((float) ttEmote.length / distance - y2 + 2.25), - addLoc.y); - addLocs.add(newAloc); - } - locations.add(addLocs); - y++; - } - - List locs = new ArrayList<>(); - - for (List listLocs : locations) { - locs.addAll(listLocs); - } - - return locs; - } - - private static List textToEmote(String textToEmote) { - List locs = new ArrayList<>(); - for (int i = 0; i < textToEmote.length(); i++) { - char l = textToEmote.charAt(i); - String letter = String.valueOf(l); - if (letter.equals("1")) { - locs.add(i); - } - } - return locs; - } - - public void playEmote(UUID uuid, ServerPlayerEntity entity, Emotes emote) { - this.players.put(uuid, new PlayerEmote(entity, emote)); - - } - - public void stopEmote(UUID uuid) { - this.players.remove(uuid); - } - - public boolean isPlayerEmoting(UUID uuid) { - return this.players.containsKey(uuid); - } -} \ No newline at end of file From 2f5084010a95d876867ceb480e030a2117a0a3e9 Mon Sep 17 00:00:00 2001 From: sophie Date: Fri, 13 Sep 2024 20:58:26 +0300 Subject: [PATCH 02/11] simple-ish database + more improvements --- src/main/java/ovh/sad/animalrp/AnimalRP.java | 8 +++ .../java/ovh/sad/animalrp/animals/Animal.java | 4 ++ .../sad/animalrp/commands/NoChatCommand.java | 2 + .../ovh/sad/animalrp/commands/TfCommand.java | 2 + .../java/ovh/sad/animalrp/util/Emote.java | 1 - .../ovh/sad/animalrp/util/HashmapStore.java | 65 +++++++++++++++++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ovh/sad/animalrp/util/HashmapStore.java diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index 2659bc9..d216945 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -13,6 +13,7 @@ import ovh.sad.animalrp.commands.InteractionCommand; import ovh.sad.animalrp.commands.NoChatCommand; import ovh.sad.animalrp.commands.TfCommand; import ovh.sad.animalrp.util.Emote; +import ovh.sad.animalrp.util.HashmapStore; import ovh.sad.animalrp.util.Mood; import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderHandler; @@ -45,6 +46,13 @@ public class AnimalRP implements ModInitializer { animals.put("dog", new Dog()); animals.put("fox", new Fox()); animals.put("bee", new Bee()); + + 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)); + }); emotes = new Emote(); Placeholders.register(Identifier.of("animalrp", "animalcolor"), new PlaceholderHandler() { diff --git a/src/main/java/ovh/sad/animalrp/animals/Animal.java b/src/main/java/ovh/sad/animalrp/animals/Animal.java index 7ee5cfc..b796ba4 100644 --- a/src/main/java/ovh/sad/animalrp/animals/Animal.java +++ b/src/main/java/ovh/sad/animalrp/animals/Animal.java @@ -14,6 +14,10 @@ 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/commands/NoChatCommand.java b/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java index fc1050d..5f74283 100644 --- a/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java @@ -9,6 +9,7 @@ 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, @@ -25,6 +26,7 @@ public class NoChatCommand { 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 3a6222e..981b7f0 100644 --- a/src/main/java/ovh/sad/animalrp/commands/TfCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/TfCommand.java @@ -14,6 +14,7 @@ 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, @@ -54,6 +55,7 @@ public class TfCommand { Integer.parseInt(animal.color.substring(1), 16))), false); + HashmapStore.save("users.json", AnimalRP.users); return 1; }))); } diff --git a/src/main/java/ovh/sad/animalrp/util/Emote.java b/src/main/java/ovh/sad/animalrp/util/Emote.java index 1b109bd..2c227be 100644 --- a/src/main/java/ovh/sad/animalrp/util/Emote.java +++ b/src/main/java/ovh/sad/animalrp/util/Emote.java @@ -149,7 +149,6 @@ public class Emote { public void playEmote(UUID uuid, ServerPlayerEntity entity, Emotes emote) { this.players.put(uuid, new PlayerEmote(entity, emote)); - } public void stopEmote(UUID uuid) { diff --git a/src/main/java/ovh/sad/animalrp/util/HashmapStore.java b/src/main/java/ovh/sad/animalrp/util/HashmapStore.java new file mode 100644 index 0000000..725134f --- /dev/null +++ b/src/main/java/ovh/sad/animalrp/util/HashmapStore.java @@ -0,0 +1,65 @@ +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(); + } + } +} From aa200b17c08caa4aba410bc7bc1b39c1ef268415 Mon Sep 17 00:00:00 2001 From: sophie Date: Fri, 13 Sep 2024 21:10:03 +0300 Subject: [PATCH 03/11] Formatting --- src/main/java/ovh/sad/animalrp/AnimalRP.java | 33 ++++++++++++------- .../sad/animalrp/commands/EmoteCommand.java | 30 +++++++++++------ .../animalrp/commands/InteractionCommand.java | 15 ++++++--- .../sad/animalrp/commands/NoChatCommand.java | 14 +++++--- .../sad/animalrp/mixin/DecoratedMessage.java | 7 ++-- .../ovh/sad/animalrp/mixin/FoodEating.java | 12 +++---- .../java/ovh/sad/animalrp/mixin/Sneaking.java | 6 ++-- .../java/ovh/sad/animalrp/util/Cooldown.java | 2 +- .../java/ovh/sad/animalrp/util/Emote.java | 11 ++++--- src/main/java/ovh/sad/animalrp/util/Mood.java | 2 +- .../ovh/sad/animalrp/util/TextDestroyer.java | 16 +++++---- 11 files changed, 91 insertions(+), 57 deletions(-) diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index d216945..faeb464 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -29,7 +29,6 @@ import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class AnimalRP implements ModInitializer { public static ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); @@ -40,6 +39,7 @@ public class AnimalRP implements ModInitializer { public static final String MOD_ID = "animal-rp"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + @Override public void onInitialize() { animals.put("cat", new Cat()); @@ -47,10 +47,10 @@ public class AnimalRP implements ModInitializer { animals.put("fox", new Fox()); animals.put("bee", new Bee()); - HashmapStore.get("users.json").forEach((k,v) -> { + HashmapStore.get("users.json").forEach((k, v) -> { users.put(UUID.fromString(k), animals.get(v)); }); - HashmapStore.get("nochat.json").forEach((k,v) -> { + HashmapStore.get("nochat.json").forEach((k, v) -> { noChat.put(UUID.fromString(k), Boolean.valueOf(v)); }); emotes = new Emote(); @@ -61,23 +61,32 @@ public class AnimalRP implements ModInitializer { if (!ctx.hasPlayer()) return PlaceholderResult.invalid("No player!"); Animal animal = users.get(ctx.player().getUuid()); - if(animal == null) + if (animal == null) return PlaceholderResult.value(""); - return PlaceholderResult.value(""); + if (noChat.get(ctx.player().getUuid()) != null) + return PlaceholderResult.value(""); + return PlaceholderResult.value(""); } }); - + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { (new TfCommand()).Command(dispatcher, registryAccess, environment); (new NoChatCommand()).Command(dispatcher, registryAccess, environment); (new EmoteCommand()).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("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/commands/EmoteCommand.java b/src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java index 63f15fc..199daca 100644 --- a/src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java @@ -32,25 +32,27 @@ public class EmoteCommand { } ServerPlayerEntity player = context.getSource().getPlayer(); - + Emote.Emotes emote; - + try { emote = Emotes.valueOf(arg.toUpperCase()); - } catch(Exception e) { + } catch (Exception e) { emote = null; } - if(emote == null) { + if (emote == null) { this.options(context.getSource()); return 0; } - - if(AnimalRP.emotes.isPlayerEmoting(player.getUuid())) { - context.getSource().sendFeedback(() -> Text.literal("Stopped emoting.").withColor(8421504), false); + + if (AnimalRP.emotes.isPlayerEmoting(player.getUuid())) { + context.getSource().sendFeedback( + () -> Text.literal("Stopped emoting.").withColor(8421504), false); AnimalRP.emotes.stopEmote(player.getUuid()); } else { - context.getSource().sendFeedback(() -> Text.literal("Emoting!").withColor(65280), false); + context.getSource().sendFeedback(() -> Text.literal("Emoting!").withColor(65280), + false); AnimalRP.emotes.playEmote(player.getUuid(), context.getSource().getPlayer(), emote); } return 1; @@ -59,7 +61,15 @@ public class EmoteCommand { @SuppressWarnings("deprecation") private void options(ServerCommandSource player) { - player.sendFeedback(() -> TextParserUtils.formatText("You have " + String.join(", ", Emote.emotes.keySet().stream().map(Emote.Emotes::name).map(String::toLowerCase).collect(Collectors.toSet())) + " as options."), false); + player.sendFeedback( + () -> TextParserUtils + .formatText( + "You have " + + String.join(", ", + Emote.emotes.keySet().stream().map(Emote.Emotes::name) + .map(String::toLowerCase).collect(Collectors.toSet())) + + " as options."), + false); } - + } \ 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 8eeff06..cb7443f 100644 --- a/src/main/java/ovh/sad/animalrp/commands/InteractionCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/InteractionCommand.java @@ -48,7 +48,9 @@ public class InteractionCommand { if (aplayer == null) { context.getSource().sendFeedback( - () -> Text.literal("Only animals can interact with other animals :(").withColor(8421504), false); + () -> Text.literal("Only animals can interact with other animals :(") + .withColor(8421504), + false); return 0; } @@ -56,14 +58,18 @@ public class InteractionCommand { if (splayer.getName() == player.getName()) { context.getSource().sendFeedback( - () -> Text.literal("You can't " + this.command + " yourself.").withColor(8421504), 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( - () -> Text.literal(splayer.getName() + " is not an animal! :(").withColor(8421504), false); + () -> Text.literal(splayer.getName() + " is not an animal! :(") + .withColor(8421504), + false); return 0; } @@ -75,7 +81,8 @@ public class InteractionCommand { String.format(this.toYou, "" + 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 5f74283..e392c09 100644 --- a/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java @@ -18,15 +18,19 @@ public class NoChatCommand { UUID userUuid = context.getSource().getEntity().getUuid(); 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); + 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(() -> Text.literal("AnimalRP's chat modifications are now disabled for you.").withColor(16711680), 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); + HashmapStore.save("nochat.json", AnimalRP.noChat); return 0; })); diff --git a/src/main/java/ovh/sad/animalrp/mixin/DecoratedMessage.java b/src/main/java/ovh/sad/animalrp/mixin/DecoratedMessage.java index 2650ea0..c7dc504 100644 --- a/src/main/java/ovh/sad/animalrp/mixin/DecoratedMessage.java +++ b/src/main/java/ovh/sad/animalrp/mixin/DecoratedMessage.java @@ -27,8 +27,9 @@ 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; @@ -36,7 +37,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 3b76714..a506d1f 100644 --- a/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java +++ b/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java @@ -18,18 +18,18 @@ import ovh.sad.animalrp.animals.Animal; import ovh.sad.animalrp.animals.Bee; @Mixin(value = LivingEntity.class) -public class FoodEating { +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)) { + if (entity.getType().equals(EntityType.PLAYER)) { ServerPlayerEntity player = (ServerPlayerEntity) entity; - Animal animal = AnimalRP.users.get(player.getUuid()); + Animal animal = AnimalRP.users.get(player.getUuid()); - if (animal != null) { - if(animal.name == "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 b0ed500..bb290a0 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 index a92c524..dc5f12a 100644 --- a/src/main/java/ovh/sad/animalrp/util/Cooldown.java +++ b/src/main/java/ovh/sad/animalrp/util/Cooldown.java @@ -10,7 +10,7 @@ public class Cooldown { public long getTime() { return this.timeCreated - (System.currentTimeMillis() - this.length); } - + public boolean isExpired() { return this.getTime() <= 0; } diff --git a/src/main/java/ovh/sad/animalrp/util/Emote.java b/src/main/java/ovh/sad/animalrp/util/Emote.java index 2c227be..a69bfd5 100644 --- a/src/main/java/ovh/sad/animalrp/util/Emote.java +++ b/src/main/java/ovh/sad/animalrp/util/Emote.java @@ -19,8 +19,8 @@ public class Emote { ServerPlayerEntity entity; Emotes emote; - PlayerEmote( ServerPlayerEntity entity, - Emotes emote) { + PlayerEmote(ServerPlayerEntity entity, + Emotes emote) { this.entity = entity; this.emote = emote; } @@ -97,9 +97,10 @@ public class Emote { List locs = getEmoteLocs(player.getPos().subtract(0, player.isSneaking() ? .5 : 0, 0), emotes.get(emote), player.getRotationVector()); for (Vec3d loc : locs) { - for(int i =0; i < 15; i ++) { - player.getWorld().addParticle(new DustParticleEffect(Vec3d.unpackRgb(16777215).toVector3f(), 0.5f), loc.x, - loc.y, loc.z, 0, 0, 0); + for (int i = 0; i < 15; i++) { + player.getWorld().addParticle(new DustParticleEffect(Vec3d.unpackRgb(16777215).toVector3f(), 0.5f), + loc.x, + loc.y, loc.z, 0, 0, 0); } } } diff --git a/src/main/java/ovh/sad/animalrp/util/Mood.java b/src/main/java/ovh/sad/animalrp/util/Mood.java index f6db956..5e78720 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 da08032..b6cbdea 100644 --- a/src/main/java/ovh/sad/animalrp/util/TextDestroyer.java +++ b/src/main/java/ovh/sad/animalrp/util/TextDestroyer.java @@ -20,23 +20,25 @@ 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); From 6898039c610aa661c60540288cc21bf83635a4cf Mon Sep 17 00:00:00 2001 From: sophie Date: Fri, 13 Sep 2024 21:31:42 +0300 Subject: [PATCH 04/11] better idea --- src/main/java/ovh/sad/animalrp/AnimalRP.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index faeb464..bfee332 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -65,7 +65,7 @@ public class AnimalRP implements ModInitializer { return PlaceholderResult.value(""); if (noChat.get(ctx.player().getUuid()) != null) return PlaceholderResult.value(""); - return PlaceholderResult.value(""); + return PlaceholderResult.value(""+arg+""); } }); From d12c3e57697c011412608b0caab8c064586100ab Mon Sep 17 00:00:00 2001 From: sophie Date: Fri, 13 Sep 2024 21:43:52 +0300 Subject: [PATCH 05/11] Ok --- src/main/java/ovh/sad/animalrp/AnimalRP.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index bfee332..7c68590 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -65,10 +65,10 @@ public class AnimalRP implements ModInitializer { return PlaceholderResult.value(""); if (noChat.get(ctx.player().getUuid()) != null) return PlaceholderResult.value(""); - return PlaceholderResult.value(""+arg+""); + return PlaceholderResult.value(animal.color); } }); - + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { (new TfCommand()).Command(dispatcher, registryAccess, environment); (new NoChatCommand()).Command(dispatcher, registryAccess, environment); From 4c09e501b4281c12af0e710956b75c3566b88f8f Mon Sep 17 00:00:00 2001 From: sophie Date: Thu, 19 Sep 2024 02:56:19 +0300 Subject: [PATCH 06/11] updateesss --- src/main/java/ovh/sad/animalrp/AnimalRP.java | 10 ++++++++++ src/main/java/ovh/sad/animalrp/commands/TfCommand.java | 2 -- src/main/java/ovh/sad/animalrp/util/Emote.java | 9 +++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index 7c68590..26bb806 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -42,6 +42,16 @@ public class AnimalRP implements ModInitializer { @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"); animals.put("cat", new Cat()); animals.put("dog", new Dog()); animals.put("fox", new Fox()); diff --git a/src/main/java/ovh/sad/animalrp/commands/TfCommand.java b/src/main/java/ovh/sad/animalrp/commands/TfCommand.java index 981b7f0..0a80723 100644 --- a/src/main/java/ovh/sad/animalrp/commands/TfCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/TfCommand.java @@ -24,8 +24,6 @@ public class TfCommand { .executes(context -> { 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); diff --git a/src/main/java/ovh/sad/animalrp/util/Emote.java b/src/main/java/ovh/sad/animalrp/util/Emote.java index a69bfd5..511bcf2 100644 --- a/src/main/java/ovh/sad/animalrp/util/Emote.java +++ b/src/main/java/ovh/sad/animalrp/util/Emote.java @@ -97,11 +97,8 @@ public class Emote { List locs = getEmoteLocs(player.getPos().subtract(0, player.isSneaking() ? .5 : 0, 0), emotes.get(emote), player.getRotationVector()); for (Vec3d loc : locs) { - for (int i = 0; i < 15; i++) { - player.getWorld().addParticle(new DustParticleEffect(Vec3d.unpackRgb(16777215).toVector3f(), 0.5f), - loc.x, - loc.y, loc.z, 0, 0, 0); - } + player.getServerWorld().spawnParticles(new DustParticleEffect(Vec3d.unpackRgb(16777215).toVector3f(), 0.5f), + loc.x, loc.y, loc.z, 15, 0, 0, 0, 0); } } @@ -116,7 +113,7 @@ public class Emote { float y2 = (float) y / ((float) distance / 2); float side = (((float) emoteTextLine.get(x) / distance) - ((float) ttEmote[0].length()) / 2 / distance); Vec3d idfk = rotationLoc.normalize(); - Vec3d rotation = new Vec3d(idfk.x, 0, idfk.y); + Vec3d rotation = new Vec3d(idfk.x, 0, idfk.z); Vec3d rot = rotation.crossProduct(new Vec3d(0, side, 0)); Vec3d addLoc = loc.add(rot); Vec3d newAloc = new Vec3d(addLoc.x, loc.getY() + ((float) ttEmote.length / distance - y2 + 2.25), From 42daa7c8cd9b74eb15cef99283d7ab9275d72cad Mon Sep 17 00:00:00 2001 From: sophie Date: Sun, 10 Nov 2024 17:05:06 +0200 Subject: [PATCH 07/11] stop threadexecutor on server shutdown --- src/main/java/ovh/sad/animalrp/AnimalRP.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index 26bb806..df03a8e 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -2,6 +2,7 @@ package ovh.sad.animalrp; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.util.Identifier; import ovh.sad.animalrp.animals.Animal; import ovh.sad.animalrp.animals.Cat; @@ -98,5 +99,9 @@ ZZZzz /,`.-'`' -. ;-;;,_ (new InteractionCommand("cuddle", Mood.CUTE, "%s cuddles with you. %s", "You and %s start cuddling. How cute! %s")).Command(dispatcher, registryAccess, environment); }); + + ServerLifecycleEvents.SERVER_STOPPING.register((server) -> { + executor.shutdownNow(); + }); } } \ No newline at end of file From 4d0b5434eee45ac8f3fa564ea90f9f430cf98803 Mon Sep 17 00:00:00 2001 From: sophie Date: Sun, 5 Jan 2025 02:03:29 +0200 Subject: [PATCH 08/11] (unfinished) feat: remove emote crap, add commands, update to 1.21.4, fix /tf off bug --- build.gradle | 2 +- gradle.properties | 10 +- src/main/java/ovh/sad/animalrp/AnimalRP.java | 10 +- .../java/ovh/sad/animalrp/animals/Bee.java | 25 ++- .../java/ovh/sad/animalrp/animals/Fox.java | 7 +- .../sad/animalrp/commands/EmoteCommand.java | 75 --------- .../ovh/sad/animalrp/commands/TfCommand.java | 1 + .../java/ovh/sad/animalrp/util/Emote.java | 159 ------------------ src/main/resources/fabric.mod.json | 10 +- 9 files changed, 37 insertions(+), 262 deletions(-) delete mode 100644 src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java delete mode 100644 src/main/java/ovh/sad/animalrp/util/Emote.java diff --git a/build.gradle b/build.gradle index 3f79d18..97c78e9 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.4.1+1.21") + modImplementation include("eu.pb4:placeholder-api:2.5.1+1.21.3") // 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 38ca5f0..a6eb3db 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.1 -yarn_mappings=1.21.1+build.3 -loader_version=0.16.4 +minecraft_version=1.21.4 +yarn_mappings=1.21.4+build.7 +loader_version=0.16.9 # Mod Properties -mod_version=1.0.0 +mod_version=2.0.0 maven_group=ovh.sad.animalrp archives_base_name=animal-rp # Dependencies -fabric_version=0.103.0+1.21.1 +fabric_version=0.114.0+1.21.4 diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index df03a8e..813bda3 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -9,11 +9,9 @@ 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.EmoteCommand; import ovh.sad.animalrp.commands.InteractionCommand; import ovh.sad.animalrp.commands.NoChatCommand; import ovh.sad.animalrp.commands.TfCommand; -import ovh.sad.animalrp.util.Emote; import ovh.sad.animalrp.util.HashmapStore; import ovh.sad.animalrp.util.Mood; import eu.pb4.placeholders.api.PlaceholderContext; @@ -36,7 +34,6 @@ public class AnimalRP implements ModInitializer { public static HashMap users = new HashMap<>(); public static HashMap noChat = new HashMap<>(); public static HashMap animals = new HashMap<>(); - public static Emote emotes; public static final String MOD_ID = "animal-rp"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); @@ -64,7 +61,6 @@ ZZZzz /,`.-'`' -. ;-;;,_ HashmapStore.get("nochat.json").forEach((k, v) -> { noChat.put(UUID.fromString(k), Boolean.valueOf(v)); }); - emotes = new Emote(); Placeholders.register(Identifier.of("animalrp", "animalcolor"), new PlaceholderHandler() { @Override @@ -83,7 +79,6 @@ ZZZzz /,`.-'`' -. ;-;;,_ CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { (new TfCommand()).Command(dispatcher, registryAccess, environment); (new NoChatCommand()).Command(dispatcher, registryAccess, environment); - (new EmoteCommand()).Command(dispatcher, registryAccess, environment); (new InteractionCommand("headpats", Mood.HAPPY, "%s petted you! %s", "You petted %s! %s")) .Command(dispatcher, registryAccess, environment); @@ -98,8 +93,11 @@ ZZZzz /,`.-'`' -. ;-;;,_ "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(); }); diff --git a/src/main/java/ovh/sad/animalrp/animals/Bee.java b/src/main/java/ovh/sad/animalrp/animals/Bee.java index ea08109..20b919b 100644 --- a/src/main/java/ovh/sad/animalrp/animals/Bee.java +++ b/src/main/java/ovh/sad/animalrp/animals/Bee.java @@ -11,17 +11,21 @@ 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 net.minecraft.util.TypedActionResult; import ovh.sad.animalrp.AnimalRP; import ovh.sad.animalrp.util.Mood; import ovh.sad.animalrp.util.TextDestroyer; @@ -76,10 +80,10 @@ public class Bee extends Animal { ItemStack item = player.getStackInHand(hand); if (item == null) // air interact - return TypedActionResult.pass(item); + return ActionResult.PASS; if (!allFlowers.contains(item.getItem())) { // not a flower - return TypedActionResult.pass(item); + return ActionResult.PASS; } Boolean incorrect = false; @@ -96,25 +100,30 @@ public class Bee extends Animal { if (Bee.isItemARP(item)) { item.remove(DataComponentTypes.FOOD); - return TypedActionResult.pass(item); + return ActionResult.PASS; } - return TypedActionResult.pass(item); + return ActionResult.PASS; } if (Bee.isItemARP(item)) { // correct animal, but foodkey already set - return TypedActionResult.pass(item); + return ActionResult.PASS; } + 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() + .consumeEffect(new ApplyEffectsConsumeEffect(new StatusEffectInstance(StatusEffects.SPEED, 20 * 4, 1, true, true, true))) + .build(); item.set(DataComponentTypes.FOOD, food); + item.set(DataComponentTypes.CONSUMABLE, consumable); - return TypedActionResult.pass(item); + return ActionResult.PASS; }); } diff --git a/src/main/java/ovh/sad/animalrp/animals/Fox.java b/src/main/java/ovh/sad/animalrp/animals/Fox.java index bbe79bd..5d45e41 100644 --- a/src/main/java/ovh/sad/animalrp/animals/Fox.java +++ b/src/main/java/ovh/sad/animalrp/animals/Fox.java @@ -3,10 +3,11 @@ package ovh.sad.animalrp.animals; import java.util.Random; import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; -import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; 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; @@ -44,7 +45,7 @@ public class Fox extends Animal { if(!(source.getSource() instanceof ServerPlayerEntity)) return; if(entity instanceof PlayerEntity) return; - Entity victim = entity; + LivingEntity victim = entity; ServerPlayerEntity damager = (ServerPlayerEntity) source.getSource(); Animal animal = AnimalRP.users.get(damager.getUuid()); @@ -53,7 +54,7 @@ public class Fox extends Animal { return; } - victim.damage(victim.getDamageSources().playerAttack(damager), dmg * 0.25F); + victim.damage((ServerWorld)victim.getWorld(), victim.getDamageSources().playerAttack(damager), dmg * 0.25F); }); } diff --git a/src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java b/src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java deleted file mode 100644 index 199daca..0000000 --- a/src/main/java/ovh/sad/animalrp/commands/EmoteCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -package ovh.sad.animalrp.commands; - -import java.util.stream.Collectors; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.StringArgumentType; - -import eu.pb4.placeholders.api.TextParserUtils; -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.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; -import ovh.sad.animalrp.AnimalRP; -import ovh.sad.animalrp.util.Emote; -import ovh.sad.animalrp.util.Emote.Emotes; - -public class EmoteCommand { - public void Command(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, - CommandManager.RegistrationEnvironment environment) { - dispatcher.register(CommandManager.literal("emote") - .then(CommandManager.argument("emote", StringArgumentType.string()) - .executes((context) -> { - Entity sender = context.getSource().getEntity(); - final String arg = StringArgumentType.getString(context, "emote"); - - if (!(sender instanceof ServerPlayerEntity)) { - context.getSource().sendFeedback( - () -> Text.literal("I'm sorry console.").withColor(8421504), false); - return 0; - } - - ServerPlayerEntity player = context.getSource().getPlayer(); - - Emote.Emotes emote; - - try { - emote = Emotes.valueOf(arg.toUpperCase()); - } catch (Exception e) { - emote = null; - } - - if (emote == null) { - this.options(context.getSource()); - return 0; - } - - if (AnimalRP.emotes.isPlayerEmoting(player.getUuid())) { - context.getSource().sendFeedback( - () -> Text.literal("Stopped emoting.").withColor(8421504), false); - AnimalRP.emotes.stopEmote(player.getUuid()); - } else { - context.getSource().sendFeedback(() -> Text.literal("Emoting!").withColor(65280), - false); - AnimalRP.emotes.playEmote(player.getUuid(), context.getSource().getPlayer(), emote); - } - return 1; - }))); - } - - @SuppressWarnings("deprecation") - private void options(ServerCommandSource player) { - player.sendFeedback( - () -> TextParserUtils - .formatText( - "You have " - + String.join(", ", - Emote.emotes.keySet().stream().map(Emote.Emotes::name) - .map(String::toLowerCase).collect(Collectors.toSet())) - + " as options."), - false); - } - -} \ No newline at end of file diff --git a/src/main/java/ovh/sad/animalrp/commands/TfCommand.java b/src/main/java/ovh/sad/animalrp/commands/TfCommand.java index 0a80723..a82cb99 100644 --- a/src/main/java/ovh/sad/animalrp/commands/TfCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/TfCommand.java @@ -36,6 +36,7 @@ public class TfCommand { AnimalRP.users.remove(entity.getUuid()); context.getSource().sendFeedback( () -> Text.literal("You no longer have a animal set."), false); + HashmapStore.save("users.json", AnimalRP.users); return 0; } diff --git a/src/main/java/ovh/sad/animalrp/util/Emote.java b/src/main/java/ovh/sad/animalrp/util/Emote.java deleted file mode 100644 index 511bcf2..0000000 --- a/src/main/java/ovh/sad/animalrp/util/Emote.java +++ /dev/null @@ -1,159 +0,0 @@ -package ovh.sad.animalrp.util; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import net.minecraft.particle.DustParticleEffect; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.math.Vec3d; -import ovh.sad.animalrp.AnimalRP; - -public class Emote { - class PlayerEmote { - ServerPlayerEntity entity; - Emotes emote; - - PlayerEmote(ServerPlayerEntity entity, - Emotes emote) { - this.entity = entity; - this.emote = emote; - } - } - - public enum Emotes { - HAPPY, UWU, RAWR, LOVE, RAWR2, HAPPY2 - } - - public static HashMap emotes = new HashMap(); - private HashMap players = new HashMap(); - { - emotes.put(Emotes.HAPPY, new String[] { // Emote by PotionOfHarming! - "0010000000100", - "0101000001010", - "0000000000000", - "0000011100000" - }); - emotes.put(Emotes.UWU, new String[] { - "0101000001010", - "0010000000100", - "0000000000000", - "0000011100000" - }); - - emotes.put(Emotes.RAWR, new String[] { - "0000100", - "0100010", - "0000100", - "0100010", - "0000100", - }); - emotes.put(Emotes.RAWR2, new String[] { - "001000000010", - "010100000101", - "001000000010", - "000010101000", - "000001010000", - }); - emotes.put(Emotes.LOVE, new String[] { - "0001001000", - "0010000100", - "0100001000", - "0010000100", - "0001001000", - }); - emotes.put(Emotes.HAPPY2, new String[] { - "010011100", - "000010010", - "000010010", - "010011100" - }); - } - - public Emote() { - AnimalRP.executor.scheduleWithFixedDelay(new Runnable() { - @Override - public void run() { - Set> playerset = players.entrySet(); - - for (Iterator> iterator = playerset.iterator(); iterator.hasNext();) { - Entry value = iterator.next(); - if (value.getValue().entity.isDisconnected()) { - iterator.remove(); - } else { - drawEmote(value.getValue().entity, value.getValue().emote); - } - } - } - }, 0, 250, TimeUnit.MILLISECONDS); - } - - public void drawEmote(ServerPlayerEntity player, Emotes emote) { - List locs = getEmoteLocs(player.getPos().subtract(0, player.isSneaking() ? .5 : 0, 0), - emotes.get(emote), player.getRotationVector()); - for (Vec3d loc : locs) { - player.getServerWorld().spawnParticles(new DustParticleEffect(Vec3d.unpackRgb(16777215).toVector3f(), 0.5f), - loc.x, loc.y, loc.z, 15, 0, 0, 0, 0); - } - } - - public static List getEmoteLocs(Vec3d loc, String[] ttEmote, Vec3d rotationLoc) { - List> locations = new ArrayList<>(); - int y = 0; - int distance = 10; - for (String s : ttEmote) { - List emoteTextLine = textToEmote(s); - List addLocs = new ArrayList<>(); - for (int x = 0; x < emoteTextLine.size(); x++) { - float y2 = (float) y / ((float) distance / 2); - float side = (((float) emoteTextLine.get(x) / distance) - ((float) ttEmote[0].length()) / 2 / distance); - Vec3d idfk = rotationLoc.normalize(); - Vec3d rotation = new Vec3d(idfk.x, 0, idfk.z); - Vec3d rot = rotation.crossProduct(new Vec3d(0, side, 0)); - Vec3d addLoc = loc.add(rot); - Vec3d newAloc = new Vec3d(addLoc.x, loc.getY() + ((float) ttEmote.length / distance - y2 + 2.25), - addLoc.y); - addLocs.add(newAloc); - } - locations.add(addLocs); - y++; - } - - List locs = new ArrayList<>(); - - for (List listLocs : locations) { - locs.addAll(listLocs); - } - - return locs; - } - - private static List textToEmote(String textToEmote) { - List locs = new ArrayList<>(); - for (int i = 0; i < textToEmote.length(); i++) { - char l = textToEmote.charAt(i); - String letter = String.valueOf(l); - if (letter.equals("1")) { - locs.add(i); - } - } - return locs; - } - - public void playEmote(UUID uuid, ServerPlayerEntity entity, Emotes emote) { - this.players.put(uuid, new PlayerEmote(entity, emote)); - } - - public void stopEmote(UUID uuid) { - this.players.remove(uuid); - } - - public boolean isPlayerEmoting(UUID uuid) { - return this.players.containsKey(uuid); - } -} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e62a05f..9b72fa0 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": "This is an example description! Tell everyone what your mod is about!", + "description": "furry minecraft mod", "authors": [ - "Me!" + "sophie" ], "contact": { - "homepage": "https://fabricmc.net/", - "sources": "https://github.com/FabricMC/fabric-example-mod" + "homepage": "https://sad.ovh", + "sources": "https://git.sad.ovh/sophie/animalrpfabric" }, "license": "CC0-1.0", "icon": "assets/animal-rp/icon.png", @@ -24,7 +24,7 @@ ], "depends": { "fabricloader": ">=0.16.4", - "minecraft": "~1.21.1", + "minecraft": "~1.21.4", "java": ">=21", "fabric-api": "*" }, From d7df43bc080ada12752c9f414cd419bc7e9058b6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 13 Mar 2025 02:14:10 +0200 Subject: [PATCH 09/11] Add /rpinfo for info on the mod, remove cooldowns fully, add petting on rightclick, fix bee food and redo FoodEating mixin --- README.MD | 62 +++++++++++++++---- src/main/java/ovh/sad/animalrp/AnimalRP.java | 56 +++++++++++++++-- .../java/ovh/sad/animalrp/animals/Bee.java | 6 +- .../sad/animalrp/commands/InfoCommand.java | 34 ++++++++++ .../ovh/sad/animalrp/mixin/FoodEating.java | 14 +++-- .../java/ovh/sad/animalrp/util/Cooldown.java | 35 ----------- 6 files changed, 148 insertions(+), 59 deletions(-) create mode 100644 src/main/java/ovh/sad/animalrp/commands/InfoCommand.java delete mode 100644 src/main/java/ovh/sad/animalrp/util/Cooldown.java diff --git a/README.MD b/README.MD index 9dfaede..3e501b9 100644 --- a/README.MD +++ b/README.MD @@ -1,13 +1,53 @@ -# AnimalRP port to Fabric +# **AnimalRPs mod** -Order of importance: -TODO: +## **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.** -- [ ] Database -- [ ] Player leashing -- [No] Cooldowns -- [No] Emotes -- [x] Bee -- [x] Cat -- [x] Dog -- [x] Fox \ No newline at end of file +## **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. + +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 diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index 813bda3..cbac811 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -1,26 +1,35 @@ package ovh.sad.animalrp; +import eu.pb4.placeholders.api.*; 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.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; 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.InfoCommand; 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; @@ -38,6 +47,9 @@ 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; + @Override public void onInitialize() { @@ -79,6 +91,7 @@ ZZZzz /,`.-'`' -. ;-;;,_ 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); @@ -101,5 +114,40 @@ ZZZzz /,`.-'`' -. ;-;;,_ 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); + + + attackee.sendMessage(TextParserUtils.formatText( + String.format("%s petted you! %s", + "" + attacker.getName().getString() + "", + "" + attackerAnimal.catchphrase)), false); + attacker.sendMessage(TextParserUtils.formatText( + String.format("You petted %s! %s", + "" + attackee.getName().getString() + "", + "" + attackeeAnimal.catchphrase)), false); + attacker.getWorld().playSound(attackee, attackee.getBlockPos(), + attackeeAnimal.moodSounds.get(Mood.CUTE), SoundCategory.PLAYERS, 1F, + 1); + + System.out.println(attackee.getNameForScoreboard() + " was rightclicked by " + attacker.getNameForScoreboard()); + return ActionResult.PASS; + }); } } \ No newline at end of file diff --git a/src/main/java/ovh/sad/animalrp/animals/Bee.java b/src/main/java/ovh/sad/animalrp/animals/Bee.java index 20b919b..64c81b3 100644 --- a/src/main/java/ovh/sad/animalrp/animals/Bee.java +++ b/src/main/java/ovh/sad/animalrp/animals/Bee.java @@ -74,6 +74,9 @@ 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()); @@ -112,12 +115,9 @@ public class Bee extends Animal { FoodComponent food = new FoodComponent.Builder() .alwaysEdible() - .nutrition(4) - .saturationModifier(9.4f) .build(); ConsumableComponent consumable = ConsumableComponents.food() - .consumeEffect(new ApplyEffectsConsumeEffect(new StatusEffectInstance(StatusEffects.SPEED, 20 * 4, 1, true, true, true))) .build(); item.set(DataComponentTypes.FOOD, food); diff --git a/src/main/java/ovh/sad/animalrp/commands/InfoCommand.java b/src/main/java/ovh/sad/animalrp/commands/InfoCommand.java new file mode 100644 index 0000000..48949bd --- /dev/null +++ b/src/main/java/ovh/sad/animalrp/commands/InfoCommand.java @@ -0,0 +1,34 @@ +package ovh.sad.animalrp.commands; + +import java.util.UUID; + +import com.mojang.brigadier.CommandDispatcher; + +import eu.pb4.placeholders.api.TextParserUtils; +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.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(() -> TextParserUtils.formatText("AnimalRPs is a mod that adds animals to Minecraft."), false); + context.getSource().sendFeedback(() -> TextParserUtils.formatText("Usage of this mod is very simple."), false); + context.getSource().sendFeedback(() -> TextParserUtils.formatText("- To select a animal, use: /tf"), false); + context.getSource().sendFeedback(() -> TextParserUtils.formatText("- To turn off animals, use: /tf off"), false); + context.getSource().sendFeedback(() -> TextParserUtils.formatText("- Don't want the chat changes? Use: /disableanimalchat."), false); + context.getSource().sendFeedback(() -> Text.empty(), false); + context.getSource().sendFeedback(() -> TextParserUtils.formatText("- To see what the animals do, visit: https://git.sad.ovh/sophie/animalrpfabric"), false); + context.getSource().sendFeedback(() -> TextParserUtils.formatText("- To pet someone, rightclick on them (they must be a animal!)"), false); + context.getSource().sendFeedback(() -> Text.empty(), false); + context.getSource().sendFeedback(() -> TextParserUtils.formatText("Available animals: " + String.join(", ", AnimalRP.animals.keySet().stream().toList())), false); + + return 0; + })); + } + +} \ No newline at end of file diff --git a/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java b/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java index a506d1f..560cc8e 100644 --- a/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java +++ b/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java @@ -1,5 +1,6 @@ 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; @@ -17,13 +18,14 @@ import ovh.sad.animalrp.AnimalRP; import ovh.sad.animalrp.animals.Animal; import ovh.sad.animalrp.animals.Bee; -@Mixin(value = LivingEntity.class) +@Mixin(value = Item.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; + @Inject(method = "finishUsing", at = @At("HEAD")) + public void finishUsing(ItemStack stack, World world, LivingEntity user, CallbackInfoReturnable cfr) { + if(world.isClient()) return; + + if (user.getType().equals(EntityType.PLAYER)) { + ServerPlayerEntity player = (ServerPlayerEntity) user; Animal animal = AnimalRP.users.get(player.getUuid()); diff --git a/src/main/java/ovh/sad/animalrp/util/Cooldown.java b/src/main/java/ovh/sad/animalrp/util/Cooldown.java deleted file mode 100644 index dc5f12a..0000000 --- a/src/main/java/ovh/sad/animalrp/util/Cooldown.java +++ /dev/null @@ -1,35 +0,0 @@ -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 From 523477deb991d87a2caac0b1ddd48802b9752cfa Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 13 Mar 2025 16:36:46 +0200 Subject: [PATCH 10/11] New animal, code cleanup, replace deprecated SPF with QT. --- README.MD | 3 +- src/main/java/ovh/sad/animalrp/AnimalRP.java | 23 ++++--- .../java/ovh/sad/animalrp/animals/Bee.java | 21 ++++--- .../java/ovh/sad/animalrp/animals/Cow.java | 63 +++++++++++++++++++ .../java/ovh/sad/animalrp/animals/Dog.java | 2 +- .../java/ovh/sad/animalrp/animals/Fox.java | 7 +-- .../sad/animalrp/commands/InfoCommand.java | 23 +++---- .../animalrp/commands/InteractionCommand.java | 24 +++---- .../sad/animalrp/commands/NoChatCommand.java | 11 ++-- .../ovh/sad/animalrp/commands/TfCommand.java | 37 +++++------ .../ovh/sad/animalrp/mixin/FoodEating.java | 2 +- 11 files changed, 137 insertions(+), 79 deletions(-) create mode 100644 src/main/java/ovh/sad/animalrp/animals/Cow.java diff --git a/README.MD b/README.MD index 3e501b9..0f43b1a 100644 --- a/README.MD +++ b/README.MD @@ -9,7 +9,8 @@ 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.** ## **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. diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index cbac811..e6fe243 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -1,6 +1,9 @@ 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; @@ -12,13 +15,10 @@ import net.fabricmc.fabric.api.event.player.UseEntityCallback; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; 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.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.animals.*; import ovh.sad.animalrp.commands.InfoCommand; import ovh.sad.animalrp.commands.InteractionCommand; import ovh.sad.animalrp.commands.NoChatCommand; @@ -49,7 +49,11 @@ public class AnimalRP implements ModInitializer { 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() { @@ -61,11 +65,12 @@ ZZZzz /,`.-'`' -. ;-;;,_ """; LOGGER.info(catAscii); LOGGER.info("furry animal mod for fabric"); - LOGGER.info("by @fucksophie - est. Sept 2024"); + 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)); @@ -131,14 +136,14 @@ ZZZzz /,`.-'`' -. ;-;;,_ if (lastPetTimes.getOrDefault(attackerId, 0L) + COOLDOWN_MS > currentTime) { return ActionResult.PASS; } + lastPetTimes.put(attackerId, currentTime); - - attackee.sendMessage(TextParserUtils.formatText( + attackee.sendMessage(AnimalRP.parseText( String.format("%s petted you! %s", "" + attacker.getName().getString() + "", "" + attackerAnimal.catchphrase)), false); - attacker.sendMessage(TextParserUtils.formatText( + attacker.sendMessage(AnimalRP.parseText( String.format("You petted %s! %s", "" + attackee.getName().getString() + "", "" + attackeeAnimal.catchphrase)), false); diff --git a/src/main/java/ovh/sad/animalrp/animals/Bee.java b/src/main/java/ovh/sad/animalrp/animals/Bee.java index 64c81b3..4c52127 100644 --- a/src/main/java/ovh/sad/animalrp/animals/Bee.java +++ b/src/main/java/ovh/sad/animalrp/animals/Bee.java @@ -26,6 +26,7 @@ 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 ovh.sad.animalrp.AnimalRP; import ovh.sad.animalrp.util.Mood; import ovh.sad.animalrp.util.TextDestroyer; @@ -37,13 +38,13 @@ public class Bee extends Animal { } - private static Item[] _allFlowers = { Items.ALLIUM, Items.AZURE_BLUET, Items.BLUE_ORCHID, + private static final 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 List allFlowers = Arrays.asList(_allFlowers); - public static Identifier beeFoodKey = Identifier.of("animalrp", "bee_food"); - public static HashMap inARow = new HashMap(); + public static final List allFlowers = Arrays.asList(_allFlowers); + public static HashMap inARow = new HashMap<>(); + TextDestroyer destroyer = new TextDestroyer(new String[] { ">_<", "*buzz*", ";3", ":3", "εწз", " ≧◠◡◠≦ ", "*stings you*", "*humms*", @@ -63,7 +64,7 @@ public class Bee extends Animal { ArrayList sneakers = new ArrayList(); - public static Boolean isItemARP(ItemStack is) { + public static @NotNull Boolean isItemARP(ItemStack is) { return (allFlowers.contains(is.getItem()) && is.get(DataComponentTypes.FOOD) != null); } @@ -89,12 +90,12 @@ public class Bee extends Animal { return ActionResult.PASS; } - Boolean incorrect = false; + boolean incorrect = false; if (animal == null) { incorrect = true; } else { - if (animal.name != this.name) { + if (!animal.name.equals(this.name)) { incorrect = true; } } @@ -129,7 +130,7 @@ public class Bee extends Animal { // Called from the FoodEating mixin. // Called only if the player is a animal and a bee. - public void onEat(ServerPlayerEntity player, ItemStack item) { + public void onEat(ServerPlayerEntity player, @NotNull ItemStack item) { if (!allFlowers.contains(item.getItem())) { // not a flower return; } @@ -163,11 +164,11 @@ public class Bee extends Animal { } // Called from the 'Sneaking' mixin. - public void onSneak(ServerPlayerEntity player, boolean status) { + public void onSneak(@NotNull ServerPlayerEntity player, boolean status) { Animal animal = AnimalRP.users.get(player.getUuid()); if (animal == null) return; - if (animal.name != this.name) + if (!animal.name.equals(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 new file mode 100644 index 0000000..b92958e --- /dev/null +++ b/src/main/java/ovh/sad/animalrp/animals/Cow.java @@ -0,0 +1,63 @@ +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 dfd7eab..7e78e23 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 != this.name) + if (!animal.name.equals(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 5d45e41..c000626 100644 --- a/src/main/java/ovh/sad/animalrp/animals/Fox.java +++ b/src/main/java/ovh/sad/animalrp/animals/Fox.java @@ -42,19 +42,16 @@ 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)) return; + if(!(source.getSource() instanceof ServerPlayerEntity damager)) return; if(entity instanceof PlayerEntity) return; - LivingEntity victim = entity; - ServerPlayerEntity damager = (ServerPlayerEntity) source.getSource(); - Animal animal = AnimalRP.users.get(damager.getUuid()); if (animal == null || !animal.name.equals(this.name)) { return; } - victim.damage((ServerWorld)victim.getWorld(), victim.getDamageSources().playerAttack(damager), dmg * 0.25F); + entity.damage((ServerWorld) entity.getWorld(), entity.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 index 48949bd..10628a5 100644 --- a/src/main/java/ovh/sad/animalrp/commands/InfoCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/InfoCommand.java @@ -5,28 +5,29 @@ 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(() -> TextParserUtils.formatText("AnimalRPs is a mod that adds animals to Minecraft."), false); - context.getSource().sendFeedback(() -> TextParserUtils.formatText("Usage of this mod is very simple."), false); - context.getSource().sendFeedback(() -> TextParserUtils.formatText("- To select a animal, use: /tf"), false); - context.getSource().sendFeedback(() -> TextParserUtils.formatText("- To turn off animals, use: /tf off"), false); - context.getSource().sendFeedback(() -> TextParserUtils.formatText("- Don't want the chat changes? Use: /disableanimalchat."), false); - context.getSource().sendFeedback(() -> Text.empty(), false); - context.getSource().sendFeedback(() -> TextParserUtils.formatText("- To see what the animals do, visit: https://git.sad.ovh/sophie/animalrpfabric"), false); - context.getSource().sendFeedback(() -> TextParserUtils.formatText("- To pet someone, rightclick on them (they must be a animal!)"), false); - context.getSource().sendFeedback(() -> Text.empty(), false); - context.getSource().sendFeedback(() -> TextParserUtils.formatText("Available animals: " + String.join(", ", AnimalRP.animals.keySet().stream().toList())), false); - + 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; })); } diff --git a/src/main/java/ovh/sad/animalrp/commands/InteractionCommand.java b/src/main/java/ovh/sad/animalrp/commands/InteractionCommand.java index cb7443f..5129bce 100644 --- a/src/main/java/ovh/sad/animalrp/commands/InteractionCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/InteractionCommand.java @@ -2,7 +2,6 @@ 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; @@ -10,7 +9,6 @@ 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; @@ -28,7 +26,6 @@ public class InteractionCommand { this.mood = mood; } - @SuppressWarnings("deprecation") public void Command(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { dispatcher.register(CommandManager.literal(this.command) @@ -38,18 +35,17 @@ public class InteractionCommand { if (!(sender instanceof ServerPlayerEntity)) { context.getSource().sendFeedback( - () -> Text.literal("I'm sorry console.").withColor(8421504), false); + () -> AnimalRP.parseText("I'm sorry console."), false); return 0; } - ServerPlayerEntity player = context.getSource().getPlayer(); + ServerPlayerEntity player = context.getSource().getPlayerOrThrow(); Animal aplayer = AnimalRP.users.get(player.getUuid()); if (aplayer == null) { context.getSource().sendFeedback( - () -> Text.literal("Only animals can interact with other animals :(") - .withColor(8421504), + () -> AnimalRP.parseText("Only animals can interact with other animals :("), false); return 0; } @@ -58,8 +54,7 @@ public class InteractionCommand { if (splayer.getName() == player.getName()) { context.getSource().sendFeedback( - () -> Text.literal("You can't " + this.command + " yourself.") - .withColor(8421504), + () -> AnimalRP.parseText("You can't " + this.command + " yourself."), false); return 0; } @@ -67,19 +62,18 @@ public class InteractionCommand { if (asplayer == null) { context.getSource().sendFeedback( - () -> Text.literal(splayer.getName() + " is not an animal! :(") - .withColor(8421504), + () -> AnimalRP.parseText(""+splayer.getName() + " is not an animal! :("), false); return 0; } - splayer.sendMessage(TextParserUtils.formatText( + splayer.sendMessage(AnimalRP.parseText( String.format(this.toThem, - "" + player.getName().getString() + "", + "" + player.getName().getString() + "", "" + aplayer.catchphrase))); - player.sendMessage(TextParserUtils.formatText( + player.sendMessage(AnimalRP.parseText( 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, diff --git a/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java b/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java index e392c09..b27d0df 100644 --- a/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/NoChatCommand.java @@ -15,19 +15,18 @@ public class NoChatCommand { public void Command(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { dispatcher.register(CommandManager.literal("disableanimalchat").executes(context -> { - UUID userUuid = context.getSource().getEntity().getUuid(); + UUID userUuid = context.getSource().getEntityOrThrow().getUuid(); - Boolean isDisabled = AnimalRP.noChat.get(context.getSource().getEntity().getUuid()); + Boolean isDisabled = AnimalRP.noChat.get(context.getSource().getEntityOrThrow().getUuid()); if (isDisabled == null) isDisabled = false; - if (isDisabled) { // + if (isDisabled) { context.getSource().sendFeedback( - () -> Text.literal("AnimalRP's chat modifications are now enabled for you.").withColor(65280), + () -> AnimalRP.parseText("AnimalRP's chat modifications are now enabled for you."), false); AnimalRP.noChat.remove(userUuid); } else { - context.getSource().sendFeedback(() -> Text - .literal("AnimalRP's chat modifications are now disabled for you.").withColor(16711680), false); + context.getSource().sendFeedback(() -> AnimalRP.parseText("AnimalRP's chat modifications are now disabled for you."), false); AnimalRP.noChat.put(userUuid, true); } HashmapStore.save("nochat.json", AnimalRP.noChat); diff --git a/src/main/java/ovh/sad/animalrp/commands/TfCommand.java b/src/main/java/ovh/sad/animalrp/commands/TfCommand.java index a82cb99..32cdfa5 100644 --- a/src/main/java/ovh/sad/animalrp/commands/TfCommand.java +++ b/src/main/java/ovh/sad/animalrp/commands/TfCommand.java @@ -9,9 +9,6 @@ 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; @@ -20,9 +17,13 @@ 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().getEntity(); + final Entity entity = context.getSource().getEntityOrThrow(); final String animalString = StringArgumentType.getString(context, "animal"); Animal animal = AnimalRP.animals.get(animalString); @@ -30,44 +31,40 @@ public class TfCommand { if (animalString.equals("off")) { if (AnimalRP.users.get(entity.getUuid()) == null) { context.getSource().sendFeedback( - () -> Text.literal("You do not have a animal set."), false); + () -> AnimalRP.parseText("You do not have a animal set."), false); return 0; } AnimalRP.users.remove(entity.getUuid()); context.getSource().sendFeedback( - () -> Text.literal("You no longer have a animal set."), false); + () -> AnimalRP.parseText("You no longer have a animal set."), false); HashmapStore.save("users.json", AnimalRP.users); return 0; } - if (animal == null) { - classicError(context.getSource()); + if(animal == null) { + classicError(context.getSource(), true); return 0; } AnimalRP.users.put(entity.getUuid(), animal); context.getSource() .sendFeedback( - () -> Text.literal("You are now an " + animalString + "! ") - .append(Text.literal(animal.catchphrase) - .formatted(Formatting.ITALIC).withColor( - Integer.parseInt(animal.color.substring(1), - 16))), + () -> AnimalRP.parseText("You are now an " + animalString + "! "+animal.catchphrase), false); HashmapStore.save("users.json", AnimalRP.users); return 1; }))); } - void classicError(ServerCommandSource source) { - MutableText options = Text.literal("Your options are: "); + void classicError(ServerCommandSource source, Boolean showInvalidAnimal) { + StringBuilder options = new StringBuilder("Your options are: "); + for (Entry entry : AnimalRP.animals.entrySet()) { - options.append(Text.literal(entry.getKey() + " ") - .withColor(Integer.parseInt(entry.getValue().color.substring(1), 16))); + options.append(" ").append(entry.getKey()).append(""); } - 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); + 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); } } \ No newline at end of file diff --git a/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java b/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java index 560cc8e..ea26245 100644 --- a/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java +++ b/src/main/java/ovh/sad/animalrp/mixin/FoodEating.java @@ -30,7 +30,7 @@ public class FoodEating { Animal animal = AnimalRP.users.get(player.getUuid()); if (animal != null) { - if (animal.name == "bee") { + if (animal.name.equals("bee")) { ((Bee) animal).onEat(player, stack); } if (animal.superfoods.contains(stack.getItem())) { From 56e4eb4cf043bd1e5265776d8a867a45da39da3c Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 13 Mar 2025 16:57:13 +0200 Subject: [PATCH 11/11] Do not reimplement interactions for rightclicking --- README.MD | 9 +++++++++ src/main/java/ovh/sad/animalrp/AnimalRP.java | 21 +++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.MD b/README.MD index 0f43b1a..9650ebe 100644 --- a/README.MD +++ b/README.MD @@ -11,6 +11,15 @@ 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. diff --git a/src/main/java/ovh/sad/animalrp/AnimalRP.java b/src/main/java/ovh/sad/animalrp/AnimalRP.java index e6fe243..390139d 100644 --- a/src/main/java/ovh/sad/animalrp/AnimalRP.java +++ b/src/main/java/ovh/sad/animalrp/AnimalRP.java @@ -13,7 +13,9 @@ 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; @@ -58,6 +60,7 @@ public class AnimalRP implements ModInitializer { public void onInitialize() { String catAscii = """ + |\\ _,,,---,,_ ZZZzz /,`.-'`' -. ;-;;,_ |,4- ) )-,_. ,\\ ( `'-' @@ -139,18 +142,12 @@ ZZZzz /,`.-'`' -. ;-;;,_ lastPetTimes.put(attackerId, currentTime); - attackee.sendMessage(AnimalRP.parseText( - String.format("%s petted you! %s", - "" + attacker.getName().getString() + "", - "" + attackerAnimal.catchphrase)), false); - attacker.sendMessage(AnimalRP.parseText( - String.format("You petted %s! %s", - "" + attackee.getName().getString() + "", - "" + attackeeAnimal.catchphrase)), false); - attacker.getWorld().playSound(attackee, attackee.getBlockPos(), - attackeeAnimal.moodSounds.get(Mood.CUTE), SoundCategory.PLAYERS, 1F, - 1); - + 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; });