-
-
Save anonymous/1a73f7e50bc702e052b0 to your computer and use it in GitHub Desktop.
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
@SuppressWarnings({ "unchecked", "rawtypes" }) | |
public static boolean spawnCustomMob (Location location, Object mob) { | |
try { | |
StormReflect.invokeObject(mob, StormReflect.getClass(NMSClass.ENTITY.getFullName()), "setPositionRotation", new Object[] {location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()}); | |
Class<?> superClass = mob.getClass().getSuperclass(); | |
Map d = (Map) StormReflect.getStaticField(StormReflect.getClass(NMSClass.ENTITY_TYPES.getFullName()), "d"); | |
Set<Class<?>> set = d.keySet(); | |
while(superClass.getSuperclass() != null && !set.contains(superClass)) | |
superClass = superClass.getSuperclass(); | |
String name = null; | |
for(Object en : d.entrySet()) { | |
Entry<Class<?>, String> ent = (Entry<Class<?>, String>) en; | |
if(ent.getKey().equals(superClass)) { | |
name = ent.getValue(); | |
break; | |
} | |
} | |
if(superClass == null || name == null) | |
return false; | |
Map f = (Map) StormReflect.getStaticField(StormReflect.getClass(NMSClass.ENTITY_TYPES.getFullName()), "f"); | |
int id = -1; | |
for(Object en : f.entrySet()) { | |
Entry<Class<?>, Integer> ent = (Entry<Class<?>, Integer>) en; | |
if(ent.getKey().equals(superClass)) { | |
id = ent.getValue(); | |
break; | |
} | |
} | |
if(id == -1) | |
return false; | |
Map c = (Map) StormReflect.getStaticField(StormReflect.getClass(NMSClass.ENTITY_TYPES.getFullName()), "c"); | |
Map e = (Map) StormReflect.getStaticField(StormReflect.getClass(NMSClass.ENTITY_TYPES.getFullName()), "e"); | |
Map g = (Map) StormReflect.getStaticField(StormReflect.getClass(NMSClass.ENTITY_TYPES.getFullName()), "g"); | |
c.put(name, mob.getClass()); | |
d.put(mob.getClass(), name); | |
e.put(Integer.valueOf(id), mob.getClass()); | |
f.put(mob.getClass(), Integer.valueOf(id)); | |
g.put(name, Integer.valueOf(id)); | |
StormReflect.invokeObject(StormReflect.getField(mob, StormReflect.getClass(NMSClass.ENTITY.getFullName()), "world"), StormReflect.getClass(NMSClass.WORLD.getFullName()), "addEntity", mob, SpawnReason.CUSTOM); | |
c.put(name, superClass); | |
d.put(superClass, name); | |
e.put(Integer.valueOf(id), superClass); | |
f.put(superClass, Integer.valueOf(id)); | |
g.put(name, Integer.valueOf(id)); | |
return true; | |
}catch(Exception e) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment