Implemented Fox properties

This commit is contained in:
D3v1s0m 2023-07-03 11:37:56 +05:30
parent 8c83cb3428
commit 4cc468b919
No known key found for this signature in database
GPG Key ID: 3B6EC35367B8D82E
10 changed files with 63 additions and 9 deletions

@ -0,0 +1,6 @@
package lol.pyr.znpcsplus.util;
public enum FoxVariant {
RED,
SNOW
}

@ -285,6 +285,7 @@ public class ZNpcsPlus extends JavaPlugin {
registerEnumParser(manager, CreeperState.class, incorrectUsageMessage); registerEnumParser(manager, CreeperState.class, incorrectUsageMessage);
registerEnumParser(manager, ParrotVariant.class, incorrectUsageMessage); registerEnumParser(manager, ParrotVariant.class, incorrectUsageMessage);
registerEnumParser(manager, SpellType.class, incorrectUsageMessage); registerEnumParser(manager, SpellType.class, incorrectUsageMessage);
registerEnumParser(manager, FoxVariant.class, incorrectUsageMessage);
manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root")) manager.registerCommand("npc", new MultiCommand(loadHelpMessage("root"))
.addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry)) .addSubcommand("create", new CreateCommand(npcRegistry, typeRegistry))

@ -126,6 +126,7 @@ public class PropertySetCommand implements CommandHandler {
if (type == ParrotVariant.class) return context.suggestEnum(ParrotVariant.values()); if (type == ParrotVariant.class) return context.suggestEnum(ParrotVariant.values());
if (type == BlockState.class) return context.suggestLiteral("hand", "looking_at", "block"); if (type == BlockState.class) return context.suggestLiteral("hand", "looking_at", "block");
if (type == SpellType.class) return context.suggestEnum(SpellType.values()); if (type == SpellType.class) return context.suggestEnum(SpellType.values());
if (type == FoxVariant.class) return context.suggestEnum(FoxVariant.values());
} }
else if (context.argSize() == 4) { else if (context.argSize() == 4) {
if (type == BlockState.class) { if (type == BlockState.class) {

@ -39,6 +39,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
registerEnumSerializer(CreeperState.class); registerEnumSerializer(CreeperState.class);
registerEnumSerializer(ParrotVariant.class); registerEnumSerializer(ParrotVariant.class);
registerEnumSerializer(SpellType.class); registerEnumSerializer(SpellType.class);
registerEnumSerializer(FoxVariant.class);
registerType("glow", NamedTextColor.class); registerType("glow", NamedTextColor.class);
registerType("fire", false); registerType("fire", false);
@ -122,6 +123,13 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
// Evoker // Evoker
registerType("evoker_spell", SpellType.NONE); registerType("evoker_spell", SpellType.NONE);
// Fox
registerType("fox_variant", FoxVariant.RED);
registerType("fox_sitting", false);
registerType("fox_crouching", false);
registerType("fox_sleeping", false);
registerType("fox_faceplanted", false);
// Pufferfish // Pufferfish
registerType("puff_state", null); // TODO: Make a puff state enum class registerType("puff_state", null); // TODO: Make a puff state enum class
@ -140,13 +148,6 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
registerType("carpet_color", DyeColor.class); // TODO registerType("carpet_color", DyeColor.class); // TODO
registerType("llama_variant", 0); // TODO registerType("llama_variant", 0); // TODO
// Fox
registerType("fox_variant", 0); // TODO: 0 = red, 1 = snow
registerType("fox_sitting", false); // TODO
registerType("fox_crouching", false); // TODO
registerType("fox_sleeping", false); // TODO
registerType("fox_faceplanting", false); // TODO
// Frog // Frog
registerType("frog_type", null); // TODO: It has a custom type read on wiki.vg registerType("frog_type", null); // TODO: It has a custom type read on wiki.vg

@ -76,4 +76,8 @@ public interface MetadataFactory {
// Evoker // Evoker
EntityData evokerSpell(int spell); EntityData evokerSpell(int spell);
// Fox
EntityData foxVariant(int variant);
EntityData foxProperties(boolean sitting, boolean crouching, boolean sleeping, boolean facePlanted);
} }

@ -103,4 +103,14 @@ public class V1_15MetadataFactory extends V1_14MetadataFactory {
public EntityData evokerSpell(int spell) { public EntityData evokerSpell(int spell) {
return newEntityData(16, EntityDataTypes.BYTE, (byte) spell); return newEntityData(16, EntityDataTypes.BYTE, (byte) spell);
} }
@Override
public EntityData foxVariant(int variant) {
return newEntityData(16, EntityDataTypes.INT, variant);
}
@Override
public EntityData foxProperties(boolean sitting, boolean crouching, boolean sleeping, boolean facePlanted) {
return newEntityData(17, EntityDataTypes.BYTE, (byte) ((sitting ? 0x01 : 0) | (crouching ? 0x04 : 0) | (sleeping ? 0x20 : 0) | (facePlanted ? 0x40 : 0)));
}
} }

@ -163,4 +163,14 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory {
public EntityData evokerSpell(int spell) { public EntityData evokerSpell(int spell) {
return newEntityData(17, EntityDataTypes.BYTE, (byte) spell); return newEntityData(17, EntityDataTypes.BYTE, (byte) spell);
} }
@Override
public EntityData foxVariant(int variant) {
return newEntityData(17, EntityDataTypes.INT, variant);
}
@Override
public EntityData foxProperties(boolean sitting, boolean crouching, boolean sleeping, boolean facePlanted) {
return newEntityData(18, EntityDataTypes.BYTE, (byte) ((sitting ? 0x01 : 0) | (crouching ? 0x04 : 0) | (sleeping ? 0x20 : 0) | (facePlanted ? 0x40 : 0)));
}
} }

@ -185,6 +185,16 @@ public class V1_8MetadataFactory implements MetadataFactory {
throw new UnsupportedOperationException("The evoker spell entity data isn't supported on this version"); throw new UnsupportedOperationException("The evoker spell entity data isn't supported on this version");
} }
@Override
public EntityData foxVariant(int variant) {
throw new UnsupportedOperationException("The fox variant entity data isn't supported on this version");
}
@Override
public EntityData foxProperties(boolean sitting, boolean crouching, boolean sleeping, boolean facePlanted) {
throw new UnsupportedOperationException("The fox properties entity data isn't supported on this version");
}
@Override @Override
public EntityData silent(boolean enabled) { public EntityData silent(boolean enabled) {
return newEntityData(4, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0)); return newEntityData(4, EntityDataTypes.BYTE, (byte) (enabled ? 1 : 0));

@ -246,7 +246,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "fox", EntityTypes.FOX) register(builder(p, "fox", EntityTypes.FOX)
.setHologramOffset(-1.275) .setHologramOffset(-1.275)
.addProperties("hand")); .addProperties("hand", "fox_variant", "fox_sitting", "fox_crouching", "fox_sleeping", "fox_faceplanted"));
register(builder(p, "panda", EntityTypes.PANDA) register(builder(p, "panda", EntityTypes.PANDA)
.setHologramOffset(-0.725)); .setHologramOffset(-0.725));

@ -195,9 +195,20 @@ public class V1_8PacketFactory implements PacketFactory {
); );
add(data, metadataFactory.endermanScreaming(properties.getProperty(propertyRegistry.getByName("enderman_screaming", Boolean.class)))); add(data, metadataFactory.endermanScreaming(properties.getProperty(propertyRegistry.getByName("enderman_screaming", Boolean.class))));
add(data, metadataFactory.endermanStaring(properties.getProperty(propertyRegistry.getByName("enderman_staring", Boolean.class)))); add(data, metadataFactory.endermanStaring(properties.getProperty(propertyRegistry.getByName("enderman_staring", Boolean.class))));
} else if (entity.getType().equals(EntityTypes.EVOKER)) { }
else if (entity.getType().equals(EntityTypes.EVOKER)) {
add(data, metadataFactory.evokerSpell(properties.getProperty(propertyRegistry.getByName("evoker_spell", SpellType.class)).ordinal())); add(data, metadataFactory.evokerSpell(properties.getProperty(propertyRegistry.getByName("evoker_spell", SpellType.class)).ordinal()));
} }
else if (entity.getType().equals(EntityTypes.FOX)) {
// Not sure if this should be in here or in 1.14 PacketFactory
add(data, metadataFactory.foxVariant(properties.getProperty(propertyRegistry.getByName("fox_variant", FoxVariant.class)).ordinal()));
add(data, metadataFactory.foxProperties(
properties.getProperty(propertyRegistry.getByName("fox_sitting", Boolean.class)),
properties.getProperty(propertyRegistry.getByName("fox_crouching", Boolean.class)),
properties.getProperty(propertyRegistry.getByName("fox_sleeping", Boolean.class)),
properties.getProperty(propertyRegistry.getByName("fox_faceplanted", Boolean.class))
));
}
if (properties.getProperty(propertyRegistry.getByName("dinnerbone", Boolean.class))) { if (properties.getProperty(propertyRegistry.getByName("dinnerbone", Boolean.class))) {
add(data, metadataFactory.name(Component.text("Dinnerbone"))); add(data, metadataFactory.name(Component.text("Dinnerbone")));