|
| 1 | +package org.skriptlang.skript.bukkit.entity.nautilus; |
| 2 | + |
| 3 | +import ch.njol.skript.classes.registry.RegistryClassInfo; |
| 4 | +import ch.njol.skript.entity.EntityData; |
| 5 | +import ch.njol.skript.lang.Literal; |
| 6 | +import ch.njol.skript.lang.SkriptParser.ParseResult; |
| 7 | +import ch.njol.skript.registrations.Classes; |
| 8 | +import ch.njol.skript.variables.Variables; |
| 9 | +import ch.njol.util.Kleenean; |
| 10 | +import ch.njol.util.coll.CollectionUtils; |
| 11 | +import io.papermc.paper.registry.RegistryAccess; |
| 12 | +import io.papermc.paper.registry.RegistryKey; |
| 13 | +import org.bukkit.Registry; |
| 14 | +import org.bukkit.entity.ZombieNautilus; |
| 15 | +import org.bukkit.entity.ZombieNautilus.Variant; |
| 16 | +import org.jetbrains.annotations.NotNull; |
| 17 | +import org.jetbrains.annotations.Nullable; |
| 18 | + |
| 19 | +import java.util.Objects; |
| 20 | + |
| 21 | +public class ZombieNautilusData extends EntityData<ZombieNautilus> { |
| 22 | + |
| 23 | + private static Variant[] VARIANTS; |
| 24 | + |
| 25 | + public static void register() { |
| 26 | + EntityData.register(ZombieNautilusData.class, "zombie nautilus", ZombieNautilus.class, 0, "zombie nautilus"); |
| 27 | + Variables.yggdrasil.registerSingleClass(Variant.class, "ZombieNautilus.Variant"); |
| 28 | + |
| 29 | + Registry<@NotNull Variant> variantRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ZOMBIE_NAUTILUS_VARIANT); |
| 30 | + VARIANTS = variantRegistry.stream().toArray(Variant[]::new); |
| 31 | + Classes.registerClass(new RegistryClassInfo<>(Variant.class, variantRegistry, "zombienautilusvariant", "zombie nautilus variants") |
| 32 | + .user("zombie ?nautilus ?variants?") |
| 33 | + .name("Zombie Nautilus Variant") |
| 34 | + .description("Represents the variant of a zombie nautilus.") |
| 35 | + .since("INSERT VERSION") |
| 36 | + .documentationId("ZombieNautilusVariant")); |
| 37 | + } |
| 38 | + |
| 39 | + private Kleenean isTamed = Kleenean.UNKNOWN; |
| 40 | + private @Nullable Variant variant = null; |
| 41 | + |
| 42 | + public ZombieNautilusData() { } |
| 43 | + |
| 44 | + public ZombieNautilusData(@Nullable Variant variant) { |
| 45 | + this.variant = variant; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + protected boolean init(Literal<?>[] exprs, int matchedCodeName, int matchedPattern, ParseResult parseResult) { |
| 50 | + if (parseResult.hasTag("tamed")) { |
| 51 | + isTamed = Kleenean.TRUE; |
| 52 | + } |
| 53 | + if (exprs[0] != null) { |
| 54 | + //noinspection unchecked |
| 55 | + variant = ((Literal<ZombieNautilus.Variant>) exprs[0]).getSingle(); |
| 56 | + } |
| 57 | + return true; |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + protected boolean init(@Nullable Class<? extends ZombieNautilus> entityClass, @Nullable ZombieNautilus zombieNautilus) { |
| 62 | + if (zombieNautilus != null) { |
| 63 | + isTamed = Kleenean.get(zombieNautilus.isTamed()); |
| 64 | + variant = zombieNautilus.getVariant(); |
| 65 | + } |
| 66 | + return true; |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public void set(ZombieNautilus zombieNautilus) { |
| 71 | + zombieNautilus.setTamed(isTamed.isTrue()); |
| 72 | + Variant variant = this.variant; |
| 73 | + if (variant == null) { |
| 74 | + variant = CollectionUtils.getRandom(VARIANTS); |
| 75 | + } |
| 76 | + assert variant != null; |
| 77 | + zombieNautilus.setVariant(variant); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + protected boolean match(ZombieNautilus zombieNautilus) { |
| 82 | + return kleeneanMatch(isTamed, zombieNautilus.isTamed()) && |
| 83 | + dataMatch(variant, zombieNautilus.getVariant()); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public Class<? extends ZombieNautilus> getType() { |
| 88 | + return ZombieNautilus.class; |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public @NotNull EntityData<?> getSuperType() { |
| 93 | + return new ZombieNautilusData(); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + protected int hashCode_i() { |
| 98 | + return Objects.hash(isTamed, variant); |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + protected boolean equals_i(EntityData<?> entityData) { |
| 103 | + if (!(entityData instanceof ZombieNautilusData other)) { |
| 104 | + return false; |
| 105 | + } |
| 106 | + return isTamed == other.isTamed && variant == other.variant; |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + public boolean isSupertypeOf(EntityData<?> entityData) { |
| 111 | + if (!(entityData instanceof ZombieNautilusData other)) { |
| 112 | + return false; |
| 113 | + } |
| 114 | + return kleeneanMatch(isTamed, other.isTamed) && dataMatch(variant, other.variant); |
| 115 | + } |
| 116 | + |
| 117 | +} |
0 commit comments