change some properties to CustomTypeProperty
This commit is contained in:
		
							parent
							
								
									6128cac379
								
							
						
					
					
						commit
						6ebc60c11e
					
				
					 4 changed files with 4 additions and 79 deletions
				
			
		|  | @ -3,6 +3,7 @@ package lol.pyr.znpcsplus.entity; | |||
| import com.github.retrooper.packetevents.PacketEvents; | ||||
| import com.github.retrooper.packetevents.manager.server.ServerVersion; | ||||
| import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; | ||||
| import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose; | ||||
| import com.github.retrooper.packetevents.protocol.nbt.NBTCompound; | ||||
| import com.github.retrooper.packetevents.protocol.nbt.NBTInt; | ||||
| import com.github.retrooper.packetevents.protocol.nbt.NBTString; | ||||
|  | @ -385,7 +386,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { | |||
|         else if (ver.isNewerThanOrEquals(ServerVersion.V_1_14)) snowGolemIndex = 14; | ||||
|         else if (ver.isNewerThanOrEquals(ServerVersion.V_1_10)) snowGolemIndex = 12; | ||||
|         else snowGolemIndex = 10; | ||||
|         register(new DerpySnowgolemProperty(snowGolemIndex)); | ||||
|         register(new CustomTypeProperty<>("derpy_snowgolem", snowGolemIndex, false, EntityDataTypes.BYTE, b -> (byte) (b ? 0x00 : 0x10))); | ||||
| 
 | ||||
|         if (!ver.isNewerThanOrEquals(ServerVersion.V_1_10)) return; | ||||
|         // Polar Bear | ||||
|  | @ -458,7 +459,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { | |||
| 
 | ||||
|         if (!ver.isNewerThanOrEquals(ServerVersion.V_1_14)) return; | ||||
|         // Pose | ||||
|         register(new NpcPoseProperty()); | ||||
|         register(new CustomTypeProperty<>("pose", 6, NpcPose.STANDING, EntityDataTypes.ENTITY_POSE, npcPose -> EntityPose.valueOf(npcPose.name()))); | ||||
| 
 | ||||
|         // Villager | ||||
|         final int villagerIndex; | ||||
|  | @ -579,7 +580,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { | |||
|         register(new BooleanProperty("bashing", 18, false, legacyBooleans)); | ||||
| 
 | ||||
|         // Sniffer | ||||
|         register(new SnifferStateProperty(17)); | ||||
|         register(new CustomTypeProperty<>("sniffer_state", 17, SnifferState.IDLING, EntityDataTypes.SNIFFER_STATE, state -> com.github.retrooper.packetevents.protocol.entity.sniffer.SnifferState.valueOf(state.name()))); | ||||
|     } | ||||
| 
 | ||||
|     private void registerSerializer(PropertySerializer<?> serializer) { | ||||
|  |  | |||
|  | @ -1,23 +0,0 @@ | |||
| package lol.pyr.znpcsplus.entity.properties; | ||||
| 
 | ||||
| import com.github.retrooper.packetevents.protocol.entity.data.EntityData; | ||||
| import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; | ||||
| import lol.pyr.znpcsplus.entity.EntityPropertyImpl; | ||||
| import lol.pyr.znpcsplus.entity.PacketEntity; | ||||
| import org.bukkit.entity.Player; | ||||
| 
 | ||||
| import java.util.Map; | ||||
| 
 | ||||
| public class DerpySnowgolemProperty extends EntityPropertyImpl<Boolean> { | ||||
|     private final int index; | ||||
| 
 | ||||
|     public DerpySnowgolemProperty(int index) { | ||||
|         super("derpy_snowgolem", false, Boolean.class); | ||||
|         this.index = index; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) { | ||||
|         properties.put(index, new EntityData(index, EntityDataTypes.BYTE, (byte) (entity.getProperty(this) ? 0x00 : 0x10))); | ||||
|     } | ||||
| } | ||||
|  | @ -1,23 +0,0 @@ | |||
| package lol.pyr.znpcsplus.entity.properties; | ||||
| 
 | ||||
| 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.pose.EntityPose; | ||||
| import lol.pyr.znpcsplus.entity.EntityPropertyImpl; | ||||
| import lol.pyr.znpcsplus.entity.PacketEntity; | ||||
| import lol.pyr.znpcsplus.util.NpcPose; | ||||
| import org.bukkit.entity.Player; | ||||
| 
 | ||||
| import java.util.Map; | ||||
| 
 | ||||
| public class NpcPoseProperty extends EntityPropertyImpl<NpcPose> { | ||||
| 
 | ||||
|     public NpcPoseProperty() { | ||||
|         super("pose", NpcPose.STANDING, NpcPose.class); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) { | ||||
|         properties.put(6, newEntityData(6, EntityDataTypes.ENTITY_POSE, EntityPose.valueOf(entity.getProperty(this).name()))); | ||||
|     } | ||||
| } | ||||
|  | @ -1,30 +0,0 @@ | |||
| package lol.pyr.znpcsplus.entity.properties; | ||||
| 
 | ||||
| import com.github.retrooper.packetevents.protocol.entity.data.EntityData; | ||||
| import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; | ||||
| import lol.pyr.znpcsplus.entity.EntityPropertyImpl; | ||||
| import lol.pyr.znpcsplus.entity.PacketEntity; | ||||
| import lol.pyr.znpcsplus.util.SnifferState; | ||||
| import org.bukkit.entity.Player; | ||||
| 
 | ||||
| import java.util.Map; | ||||
| 
 | ||||
| public class SnifferStateProperty extends EntityPropertyImpl<SnifferState> { | ||||
|     private final int index; | ||||
| 
 | ||||
|     public SnifferStateProperty(int index) { | ||||
|         super("sniffer_state", SnifferState.IDLING, SnifferState.class); | ||||
|         this.index = index; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) { | ||||
|         SnifferState state = entity.getProperty(this); | ||||
|         if (state == null) return; | ||||
|         try { | ||||
|             properties.put(index, newEntityData(index, EntityDataTypes.SNIFFER_STATE, com.github.retrooper.packetevents.protocol.entity.sniffer.SnifferState.valueOf(state.name()))); | ||||
|         } catch (IllegalArgumentException e) { | ||||
|             // ignore | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in a new issue