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