fix object data
This commit is contained in:
		
							parent
							
								
									08af20f5ad
								
							
						
					
					
						commit
						a7d7fd2748
					
				
					 7 changed files with 33 additions and 17 deletions
				
			
		|  | @ -5,7 +5,7 @@ | ||||||
|     <option name="linkedExternalProjectsSettings"> |     <option name="linkedExternalProjectsSettings"> | ||||||
|       <GradleProjectSettings> |       <GradleProjectSettings> | ||||||
|         <option name="externalProjectPath" value="$PROJECT_DIR$" /> |         <option name="externalProjectPath" value="$PROJECT_DIR$" /> | ||||||
|         <option name="gradleHome" value="" /> |         <option name="gradleJvm" value="17" /> | ||||||
|         <option name="modules"> |         <option name="modules"> | ||||||
|           <set> |           <set> | ||||||
|             <option value="$PROJECT_DIR$" /> |             <option value="$PROJECT_DIR$" /> | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ import com.github.retrooper.packetevents.wrapper.PacketWrapper; | ||||||
| import com.github.retrooper.packetevents.wrapper.play.server.*; | import com.github.retrooper.packetevents.wrapper.play.server.*; | ||||||
| import me.tofaa.entitylib.EntityLib; | import me.tofaa.entitylib.EntityLib; | ||||||
| import me.tofaa.entitylib.meta.EntityMeta; | import me.tofaa.entitylib.meta.EntityMeta; | ||||||
|  | import me.tofaa.entitylib.meta.types.ObjectData; | ||||||
| import org.jetbrains.annotations.NotNull; | import org.jetbrains.annotations.NotNull; | ||||||
| 
 | 
 | ||||||
| import java.util.*; | import java.util.*; | ||||||
|  | @ -40,6 +41,11 @@ public class WrapperEntity { | ||||||
|         if (spawned) return false; |         if (spawned) return false; | ||||||
|         this.location = location; |         this.location = location; | ||||||
|         this.spawned = true; |         this.spawned = true; | ||||||
|  | 
 | ||||||
|  |         int data = 0; | ||||||
|  |         if (meta instanceof ObjectData) { | ||||||
|  |             data = ((ObjectData) meta).getObjectData(); | ||||||
|  |         } | ||||||
|         sendPacketToViewers( |         sendPacketToViewers( | ||||||
|                 new WrapperPlayServerSpawnEntity( |                 new WrapperPlayServerSpawnEntity( | ||||||
|                         entityId, |                         entityId, | ||||||
|  | @ -49,7 +55,7 @@ public class WrapperEntity { | ||||||
|                         location.getPitch(), |                         location.getPitch(), | ||||||
|                         location.getYaw(), |                         location.getYaw(), | ||||||
|                         location.getYaw(), |                         location.getYaw(), | ||||||
|                         0, |                         data, | ||||||
|                         Optional.empty() |                         Optional.empty() | ||||||
|                 ) |                 ) | ||||||
|         ); |         ); | ||||||
|  | @ -93,6 +99,12 @@ public class WrapperEntity { | ||||||
|         viewers.forEach(uuid -> EntityLib.sendPacket(uuid, packet)); |         viewers.forEach(uuid -> EntityLib.sendPacket(uuid, packet)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public void sendPacketsToViewers(PacketWrapper<?>... wrappers) { | ||||||
|  |         for (PacketWrapper<?> wrapper : wrappers) { | ||||||
|  |             sendPacketToViewers(wrapper); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public boolean addViewer(UUID uuid) { |     public boolean addViewer(UUID uuid) { | ||||||
|         if (!viewers.add(uuid)) { |         if (!viewers.add(uuid)) { | ||||||
|             return false; |             return false; | ||||||
|  |  | ||||||
|  | @ -109,6 +109,7 @@ public class WrapperEntityEquipment { | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|     public void refresh() { |     public void refresh() { | ||||||
|         this.entity.sendPacketToViewers(createPacket()); |         this.entity.sendPacketToViewers(createPacket()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								test-plugin/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								test-plugin/.gitignore
									
									
									
									
										vendored
									
									
								
							|  | @ -4,6 +4,8 @@ build/ | ||||||
| !**/src/main/**/build/ | !**/src/main/**/build/ | ||||||
| !**/src/test/**/build/ | !**/src/test/**/build/ | ||||||
| 
 | 
 | ||||||
|  | run | ||||||
|  | 
 | ||||||
| ### IntelliJ IDEA ### | ### IntelliJ IDEA ### | ||||||
| .idea/modules.xml | .idea/modules.xml | ||||||
| .idea/jarRepositories.xml | .idea/jarRepositories.xml | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| plugins { | plugins { | ||||||
|     id 'java' |     id 'java' | ||||||
|     id 'com.github.johnrengelman.shadow' version '7.1.2' |     id 'com.github.johnrengelman.shadow' version '7.1.2' | ||||||
|     id("io.papermc.paperweight.userdev") version "1.5.11" |     //id("io.papermc.paperweight.userdev") version "1.5.11" | ||||||
|     id 'xyz.jpenilla.run-paper' version '2.2.2' |     id 'xyz.jpenilla.run-paper' version '2.2.2' | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -25,7 +25,17 @@ repositories { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| dependencies { | dependencies { | ||||||
|     paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT") |     compileOnly('org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT') | ||||||
|     compileOnly('com.github.retrooper.packetevents:spigot:2.0.2') |     compileOnly('com.github.retrooper.packetevents:spigot:2.0.2') | ||||||
|     implementation project(':') |     implementation project(':') | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | tasks { | ||||||
|  |     runServer { | ||||||
|  |         minecraftVersion("1.20.1") | ||||||
|  | 
 | ||||||
|  |         downloadPlugins { | ||||||
|  |             modrinth('packetevents', '2.2.0') | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -4,6 +4,7 @@ import com.github.retrooper.packetevents.PacketEvents; | ||||||
| import com.github.retrooper.packetevents.protocol.player.InteractionHand; | import com.github.retrooper.packetevents.protocol.player.InteractionHand; | ||||||
| import com.github.retrooper.packetevents.protocol.player.User; | import com.github.retrooper.packetevents.protocol.player.User; | ||||||
| import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity; | import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity; | ||||||
|  | import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerCloseWindow; | ||||||
| import me.tofaa.entitylib.entity.EntityInteractionProcessor; | import me.tofaa.entitylib.entity.EntityInteractionProcessor; | ||||||
| import me.tofaa.entitylib.entity.WrapperEntity; | import me.tofaa.entitylib.entity.WrapperEntity; | ||||||
| import org.bukkit.plugin.java.JavaPlugin; | import org.bukkit.plugin.java.JavaPlugin; | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ public class TestEntityCommand implements CommandExecutor { | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { |     public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||||||
|         if (!(sender instanceof Player)) return false; |         if (!(sender instanceof Player )) return false; | ||||||
|         Player player = (Player) sender; |         Player player = (Player) sender; | ||||||
|         if (entity == null) { |         if (entity == null) { | ||||||
|             entity = (WrapperLivingEntity) EntityLib.createEntity(UUID.randomUUID(), EntityTypes.ZOMBIE); |             entity = (WrapperLivingEntity) EntityLib.createEntity(UUID.randomUUID(), EntityTypes.ZOMBIE); | ||||||
|  | @ -37,7 +37,7 @@ public class TestEntityCommand implements CommandExecutor { | ||||||
|             entity.spawn(SpigotConversionUtil.fromBukkitLocation(player.getLocation())); |             entity.spawn(SpigotConversionUtil.fromBukkitLocation(player.getLocation())); | ||||||
|         } |         } | ||||||
|         ItemStack held = player.getInventory().getItemInMainHand(); |         ItemStack held = player.getInventory().getItemInMainHand(); | ||||||
|         if (held != null && !held.getType().isAir()) { |         if (!held.getType().isAir()) { | ||||||
|             entity.getEquipment().setBoots(SpigotConversionUtil.fromBukkitItemStack(held)); |             entity.getEquipment().setBoots(SpigotConversionUtil.fromBukkitItemStack(held)); | ||||||
|         } |         } | ||||||
|         EntityMeta meta = entity.getMeta(); |         EntityMeta meta = entity.getMeta(); | ||||||
|  | @ -50,17 +50,7 @@ public class TestEntityCommand implements CommandExecutor { | ||||||
|         player.sendMessage("on fire: " + meta.isOnFire()); |         player.sendMessage("on fire: " + meta.isOnFire()); | ||||||
|         player.sendMessage("glowing: " + meta.hasGlowingEffect()); |         player.sendMessage("glowing: " + meta.hasGlowingEffect()); | ||||||
| 
 | 
 | ||||||
| 
 |         entity.refresh(); | ||||||
|         WrapperEntity e = EntityLib.createEntity(UUID.randomUUID(), EntityTypes.ARMOR_STAND); |  | ||||||
|         int entityId = e.getEntityId(); // You can set the entityId provider to change this, WrapperEntity#ID_PROVIDER |  | ||||||
|         if (e == null) { |  | ||||||
|             throw new RuntimeException("Error creating entity meta"); // Only happens if the entity meta is null/invalid. |  | ||||||
|         } |  | ||||||
|         ArmorStandMeta m = (ArmorStandMeta) e.getMeta(); |  | ||||||
|         m.setInvisible(true); |  | ||||||
|         e.spawn(new Location(1, 2, 3, 4, 5)); |  | ||||||
|         e.addViewer(player.getUniqueId()); |  | ||||||
| 
 |  | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue