Hallo nochmal,
erstmal vorweg ich bin noch sehr neu im Gebiet net.minecraft usw.
Aber ich habe hier ein problem und würde mich auf einen Vorschlag freuen wie ich diesen beheben könnte.
Mc Version: 1.12
Code:
Es kommt kein error aber es spawnt auch kein Npc.
Würde mich sehr um eine Lösungstipp freuen
Vielen Dank
L.G
P.S Will aber bitte eig. keinen fertigen code
erstmal vorweg ich bin noch sehr neu im Gebiet net.minecraft usw.
Aber ich habe hier ein problem und würde mich auf einen Vorschlag freuen wie ich diesen beheben könnte.
Mc Version: 1.12
Code:
java:
package de.mor15Euro.magicapi.api.npc;
public class NPC extends Reflections {
private int entityID;
private Location loc;
private UUID uuid;
public NPC(String name, Location loc) {
entityID = (int)Math.ceil(Math.random() * 1000) + 3000;
this.uuid = UUID.randomUUID();
this.loc = loc;
}
public void spawn(Player p) {
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
setValue(packet, "a", entityID);
setValue(packet, "b", uuid);
setValue(packet, "c", (double)MathHelper.floor(loc.getX() * 32.0D));
setValue(packet, "d", (double)MathHelper.floor(loc.getY() * 32.0D));
setValue(packet, "e", (double)MathHelper.floor(loc.getZ() * 32.0D));
setValue(packet, "f", (byte) ((int) (loc.getYaw() * 256.0F / 360.0F)));
setValue(packet, "g", (byte) ((int) (loc.getPitch() * 256.0F / 360.0F)));
DataWatcher w = new DataWatcher(null);
setValue(packet, "h", w);
sendPacket(packet);
}
}
java:
package de.mor15Euro.magicapi.api.npc.utils;
public class Reflections {
public void setValue(Object obj, String name, Object value) {
try {
Field field = obj.getClass().getDeclaredField(name);
field.setAccessible(true);
field.set(obj, value);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAcces***ception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Object getValue(Object obj, String name) {
try {
Field field = obj.getClass().getDeclaredField(name);
field.setAccessible(true);
return field.get(obj);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAcces***ception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public void sendPacket(Packet<?> packet, Player p) {
((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
}
public void sendPacket(Packet<?> packet) {
for(Player p: Bukkit.getOnlinePlayers())
sendPacket(packet , p);
}
}
java:
package de.mor15Euro.magicapi.listener;
public class PlayerConnectionListener implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent e) {
new PacketReader(e.getPlayer()).inject();
NPC npc = new NPC("Hey", e.getPlayer().getLocation());
npc.spawn(e.getPlayer());
System.out.println("Spawn");
}
@EventHandler
public void onDisc(PlayerQuitEvent e) {
PacketReader.unInject(e.getPlayer());
}
}
Es kommt kein error aber es spawnt auch kein Npc.
Würde mich sehr um eine Lösungstipp freuen
Vielen Dank
L.G
P.S Will aber bitte eig. keinen fertigen code