Compare commits

...

5 commits

Author SHA1 Message Date
Soph :3 4c09e501b4
updateesss
All checks were successful
build / build (21) (push) Successful in 2m15s
2024-09-19 02:56:19 +03:00
Soph :3 d12c3e5769
Ok
All checks were successful
build / build (21) (push) Successful in 1m24s
2024-09-13 21:43:52 +03:00
Soph :3 6898039c61
better idea
All checks were successful
build / build (21) (push) Successful in 1m21s
2024-09-13 21:31:42 +03:00
Soph :3 aa200b17c0
Formatting
All checks were successful
build / build (21) (push) Successful in 1m16s
2024-09-13 21:10:03 +03:00
Soph :3 2f5084010a
simple-ish database + more improvements
All checks were successful
build / build (21) (push) Successful in 1m31s
2024-09-13 20:58:26 +03:00
14 changed files with 177 additions and 58 deletions

View file

@ -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;
@ -28,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();
@ -39,12 +39,30 @@ 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() {
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());
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() {
@ -53,9 +71,11 @@ 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("<color "+animal.color+">");
if (noChat.get(ctx.player().getUuid()) != null)
return PlaceholderResult.value("");
return PlaceholderResult.value(animal.color);
}
});
@ -64,12 +84,19 @@ public class AnimalRP implements ModInitializer {
(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);
});
}
}

View file

@ -14,6 +14,10 @@ public abstract class Animal {
public HashMap<Mood, SoundEvent> moodSounds = new HashMap<Mood, SoundEvent>();
public ArrayList<Item> superfoods = new ArrayList<Item>();
public String toString() {
return this.name;
}
Animal(String name, String catchphrase, String color) {
this.name = name;
this.catchphrase = catchphrase;

View file

@ -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("<red>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("<green>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("<red>You have <green>" + String.join(", ", Emote.emotes.keySet().stream().map(Emote.Emotes::name).map(String::toLowerCase).collect(Collectors.toSet())) + "</green> as options."), false);
player.sendFeedback(
() -> TextParserUtils
.formatText(
"<red>You have <green>"
+ String.join(", ",
Emote.emotes.keySet().stream().map(Emote.Emotes::name)
.map(String::toLowerCase).collect(Collectors.toSet()))
+ "</green> as options."),
false);
}
}

View file

@ -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,
"<light_purple>" + splayer.getName().getString() + "</light_purple>",
"<italic><gray>" + 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;
})));

View file

@ -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<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess,
@ -17,14 +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);
return 0;
}));

View file

@ -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<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess,
@ -23,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);
@ -54,6 +53,7 @@ public class TfCommand {
Integer.parseInt(animal.color.substring(1),
16))),
false);
HashmapStore.save("users.json", AnimalRP.users);
return 1;
})));
}

View file

@ -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())));
}

View file

@ -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);

View file

@ -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);
}
}
}

View file

@ -10,7 +10,7 @@ public class Cooldown {
public long getTime() {
return this.timeCreated - (System.currentTimeMillis() - this.length);
}
public boolean isExpired() {
return this.getTime() <= 0;
}

View file

@ -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,10 +97,8 @@ public class Emote {
List<Vec3d> 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);
}
}
@ -115,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),
@ -149,7 +147,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) {

View file

@ -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<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();
}
}
}

View file

@ -1,5 +1,5 @@
package ovh.sad.animalrp.util;
public enum Mood {
HAPPY,SAD,STRESSED,ANGRY,CUTE
HAPPY, SAD, STRESSED, ANGRY, CUTE
}

View file

@ -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);