Skip to content

Commit

Permalink
misc: RegistryKey -> CustomEntry
Browse files Browse the repository at this point in the history
misc: 移除不再需要的东西
  • Loading branch information
MATRIX-feather committed Oct 10, 2024
1 parent cfd635a commit 7377077
Show file tree
Hide file tree
Showing 28 changed files with 108 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class AxolotlValues extends AnimalValues
{
public final SingleValue<Integer> COLOR = createSingle("axolotl_color", 0).withRandom(0, 1, 2, 3, 4);
public final SingleValue<Integer> COLOR = createSingle("axolotl_color", 0);
public final SingleValue<Boolean> PLAYING_DEAD = createSingle("axolotl_playing_dead", false);
public final SingleValue<Boolean> SPAWNED_FROM_BUCKET = createSingle("axolotl_spawned_from_bucket", false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class CreeperValues extends MonsterValues
{
public final SingleValue<Integer> STATE = createSingle("creeper_state", 0);
public final SingleValue<Boolean> IS_CHARGED_CREEPER = createSingle("creeper_is_charged", false).withRandom(false, false, false, false, true);
public final SingleValue<Boolean> IS_CHARGED_CREEPER = createSingle("creeper_is_charged", false);
public final SingleValue<Boolean> IGNITED = createSingle("creeper_ignited", false);

public CreeperValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class FoxValues extends AnimalValues
{
public final SingleValue<Integer> FOX_VARIANT = createSingle("fox_variant", 0).withRandom(0, 1);
public final SingleValue<Integer> FOX_VARIANT = createSingle("fox_variant", 0);
public final SingleValue<Byte> FLAGS = createSingle("fox_flags", (byte)0);
public final SingleValue<UUID> TRUSTED_ID_0 = createSingle("fox_trusted_0", UUID.randomUUID());
public final SingleValue<UUID> TRUSTED_ID_1 = createSingle("fox_trusted_1", UUID.randomUUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

public class FrogValues extends AnimalValues
{
public final SingleValue<Holder<FrogVariant>> FROG_VARIANT = createSingle("frog_variant", getFrogVariant(FrogVariant.TEMPERATE))
.withRandom(getFrogVariant(FrogVariant.TEMPERATE), getFrogVariant(FrogVariant.COLD), getFrogVariant(FrogVariant.WARM));
public final SingleValue<Holder<FrogVariant>> FROG_VARIANT = createSingle("frog_variant", getFrogVariant(FrogVariant.TEMPERATE));

private Holder<FrogVariant> getFrogVariant(ResourceKey<FrogVariant> key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class LlamaValues extends ChestedHorseValues
{
public final SingleValue<Integer> SLOTS = createSingle("llama_slots", 2);
public final SingleValue<Integer> VARIANT = createSingle("llama_variant", 1).withRandom(0, 1, 2, 3);
public final SingleValue<Integer> VARIANT = createSingle("llama_variant", 1);

public LlamaValues()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class MooshroomValues extends AnimalValues
{
public final SingleValue<String> VARIANT = createSingle("mooshroom_variant", RED).withRandom(RED, RED, RED, BROWN);
public final SingleValue<String> VARIANT = createSingle("mooshroom_variant", RED);
public static final String RED = "red";
public static final String BROWN = "brown";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class ParrotValues extends TameableAnimalValues
{
public final SingleValue<Integer> PARROT_VARIANT = createSingle("parrot_variant", 0).withRandom(0, 1, 2, 3, 4);
public final SingleValue<Integer> PARROT_VARIANT = createSingle("parrot_variant", 0);

public ParrotValues()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,6 @@ public SingleValue(String name, Class<T> type, int index, @NotNull T defaultValu
this.defaultValue = defaultValue;
}

private final List<T> randomValues = new ObjectArrayList<>();

public List<T> getRandomValues()
{
return new ObjectArrayList<>(randomValues);
}

public SingleValue<T> withRandom(List<T> values)
{
var newInstance = new SingleValue<>(this.name, this.type, this.index, this.defaultValue);
newInstance.randomValues.addAll(values);

return newInstance;
}

public SingleValue<T> withRandom(T... randomValues)
{
return withRandom(Arrays.stream(randomValues).toList());
}

@Override
public boolean equals(Object obj)
{
Expand All @@ -98,7 +78,6 @@ public boolean equalsStrict(Object obj)
return this.index == other.index
&& this.type.equals(other.type)
&& this.name.equals(other.name)
&& this.randomValues.equals(other.randomValues)
&& this.defaultValue.equals(other.defaultValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,7 @@ public class WolfValues extends TameableAnimalValues
public final SingleValue<Boolean> BEGGING = createSingle("wolf_begging", false);
public final SingleValue<Integer> COLLAR_COLOR = createSingle("wolf_collar_color", 14);
public final SingleValue<Integer> ANGER_TIME = createSingle("wolf_anger_time", 0);
public final SingleValue<Holder<WolfVariant>> WOLF_VARIANT = createSingle("wolf_variant", getWolfVariant(WolfVariants.PALE)).withRandom(allVariants());

@Nullable
private Holder<WolfVariant>[] allVariants;

private Holder<WolfVariant>[] allVariants()
{
if (this.allVariants != null)
return allVariants;

this.allVariants = toVariantHolders(
WolfVariants.PALE,
WolfVariants.SPOTTED,
WolfVariants.SNOWY,
WolfVariants.BLACK,
WolfVariants.ASHEN,
WolfVariants.RUSTY,
WolfVariants.WOODS,
WolfVariants.CHESTNUT,
WolfVariants.STRIPED);

return this.allVariants;
}

public static Holder<WolfVariant>[] toVariantHolders(ResourceKey<WolfVariant>... resKeys)
{
var list = new ObjectArrayList<Holder<WolfVariant>>();

for (ResourceKey<WolfVariant> resKey : resKeys)
list.add(getWolfVariant(resKey));

return list.toArray(new Holder[]{});
}
public final SingleValue<Holder<WolfVariant>> WOLF_VARIANT = createSingle("wolf_variant", getWolfVariant(WolfVariants.PALE));

public static Holder<WolfVariant> getWolfVariant(ResourceKey<WolfVariant> resKey)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import xyz.nifeather.morph.backends.server.renderer.network.PacketFactory;
import xyz.nifeather.morph.backends.server.renderer.network.datawatcher.values.AbstractValues;
import xyz.nifeather.morph.backends.server.renderer.network.datawatcher.values.SingleValue;
import xyz.nifeather.morph.backends.server.renderer.network.registries.RegistryKey;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntry;
import xyz.nifeather.morph.backends.server.renderer.network.registries.RenderRegistry;
import xyz.nifeather.morph.backends.server.renderer.utilties.WatcherUtils;
import xyz.nifeather.morph.misc.disguiseProperty.SingleProperty;
Expand Down Expand Up @@ -128,52 +128,52 @@ protected <X> void onPropertyWrite(SingleProperty<X> property, X value)

protected final Map<String, Object> customRegistry = Collections.synchronizedMap(new Object2ObjectOpenHashMap<>());

public <X> void writeEntry(RegistryKey<X> key, X value)
public <X> void writeEntry(CustomEntry<X> entry, X value)
{
customRegistry.put(key.name, value);
customRegistry.put(entry.name, value);

if (doingInitialization)
return;

var prev = readEntryOrDefault(key, null);
onEntryWrite(key, prev, value);
var prev = readEntryOrDefault(entry, null);
onEntryWrite(entry, prev, value);
}

protected <X> void onEntryWrite(RegistryKey<X> key, @Nullable X oldVal, @Nullable X newVal)
protected <X> void onEntryWrite(CustomEntry<X> entry, @Nullable X oldVal, @Nullable X newVal)
{
}

@NotNull
public <X> X readEntryOrThrow(RegistryKey<X> key)
public <X> X readEntryOrThrow(CustomEntry<X> entry)
{
var val = this.readEntry(key);
var val = this.readEntry(entry);
if (val == null)
throw new NullDependencyException("Custom Key '%s' not found in '%s'".formatted(key, this.getClass().getSimpleName()));
throw new NullDependencyException("Custom entry '%s' not found in '%s'".formatted(entry, this.getClass().getSimpleName()));

return val;
}

public <X> X readEntryOrDefault(RegistryKey<X> key, X defaultValue)
public <X> X readEntryOrDefault(CustomEntry<X> entry, X defaultValue)
{
var val = readEntry(key);
var val = readEntry(entry);

return val == null ? defaultValue : val;
}

@Nullable
public <X> X readEntry(RegistryKey<X> key)
public <X> X readEntry(CustomEntry<X> entry)
{
var val = customRegistry.getOrDefault(key.name, null);
var val = customRegistry.getOrDefault(entry.name, null);

if (val == null) return null;

if (key.type.isInstance(val))
if (entry.type.isInstance(val))
{
return (X)val;
}
else
{
logger.warn("Find incompatible value '%s' for key '%s'!".formatted(val, key));
logger.warn("Find incompatible value '%s' for custom entry '%s'!".formatted(val, entry));

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntries;
import xyz.nifeather.morph.backends.server.renderer.network.registries.RegistryKey;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntry;
import xyz.nifeather.morph.backends.server.renderer.network.registries.ValueIndex;
import xyz.nifeather.morph.misc.AnimationNames;

Expand All @@ -18,11 +18,11 @@ protected void initRegistry()
}

@Override
protected <X> void onEntryWrite(RegistryKey<X> key, X oldVal, X newVal)
protected <X> void onEntryWrite(CustomEntry<X> entry, X oldVal, X newVal)
{
super.onEntryWrite(key, oldVal, newVal);
super.onEntryWrite(entry, oldVal, newVal);

if (key.equals(CustomEntries.ANIMATION))
if (entry.equals(CustomEntries.ANIMATION))
{
var id = newVal.toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntries;
import xyz.nifeather.morph.backends.server.renderer.network.registries.RegistryKey;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntry;
import xyz.nifeather.morph.backends.server.renderer.network.registries.ValueIndex;
import xyz.nifeather.morph.misc.AnimationNames;

Expand All @@ -25,11 +25,11 @@ protected void initRegistry()
}

@Override
protected <X> void onEntryWrite(RegistryKey<X> key, X oldVal, X newVal)
protected <X> void onEntryWrite(CustomEntry<X> entry, X oldVal, X newVal)
{
super.onEntryWrite(key, oldVal, newVal);
super.onEntryWrite(entry, oldVal, newVal);

if (key.equals(CustomEntries.ANIMATION))
if (entry.equals(CustomEntries.ANIMATION))
{
var animId = newVal.toString();
var player = getBindingPlayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntries;
import xyz.nifeather.morph.backends.server.renderer.network.registries.RegistryKey;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntry;
import xyz.nifeather.morph.backends.server.renderer.network.registries.ValueIndex;
import xyz.nifeather.morph.misc.AnimationNames;
import xyz.nifeather.morph.misc.disguiseProperty.DisguiseProperties;
Expand Down Expand Up @@ -88,11 +88,11 @@ protected <X> void onPropertyWrite(SingleProperty<X> property, X value)
}

@Override
protected <X> void onEntryWrite(RegistryKey<X> key, X oldVal, X newVal)
protected <X> void onEntryWrite(CustomEntry<X> entry, X oldVal, X newVal)
{
super.onEntryWrite(key, oldVal, newVal);
super.onEntryWrite(entry, oldVal, newVal);

if (key.equals(CustomEntries.ANIMATION))
if (entry.equals(CustomEntries.ANIMATION))
{
var animId = newVal.toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntries;
import xyz.nifeather.morph.backends.server.renderer.network.registries.RegistryKey;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntry;

public class EHasAttackAnimationWatcher extends LivingEntityWatcher
{
Expand All @@ -16,11 +16,11 @@ public EHasAttackAnimationWatcher(Player bindingPlayer, EntityType entityType)
}

@Override
protected <X> void onEntryWrite(RegistryKey<X> key, X oldVal, X newVal)
protected <X> void onEntryWrite(CustomEntry<X> entry, X oldVal, X newVal)
{
super.onEntryWrite(key, oldVal, newVal);
super.onEntryWrite(entry, oldVal, newVal);

if (key.equals(CustomEntries.ATTACK_ANIMATION) && Boolean.TRUE.equals(newVal))
if (entry.equals(CustomEntries.ATTACK_ANIMATION) && Boolean.TRUE.equals(newVal))
{
var entity = ((CraftPlayer)getBindingPlayer()).getHandle();
sendPacketToAffectedPlayers(PacketContainer.fromPacket(new ClientboundEntityEventPacket(entity, (byte)4)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.bukkit.entity.Player;
import xyz.nifeather.morph.backends.server.renderer.network.datawatcher.watchers.SingleWatcher;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntries;
import xyz.nifeather.morph.backends.server.renderer.network.registries.RegistryKey;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntry;
import xyz.nifeather.morph.backends.server.renderer.network.registries.ValueIndex;
import xyz.nifeather.morph.misc.NmsRecord;

Expand Down Expand Up @@ -72,11 +72,11 @@ protected void doSync()
}

@Override
protected <X> void onEntryWrite(RegistryKey<X> key, X oldVal, X newVal)
protected <X> void onEntryWrite(CustomEntry<X> entry, X oldVal, X newVal)
{
super.onEntryWrite(key, oldVal, newVal);
super.onEntryWrite(entry, oldVal, newVal);

if (key.equals(CustomEntries.DISGUISE_NAME))
if (entry.equals(CustomEntries.DISGUISE_NAME))
{
var str = newVal.toString();
var component = str.isEmpty() ? null : Component.literal(str);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.bukkit.entity.Fox;
import org.bukkit.entity.Player;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntries;
import xyz.nifeather.morph.backends.server.renderer.network.registries.RegistryKey;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntry;
import xyz.nifeather.morph.backends.server.renderer.network.registries.ValueIndex;
import xyz.nifeather.morph.misc.AnimationNames;
import xyz.nifeather.morph.misc.disguiseProperty.DisguiseProperties;
Expand Down Expand Up @@ -43,11 +43,11 @@ protected <X> void onPropertyWrite(SingleProperty<X> property, X value)
}

@Override
protected <X> void onEntryWrite(RegistryKey<X> key, X oldVal, X newVal)
protected <X> void onEntryWrite(CustomEntry<X> entry, X oldVal, X newVal)
{
super.onEntryWrite(key, oldVal, newVal);
super.onEntryWrite(entry, oldVal, newVal);

if (key.equals(CustomEntries.ANIMATION))
if (entry.equals(CustomEntries.ANIMATION))
{
var animId = newVal.toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.bukkit.entity.Player;
import xiamomc.pluginbase.Exceptions.NullDependencyException;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntries;
import xyz.nifeather.morph.backends.server.renderer.network.registries.RegistryKey;
import xyz.nifeather.morph.backends.server.renderer.network.registries.CustomEntry;
import xyz.nifeather.morph.backends.server.renderer.network.registries.ValueIndex;
import xyz.nifeather.morph.misc.AnimationNames;
import xyz.nifeather.morph.misc.disguiseProperty.DisguiseProperties;
Expand Down Expand Up @@ -117,11 +117,11 @@ protected <X> void onPropertyWrite(SingleProperty<X> property, X value)
}

@Override
protected <X> void onEntryWrite(RegistryKey<X> key, X oldVal, X newVal)
protected <X> void onEntryWrite(CustomEntry<X> entry, X oldVal, X newVal)
{
super.onEntryWrite(key, oldVal, newVal);
super.onEntryWrite(entry, oldVal, newVal);

if (key.equals(CustomEntries.ANIMATION))
if (entry.equals(CustomEntries.ANIMATION))
{
var animId = newVal.toString();
var player = getBindingPlayer();
Expand Down
Loading

0 comments on commit 7377077

Please sign in to comment.