package ovh.sad.animalrp.animals; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.UUID; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; 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.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.server.network.ServerPlayerEntity; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; 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; public class Bee extends Animal { class Row { Item mat; Integer times; } ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); private static Item[] _allFlowers = { Items.ALLIUM, Items.AZURE_BLUET, Items.BLUE_ORCHID, Items.CORNFLOWER, Items.DANDELION, Items.LILY_OF_THE_VALLEY, Items.OXEYE_DAISY, Items.POPPY, Items.TORCHFLOWER, Items.ORANGE_TULIP, Items.PINK_TULIP, Items.RED_TULIP, Items.WHITE_TULIP }; public static List allFlowers = Arrays.asList(_allFlowers); public static Identifier beeFoodKey = Identifier.of("animalrp", "bee_food"); public static HashMap inARow = new HashMap(); TextDestroyer destroyer = new TextDestroyer(new String[] { ">_<", "*buzz*", ";3", ":3", "εწз", " ≧◠◡◠≦ ", "*stings you*", "*humms*", "*i'm a bee*" }, new String[][] { { "e", "ee" }, { "b", "bzz" }, { "h", "hh" }, { "ie", "ee" }, { "be", "bee" }, { "E", "EE" }, { "B", "BZZ" }, { "H", "HH" }, { "IE", "EE" }, { "BE", "BEE" } }); ArrayList sneakers = new ArrayList(); public Bee() { super("bee", "Buzz...", "#FFFF00"); this.moodSounds.put(Mood.HAPPY, SoundEvents.ENTITY_BEE_LOOP); this.moodSounds.put(Mood.CUTE, SoundEvents.ENTITY_BEE_LOOP); 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); UseItemCallback.EVENT.register((player, world, hand) -> { System.out.println("1"); Animal animal = AnimalRP.users.get(player.getUuid()); ItemStack item = player.getStackInHand(hand); if (item == null) // air interact return TypedActionResult.pass(item); System.out.println("2"); if (!allFlowers.contains(item.getItem())) { // not a flower return TypedActionResult.pass(item); } System.out.println("3"); Boolean incorrect = false; if (animal == null) { incorrect = true; } else { if (animal.name != this.name) { incorrect = true; } } System.out.println("3"); if (incorrect) { if (item.get(AnimalRP.BEE_FOOD) != null) { item.remove(AnimalRP.BEE_FOOD); item.remove(DataComponentTypes.FOOD); return TypedActionResult.success(item, false); } return TypedActionResult.fail(item); } System.out.println("4"); if (item.get(AnimalRP.BEE_FOOD) != null) { // correct animal, but foodkey already set return TypedActionResult.fail(item); } System.out.println("5"); // .statusEffect(new StatusEffectInstance(StatusEffects.SPEED, 20 *4, 1, true, true, true), 1) FoodComponent food = new FoodComponent.Builder() .alwaysEdible() .nutrition(4) .saturationModifier(9.4f) .build(); System.out.println("6"); item.set(DataComponentTypes.FOOD, food); item.set(AnimalRP.BEE_FOOD, false); System.out.println("7"); return TypedActionResult.success(item, false); }); } // called from the 'Sneaking' mixin. public void onSneak(ServerPlayerEntity player, boolean status) { Animal animal = AnimalRP.users.get(player.getUuid()); if (animal == null) return; if (animal.name != this.name) return; Block type = player.getWorld().getBlockState(player.getBlockPos().down()).getBlock(); if (status && type != Blocks.AIR && type != Blocks.WATER) { if (!sneakers.contains(player.getUuid())) { sneakers.add(player.getUuid()); executor.schedule(new Runnable() { @Override public void run() { if (sneakers.contains(player.getUuid())) sneakers.remove(player.getUuid()); } }, 1, TimeUnit.SECONDS); } else { sneakers.remove(player.getUuid()); player.addStatusEffect( new StatusEffectInstance(StatusEffects.LEVITATION, 20, 5, true, true, true)); player.getWorld().playSound(player, player.getBlockPos(), animal.moodSounds.get(Mood.HAPPY), SoundCategory.PLAYERS, 10F, 1); } } } @Override public String chatTransformations(String message) { return destroyer.destroy(message); } }