Created
December 2, 2013 20:38
-
-
Save keir-nellyer/7758410 to your computer and use it in GitHub Desktop.
1.7.2 Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Accessing packets | |
private Object getMobPacket(){ | |
Location loc = entity.getLocation().subtract(0, 5, 0); | |
Class<?> mob_class = ReflectionHelper.getNMSClass("PacketPlayOutSpawnEntityLiving"); | |
Object mobPacket = null; | |
try { | |
mobPacket = mob_class.newInstance(); | |
Field a = ReflectionHelper.getField(mob_class, "a"); | |
a.setAccessible(true); | |
a.set(mobPacket, ENTITY_ID);//Entity ID | |
Field b = ReflectionHelper.getField(mob_class, "b"); | |
b.setAccessible(true); | |
b.set(mobPacket, (byte) EntityType.ENDER_DRAGON.getTypeId());//Mob type id | |
Field c = ReflectionHelper.getField(mob_class, "c"); | |
c.setAccessible(true); | |
c.set(mobPacket, loc.getBlockX());//X position | |
Field d = ReflectionHelper.getField(mob_class, "d"); | |
d.setAccessible(true); | |
d.set(mobPacket, loc.getBlockY());//Y position | |
Field e = ReflectionHelper.getField(mob_class, "e"); | |
e.setAccessible(true); | |
e.set(mobPacket, loc.getBlockZ());//Z position | |
Field i = ReflectionHelper.getField(mob_class, "i"); | |
i.setAccessible(true); | |
i.set(mobPacket, (byte) 0);//Yaw | |
Field j = ReflectionHelper.getField(mob_class, "j"); | |
j.setAccessible(true); | |
j.set(mobPacket, (byte) 0);//Pitch | |
Field k = ReflectionHelper.getField(mob_class, "k"); | |
k.setAccessible(true); | |
k.set(mobPacket, (byte) 0);//Head Pitch | |
Field f = ReflectionHelper.getField(mob_class, "f"); | |
f.setAccessible(true); | |
f.set(mobPacket, (byte) 0);//X velocity | |
Field g = ReflectionHelper.getField(mob_class, "g"); | |
g.setAccessible(true); | |
g.set(mobPacket, (byte) 0);//Y velocity | |
Field h = ReflectionHelper.getField(mob_class, "h"); | |
h.setAccessible(true); | |
h.set(mobPacket, (byte) 0);//Z velocity | |
Field l = ReflectionHelper.getField(mob_class, "l"); | |
l.setAccessible(true); | |
l.set(mobPacket, getWatcher()); | |
} catch (Throwable e1) { | |
e1.printStackTrace(); | |
} | |
return mobPacket; | |
} | |
private Object getDestroyEntityPacket(){ | |
Class<?> packet_class = ReflectionHelper.getNMSClass("PacketPlayOutEntityDestroy"); | |
Object packet = null; | |
try { | |
packet = packet_class.newInstance(); | |
Field a = ReflectionHelper.getField(packet_class, "a"); | |
a.setAccessible(true); | |
a.set(packet, new int[]{ENTITY_ID}); | |
} catch (Throwable e) { | |
e.printStackTrace(); | |
} | |
return packet; | |
} | |
private Object getMetadataPacket(Object watcher){ | |
Class<?> packet_class = ReflectionHelper.getNMSClass("PacketPlayOutEntityMetadata"); | |
Object packet = null; | |
try { | |
packet = packet_class.newInstance(); | |
Method watcher_c = ReflectionHelper.getMethodNoArgs(watcher.getClass(), "c"); | |
Field a = ReflectionHelper.getField(packet_class, "a"); | |
a.setAccessible(true); | |
a.set(packet, ENTITY_ID); | |
Field b = ReflectionHelper.getField(packet_class, "b"); | |
b.setAccessible(true); | |
b.set(packet, watcher_c.invoke(watcher)); | |
} catch (Throwable e) { | |
e.printStackTrace(); | |
} | |
return packet; | |
} | |
private Object getRespawnPacket(){ | |
Class<?> packet_class = ReflectionHelper.getNMSClass("PacketPlayOutRespawn"); | |
Object packet = null; | |
try { | |
packet = packet_class.newInstance(); | |
Field a = ReflectionHelper.getField(packet_class, "a"); | |
a.setAccessible(true); | |
a.set(packet, 1); | |
} catch (Throwable e) { | |
e.printStackTrace(); | |
} | |
return packet; | |
} | |
private Object getWatcher(){ | |
Class<?> watcher_class = ReflectionHelper.getNMSClass("DataWatcher"); | |
Object watcher = null; | |
try { | |
Constructor<?> constructor = watcher_class.getConstructor(net.minecraft.server.v1_7_R1.Entity.class); | |
watcher = constructor.newInstance(new Object[]{ null }); | |
Method a = ReflectionHelper.getMethod(watcher_class, "a", new Class<?>[]{int.class, Object.class}); | |
a.setAccessible(true); | |
a.invoke(watcher, 0, (byte) 0x20); | |
a.invoke(watcher, 6, ((float) (entity.isDead() ? 1 : entity.getHealth())) / Math.round(entity.getMaxHealth()) * 200); | |
a.invoke(watcher, 7, 0); | |
a.invoke(watcher, 8, (byte) 0); | |
a.invoke(watcher, 10, getDisplayName()); | |
a.invoke(watcher, 11, (byte) 1); | |
} catch (Throwable e) { | |
e.printStackTrace(); | |
} | |
return watcher; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment