implemented villager properties
This commit is contained in:
		
							parent
							
								
									f68d678a1c
								
							
						
					
					
						commit
						959f6241f4
					
				
					 15 changed files with 112 additions and 3 deletions
				
			
		| 
						 | 
					@ -0,0 +1,9 @@
 | 
				
			||||||
 | 
					package lol.pyr.znpcsplus.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public enum VillagerLevel {
 | 
				
			||||||
 | 
					    STONE,
 | 
				
			||||||
 | 
					    IRON,
 | 
				
			||||||
 | 
					    GOLD,
 | 
				
			||||||
 | 
					    EMERALD,
 | 
				
			||||||
 | 
					    DIAMOND
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,29 @@
 | 
				
			||||||
 | 
					package lol.pyr.znpcsplus.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public enum VillagerProfession {
 | 
				
			||||||
 | 
					    NONE(0),
 | 
				
			||||||
 | 
					    ARMORER(3),
 | 
				
			||||||
 | 
					    BUTCHER(4),
 | 
				
			||||||
 | 
					    CARTOGRAPHER(1),
 | 
				
			||||||
 | 
					    CLERIC(2),
 | 
				
			||||||
 | 
					    FARMER(0),
 | 
				
			||||||
 | 
					    FISHERMAN(0),
 | 
				
			||||||
 | 
					    FLETCHER(0),
 | 
				
			||||||
 | 
					    LEATHER_WORKER(4),
 | 
				
			||||||
 | 
					    LIBRARIAN(1),
 | 
				
			||||||
 | 
					    MASON(-1),
 | 
				
			||||||
 | 
					    NITWIT(5),
 | 
				
			||||||
 | 
					    SHEPHERD(0),
 | 
				
			||||||
 | 
					    TOOL_SMITH(3),
 | 
				
			||||||
 | 
					    WEAPON_SMITH(3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final int legacyId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    VillagerProfession(int legacyId) {
 | 
				
			||||||
 | 
					        this.legacyId = legacyId;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int getLegacyId() {
 | 
				
			||||||
 | 
					        return legacyId;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										11
									
								
								api/src/main/java/lol/pyr/znpcsplus/util/VillagerType.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								api/src/main/java/lol/pyr/znpcsplus/util/VillagerType.java
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,11 @@
 | 
				
			||||||
 | 
					package lol.pyr.znpcsplus.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public enum VillagerType {
 | 
				
			||||||
 | 
					    DESERT,
 | 
				
			||||||
 | 
					    JUNGLE,
 | 
				
			||||||
 | 
					    PLAINS,
 | 
				
			||||||
 | 
					    SAVANNA,
 | 
				
			||||||
 | 
					    SNOW,
 | 
				
			||||||
 | 
					    SWAMP,
 | 
				
			||||||
 | 
					    TAIGA
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -288,6 +288,9 @@ public class ZNpcsPlus extends JavaPlugin {
 | 
				
			||||||
        registerEnumParser(manager, SpellType.class, incorrectUsageMessage);
 | 
					        registerEnumParser(manager, SpellType.class, incorrectUsageMessage);
 | 
				
			||||||
        registerEnumParser(manager, FoxVariant.class, incorrectUsageMessage);
 | 
					        registerEnumParser(manager, FoxVariant.class, incorrectUsageMessage);
 | 
				
			||||||
        registerEnumParser(manager, FrogVariant.class, incorrectUsageMessage);
 | 
					        registerEnumParser(manager, FrogVariant.class, incorrectUsageMessage);
 | 
				
			||||||
 | 
					        registerEnumParser(manager, VillagerType.class, incorrectUsageMessage);
 | 
				
			||||||
 | 
					        registerEnumParser(manager, VillagerProfession.class, incorrectUsageMessage);
 | 
				
			||||||
 | 
					        registerEnumParser(manager, VillagerLevel.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))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -128,6 +128,9 @@ public class PropertySetCommand implements CommandHandler {
 | 
				
			||||||
                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());
 | 
					                if (type == FoxVariant.class) return context.suggestEnum(FoxVariant.values());
 | 
				
			||||||
                if (type == FrogVariant.class) return context.suggestEnum(FrogVariant.values());
 | 
					                if (type == FrogVariant.class) return context.suggestEnum(FrogVariant.values());
 | 
				
			||||||
 | 
					                if (type == VillagerType.class) return context.suggestEnum(VillagerType.values());
 | 
				
			||||||
 | 
					                if (type == VillagerProfession.class) return context.suggestEnum(VillagerProfession.values());
 | 
				
			||||||
 | 
					                if (type == VillagerLevel.class) return context.suggestEnum(VillagerLevel.values());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else if (context.argSize() == 4) {
 | 
					            else if (context.argSize() == 4) {
 | 
				
			||||||
                if (type == BlockState.class) {
 | 
					                if (type == BlockState.class) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,6 +41,9 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
 | 
				
			||||||
        registerEnumSerializer(SpellType.class);
 | 
					        registerEnumSerializer(SpellType.class);
 | 
				
			||||||
        registerEnumSerializer(FoxVariant.class);
 | 
					        registerEnumSerializer(FoxVariant.class);
 | 
				
			||||||
        registerEnumSerializer(FrogVariant.class);
 | 
					        registerEnumSerializer(FrogVariant.class);
 | 
				
			||||||
 | 
					        registerEnumSerializer(VillagerType.class);
 | 
				
			||||||
 | 
					        registerEnumSerializer(VillagerProfession.class);
 | 
				
			||||||
 | 
					        registerEnumSerializer(VillagerLevel.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        registerType("glow", NamedTextColor.class);
 | 
					        registerType("glow", NamedTextColor.class);
 | 
				
			||||||
        registerType("fire", false);
 | 
					        registerType("fire", false);
 | 
				
			||||||
| 
						 | 
					@ -186,8 +189,9 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
 | 
				
			||||||
        registerType("parrot_variant", 0); // TODO
 | 
					        registerType("parrot_variant", 0); // TODO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Villager
 | 
					        // Villager
 | 
				
			||||||
        registerType("villager_ethnicity", 1); // TODO: how tf does this work? probably need to look in mc src
 | 
					        registerType("villager_type", VillagerType.PLAINS);
 | 
				
			||||||
        registerType("villager_job", null); // TODO
 | 
					        registerType("villager_profession", VillagerProfession.NONE);
 | 
				
			||||||
 | 
					        registerType("villager_level", VillagerLevel.STONE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Show Golem
 | 
					        // Show Golem
 | 
				
			||||||
        registerType("pumpkin", true); // TODO
 | 
					        registerType("pumpkin", true); // TODO
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -86,4 +86,7 @@ public interface MetadataFactory {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Ghast
 | 
					    // Ghast
 | 
				
			||||||
    EntityData ghastAttacking(boolean attacking);
 | 
					    EntityData ghastAttacking(boolean attacking);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Villager
 | 
				
			||||||
 | 
					    EntityData villagerData(int type, int profession, int level);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -85,4 +85,9 @@ public class V1_10MetadataFactory extends V1_9MetadataFactory {
 | 
				
			||||||
    public EntityData ghastAttacking(boolean attacking) {
 | 
					    public EntityData ghastAttacking(boolean attacking) {
 | 
				
			||||||
        return newEntityData(12, EntityDataTypes.BOOLEAN, attacking);
 | 
					        return newEntityData(12, EntityDataTypes.BOOLEAN, attacking);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public EntityData villagerData(int type, int profession, int level) {
 | 
				
			||||||
 | 
					        return newEntityData(13, EntityDataTypes.INT, profession);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ package lol.pyr.znpcsplus.metadata;
 | 
				
			||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
 | 
					import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
 | 
				
			||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
 | 
					import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
 | 
				
			||||||
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
 | 
					import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
 | 
				
			||||||
 | 
					import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
 | 
				
			||||||
import lol.pyr.znpcsplus.util.CatVariant;
 | 
					import lol.pyr.znpcsplus.util.CatVariant;
 | 
				
			||||||
import lol.pyr.znpcsplus.util.CreeperState;
 | 
					import lol.pyr.znpcsplus.util.CreeperState;
 | 
				
			||||||
import lol.pyr.znpcsplus.util.ParrotVariant;
 | 
					import lol.pyr.znpcsplus.util.ParrotVariant;
 | 
				
			||||||
| 
						 | 
					@ -134,4 +135,9 @@ public class V1_14MetadataFactory extends V1_13MetadataFactory {
 | 
				
			||||||
    public EntityData ghastAttacking(boolean attacking) {
 | 
					    public EntityData ghastAttacking(boolean attacking) {
 | 
				
			||||||
        return newEntityData(14, EntityDataTypes.BOOLEAN, attacking);
 | 
					        return newEntityData(14, EntityDataTypes.BOOLEAN, attacking);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public EntityData villagerData(int type, int profession, int level) {
 | 
				
			||||||
 | 
					        return newEntityData(16, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ package lol.pyr.znpcsplus.metadata;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
 | 
					import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
 | 
				
			||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
 | 
					import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
 | 
				
			||||||
 | 
					import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
 | 
				
			||||||
import lol.pyr.znpcsplus.util.CatVariant;
 | 
					import lol.pyr.znpcsplus.util.CatVariant;
 | 
				
			||||||
import lol.pyr.znpcsplus.util.CreeperState;
 | 
					import lol.pyr.znpcsplus.util.CreeperState;
 | 
				
			||||||
import lol.pyr.znpcsplus.util.ParrotVariant;
 | 
					import lol.pyr.znpcsplus.util.ParrotVariant;
 | 
				
			||||||
| 
						 | 
					@ -118,4 +119,9 @@ public class V1_15MetadataFactory extends V1_14MetadataFactory {
 | 
				
			||||||
    public EntityData ghastAttacking(boolean attacking) {
 | 
					    public EntityData ghastAttacking(boolean attacking) {
 | 
				
			||||||
        return newEntityData(15, EntityDataTypes.BOOLEAN, attacking);
 | 
					        return newEntityData(15, EntityDataTypes.BOOLEAN, attacking);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public EntityData villagerData(int type, int profession, int level) {
 | 
				
			||||||
 | 
					        return newEntityData(17, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ package lol.pyr.znpcsplus.metadata;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
 | 
					import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
 | 
				
			||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
 | 
					import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
 | 
				
			||||||
 | 
					import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
 | 
				
			||||||
import lol.pyr.znpcsplus.util.CatVariant;
 | 
					import lol.pyr.znpcsplus.util.CatVariant;
 | 
				
			||||||
import lol.pyr.znpcsplus.util.CreeperState;
 | 
					import lol.pyr.znpcsplus.util.CreeperState;
 | 
				
			||||||
import lol.pyr.znpcsplus.util.ParrotVariant;
 | 
					import lol.pyr.znpcsplus.util.ParrotVariant;
 | 
				
			||||||
| 
						 | 
					@ -178,4 +179,9 @@ public class V1_17MetadataFactory extends V1_16MetadataFactory {
 | 
				
			||||||
    public EntityData ghastAttacking(boolean attacking) {
 | 
					    public EntityData ghastAttacking(boolean attacking) {
 | 
				
			||||||
        return newEntityData(16, EntityDataTypes.BOOLEAN, attacking);
 | 
					        return newEntityData(16, EntityDataTypes.BOOLEAN, attacking);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public EntityData villagerData(int type, int profession, int level) {
 | 
				
			||||||
 | 
					        return newEntityData(18, EntityDataTypes.VILLAGER_DATA, new VillagerData(type, profession, level));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -205,6 +205,11 @@ public class V1_8MetadataFactory implements MetadataFactory {
 | 
				
			||||||
        return newEntityData(16, EntityDataTypes.BYTE, (byte) (attacking ? 1 : 0));
 | 
					        return newEntityData(16, EntityDataTypes.BYTE, (byte) (attacking ? 1 : 0));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public EntityData villagerData(int type, int profession, int level) {
 | 
				
			||||||
 | 
					        return newEntityData(16, EntityDataTypes.INT, profession);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @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));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,4 +67,9 @@ public class V1_9MetadataFactory extends V1_8MetadataFactory {
 | 
				
			||||||
    public EntityData ghastAttacking(boolean attacking) {
 | 
					    public EntityData ghastAttacking(boolean attacking) {
 | 
				
			||||||
        return newEntityData(11, EntityDataTypes.BOOLEAN, attacking);
 | 
					        return newEntityData(11, EntityDataTypes.BOOLEAN, attacking);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public EntityData villagerData(int type, int profession, int level) {
 | 
				
			||||||
 | 
					        return newEntityData(12, EntityDataTypes.INT, profession);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -133,7 +133,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        register(builder(p, "villager", EntityTypes.VILLAGER)
 | 
					        register(builder(p, "villager", EntityTypes.VILLAGER)
 | 
				
			||||||
                .setHologramOffset(-0.025)
 | 
					                .setHologramOffset(-0.025)
 | 
				
			||||||
                .addProperties("hand"));
 | 
					                .addProperties("hand", "villager_type", "villager_profession", "villager_level"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        register(builder(p, "witch", EntityTypes.WITCH)
 | 
					        register(builder(p, "witch", EntityTypes.WITCH)
 | 
				
			||||||
                .setHologramOffset(-0.025)
 | 
					                .setHologramOffset(-0.025)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,8 @@
 | 
				
			||||||
package lol.pyr.znpcsplus.packets;
 | 
					package lol.pyr.znpcsplus.packets;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.github.retrooper.packetevents.PacketEvents;
 | 
				
			||||||
import com.github.retrooper.packetevents.PacketEventsAPI;
 | 
					import com.github.retrooper.packetevents.PacketEventsAPI;
 | 
				
			||||||
 | 
					import com.github.retrooper.packetevents.manager.server.ServerVersion;
 | 
				
			||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
 | 
					import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
 | 
				
			||||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
 | 
					import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
 | 
				
			||||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
 | 
					import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
 | 
				
			||||||
| 
						 | 
					@ -215,6 +217,18 @@ public class V1_8PacketFactory implements PacketFactory {
 | 
				
			||||||
        else if (entity.getType().equals(EntityTypes.GHAST)) {
 | 
					        else if (entity.getType().equals(EntityTypes.GHAST)) {
 | 
				
			||||||
            add(data, metadataFactory.ghastAttacking(properties.getProperty(propertyRegistry.getByName("attacking", Boolean.class))));
 | 
					            add(data, metadataFactory.ghastAttacking(properties.getProperty(propertyRegistry.getByName("attacking", Boolean.class))));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        else if (entity.getType().equals(EntityTypes.VILLAGER)) {
 | 
				
			||||||
 | 
					            VillagerProfession profession = properties.getProperty(propertyRegistry.getByName("villager_profession", VillagerProfession.class));
 | 
				
			||||||
 | 
					            int professionId = profession.ordinal();
 | 
				
			||||||
 | 
					            if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_14)) {
 | 
				
			||||||
 | 
					                professionId = profession.getLegacyId();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            add(data, metadataFactory.villagerData(
 | 
				
			||||||
 | 
					                    properties.getProperty(propertyRegistry.getByName("villager_type", VillagerType.class)).ordinal(),
 | 
				
			||||||
 | 
					                    professionId,
 | 
				
			||||||
 | 
					                    properties.getProperty(propertyRegistry.getByName("villager_level", VillagerLevel.class)).ordinal() + 1
 | 
				
			||||||
 | 
					            ));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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")));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue