|
@@ -23,67 +23,75 @@ import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
|
|
|
import org.bukkit.entity.*;
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
import me.hammerle.kp.snuviscript.ScriptEvents;
|
|
|
-import net.minecraft.core.BlockPosition;
|
|
|
-import net.minecraft.core.IRegistry;
|
|
|
-import net.minecraft.nbt.MojangsonParser;
|
|
|
-import net.minecraft.nbt.NBTTagCompound;
|
|
|
+import net.minecraft.core.BlockPos;
|
|
|
+import net.minecraft.core.Registry;
|
|
|
+import net.minecraft.nbt.CompoundTag;
|
|
|
+import net.minecraft.nbt.TagParser;
|
|
|
import net.minecraft.network.protocol.Packet;
|
|
|
-import net.minecraft.network.protocol.game.*;
|
|
|
-import net.minecraft.server.level.EntityPlayer;
|
|
|
-import net.minecraft.server.level.WorldServer;
|
|
|
-import net.minecraft.server.network.PlayerConnection;
|
|
|
+import net.minecraft.server.level.ServerLevel;
|
|
|
+import net.minecraft.server.level.ServerPlayer;
|
|
|
+import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
|
-import net.minecraft.world.entity.EntityCreature;
|
|
|
-import net.minecraft.world.entity.EntityLiving;
|
|
|
-import net.minecraft.world.entity.EntityTypes;
|
|
|
-import net.minecraft.world.entity.EnumCreatureType;
|
|
|
-import net.minecraft.world.entity.item.EntityItem;
|
|
|
-import net.minecraft.world.entity.monster.EntityMonster;
|
|
|
-import net.minecraft.world.entity.projectile.EntityArrow;
|
|
|
-import net.minecraft.world.entity.projectile.EntityFireballFireball;
|
|
|
-import net.minecraft.world.entity.projectile.EntityFireworks;
|
|
|
-import net.minecraft.world.entity.projectile.EntityWitherSkull;
|
|
|
-import net.minecraft.world.level.block.entity.TileEntity;
|
|
|
-import net.minecraft.world.level.block.state.IBlockData;
|
|
|
-import net.minecraft.world.entity.ai.attributes.AttributeDefaults;
|
|
|
-import net.minecraft.world.entity.ai.attributes.AttributeProvider;
|
|
|
-import net.minecraft.world.entity.ai.attributes.GenericAttributes;
|
|
|
+import net.minecraft.world.entity.EntityType;
|
|
|
+import net.minecraft.world.entity.MobCategory;
|
|
|
+import net.minecraft.world.entity.PathfinderMob;
|
|
|
+import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
|
|
+import net.minecraft.world.entity.ai.attributes.Attributes;
|
|
|
+import net.minecraft.world.entity.ai.attributes.DefaultAttributes;
|
|
|
+import net.minecraft.world.entity.ai.goal.FloatGoal;
|
|
|
+import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
|
|
|
+import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
|
|
|
+import net.minecraft.world.entity.item.ItemEntity;
|
|
|
+import net.minecraft.world.entity.monster.Monster;
|
|
|
+import net.minecraft.world.level.Level;
|
|
|
+import net.minecraft.world.level.block.entity.BlockEntity;
|
|
|
+import net.minecraft.world.phys.Vec3;
|
|
|
+import net.minecraft.network.protocol.game.ClientboundAddMobPacket;
|
|
|
+import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
|
|
|
+import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket;
|
|
|
+import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
|
|
|
+import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket;
|
|
|
|
|
|
public class NMS {
|
|
|
private final static HashMap<String, DamageSource> DAMAGE_SOURCES = new HashMap<>();
|
|
|
|
|
|
- private static EntityTypes<RawHuman.WrapperHuman> HUMAN_TYPE;
|
|
|
+ private static EntityType<RawHuman.WrapperHuman> HUMAN_TYPE;
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public static void init() {
|
|
|
try {
|
|
|
- Method m = EntityTypes.class.getDeclaredMethod("a", String.class,
|
|
|
- EntityTypes.Builder.class);
|
|
|
+ Method m = EntityType.class.getDeclaredMethod("a", String.class,
|
|
|
+ EntityType.Builder.class);
|
|
|
m.setAccessible(true);
|
|
|
+
|
|
|
HUMAN_TYPE =
|
|
|
- (EntityTypes<RawHuman.WrapperHuman>) m.invoke(null, "human", EntityTypes.Builder
|
|
|
- .a(RawHuman.WrapperHuman::new, EnumCreatureType.a).a(0.6f, 1.95f));
|
|
|
+ (EntityType<RawHuman.WrapperHuman>) m.invoke(null, "human", EntityType.Builder
|
|
|
+ .of(RawHuman.WrapperHuman::new, MobCategory.CREATURE)
|
|
|
+ .sized(0.6f, 1.95f));
|
|
|
|
|
|
final Field unsafeField = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
|
|
unsafeField.setAccessible(true);
|
|
|
final sun.misc.Unsafe unsafe = (sun.misc.Unsafe) unsafeField.get(null);
|
|
|
|
|
|
- Field attributesMapField = AttributeDefaults.class.getDeclaredField("b");
|
|
|
+ Field attributesMapField = DefaultAttributes.class.getDeclaredField("b");
|
|
|
attributesMapField.setAccessible(true);
|
|
|
|
|
|
Object base = unsafe.staticFieldBase(attributesMapField);
|
|
|
long offset = unsafe.staticFieldOffset(attributesMapField);
|
|
|
|
|
|
- Map<EntityTypes<? extends EntityLiving>, AttributeProvider> attributesMap =
|
|
|
- (Map<EntityTypes<? extends EntityLiving>, AttributeProvider>) attributesMapField
|
|
|
+ Map<EntityType<? extends net.minecraft.world.entity.LivingEntity>, AttributeSupplier> attributesMap =
|
|
|
+ (Map<EntityType<? extends net.minecraft.world.entity.LivingEntity>, AttributeSupplier>) attributesMapField
|
|
|
.get(null);
|
|
|
attributesMap = new HashMap<>(attributesMap);
|
|
|
attributesMap.put(HUMAN_TYPE,
|
|
|
- EntityMonster.fD().a(GenericAttributes.a, 20.0).a(GenericAttributes.f, 1)
|
|
|
- .a(GenericAttributes.d, 0.1).a(GenericAttributes.h).a());
|
|
|
+ Monster.createMonsterAttributes().add(Attributes.MAX_HEALTH, 20.0)
|
|
|
+ .add(Attributes.ATTACK_DAMAGE, 1)
|
|
|
+ .add(Attributes.MOVEMENT_SPEED, 0.1).add(Attributes.ATTACK_SPEED)
|
|
|
+ .build());
|
|
|
+
|
|
|
unsafe.putObject(base, offset, attributesMap);
|
|
|
|
|
|
- AttributeDefaults.a();
|
|
|
+ DefaultAttributes.validate();
|
|
|
} catch(Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
KajetansPlugin.warn(ex.getMessage());
|
|
@@ -104,28 +112,59 @@ public class NMS {
|
|
|
public void setName(String name);
|
|
|
}
|
|
|
|
|
|
+ private static void setId(net.minecraft.world.entity.Entity e, int id) {
|
|
|
+ e.setId(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int getId(net.minecraft.world.entity.Entity e) {
|
|
|
+ return e.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static UUID getUUID(net.minecraft.world.entity.Entity e) {
|
|
|
+ return e.getUUID();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void moveTo(net.minecraft.world.entity.Entity e, double x, double y, double z,
|
|
|
+ float yaw, float pitch) {
|
|
|
+ e.moveTo(x, y, z, yaw, pitch);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Level getWorld(net.minecraft.world.entity.Entity e) {
|
|
|
+ return e.getLevel();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static GameProfile getGameProfile(net.minecraft.world.entity.player.Player e) {
|
|
|
+ return e.getGameProfile();
|
|
|
+ }
|
|
|
+
|
|
|
private static class RawHuman extends CraftCreature implements Human {
|
|
|
- private static class WrapperHuman extends EntityCreature {
|
|
|
- private EntityPlayer player;
|
|
|
+ private static class WrapperHuman extends PathfinderMob {
|
|
|
+ private ServerPlayer player;
|
|
|
|
|
|
- public WrapperHuman(EntityTypes<? extends WrapperHuman> type,
|
|
|
- net.minecraft.world.level.World world) {
|
|
|
+ public WrapperHuman(EntityType<? extends WrapperHuman> type,
|
|
|
+ Level world) {
|
|
|
super(type, world);
|
|
|
setPlayer("Default", world);
|
|
|
}
|
|
|
|
|
|
- private void setPlayer(String name, net.minecraft.world.level.World world) {
|
|
|
- player = new EntityPlayer(getCraftServer().getServer(), (WorldServer) world,
|
|
|
- new GameProfile(cm(), name));
|
|
|
- player.e(getBukkitEntity().getEntityId());
|
|
|
+ private void setPlayer(String name, Level world) {
|
|
|
+ player = new ServerPlayer(getCraftServer().getServer(), (ServerLevel) world,
|
|
|
+ new GameProfile(NMS.getUUID(this), name));
|
|
|
+ NMS.setId(player, NMS.getId(this));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean a(DamageSource ds, float amount) {
|
|
|
+ public void tick() {
|
|
|
+ super.tick();
|
|
|
+ setYRot(getYHeadRot());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean hurt(DamageSource ds, float amount) {
|
|
|
if(ScriptEvents.onHumanHurt(ds, getWrappedEntity(), amount)) {
|
|
|
return false;
|
|
|
}
|
|
|
- return super.a(ds, amount);
|
|
|
+ return super.hurt(ds, amount);
|
|
|
}
|
|
|
|
|
|
public RawHuman getWrappedEntity() {
|
|
@@ -137,66 +176,68 @@ public class NMS {
|
|
|
return getWrappedEntity();
|
|
|
}
|
|
|
|
|
|
- public EntityPlayer update(PacketPlayOutSpawnEntityLiving p) {
|
|
|
- player.e(p.b()); // set id, get id
|
|
|
- player.a(p.e(), p.f(), p.g(), 0.0f, 0.0f);
|
|
|
+ public ServerPlayer update(ClientboundAddMobPacket p) {
|
|
|
+ NMS.setId(player, p.getId());
|
|
|
+ NMS.moveTo(player, p.getX(), p.getY(), p.getZ(), 0.0f, 0.0f);
|
|
|
return player;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void b(NBTTagCompound nbt) {
|
|
|
- super.b(nbt);
|
|
|
+ public void addAdditionalSaveData(CompoundTag nbt) {
|
|
|
+ super.addAdditionalSaveData(nbt);
|
|
|
|
|
|
- GameProfile gp = player.fp();
|
|
|
- nbt.a("HumanName", gp.getName());
|
|
|
+ GameProfile gp = NMS.getGameProfile(player);
|
|
|
+ nbt.putString("HumanName", gp.getName());
|
|
|
|
|
|
Collection<Property> c = gp.getProperties().get("textures");
|
|
|
for(Property p : c) {
|
|
|
if(p.getName().equals("textures")) {
|
|
|
- nbt.a("HumanTexture", p.getValue());
|
|
|
- nbt.a("HumanSignature", p.getSignature());
|
|
|
+ nbt.putString("HumanTexture", p.getValue());
|
|
|
+ nbt.putString("HumanSignature", p.getSignature());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void a(NBTTagCompound nbt) {
|
|
|
- super.a(nbt);
|
|
|
- if(nbt.b("HumanName", 8)) {
|
|
|
- String name = nbt.l("HumanName");
|
|
|
- setPlayer(name, player.t);
|
|
|
+ public void readAdditionalSaveData(CompoundTag nbt) {
|
|
|
+ super.readAdditionalSaveData(nbt);
|
|
|
+ if(nbt.contains("HumanName", CompoundTag.TAG_STRING)) {
|
|
|
+ String name = nbt.getString("HumanName");
|
|
|
+ setPlayer(name, NMS.getWorld(player));
|
|
|
}
|
|
|
- if(nbt.b("HumanTexture", 8) && nbt.b("HumanSignature", 8)) {
|
|
|
- String texture = nbt.l("HumanTexture");
|
|
|
- String signature = nbt.l("HumanSignature");
|
|
|
+ if(nbt.contains("HumanTexture", CompoundTag.TAG_STRING)
|
|
|
+ && nbt.contains("HumanSignature", CompoundTag.TAG_STRING)) {
|
|
|
+ String texture = nbt.getString("HumanTexture");
|
|
|
+ String signature = nbt.getString("HumanSignature");
|
|
|
setSkinWithoutPacket(texture, signature);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void updatePosition() {
|
|
|
Location l = getBukkitEntity().getLocation();
|
|
|
- player.a(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
|
|
|
+ NMS.moveTo(player, l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
|
|
|
}
|
|
|
|
|
|
public void setSkinWithoutPacket(String texture, String signature) {
|
|
|
- GameProfile gp = player.fp();
|
|
|
+ GameProfile gp = NMS.getGameProfile(player);
|
|
|
gp.getProperties().clear();
|
|
|
gp.getProperties().put("textures", new Property("textures", texture, signature));
|
|
|
}
|
|
|
|
|
|
private void sync() {
|
|
|
updatePosition();
|
|
|
- PacketPlayOutPlayerInfo info = new PacketPlayOutPlayerInfo(
|
|
|
- PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, player);
|
|
|
- PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(player);
|
|
|
+ ClientboundPlayerInfoPacket info = new ClientboundPlayerInfoPacket(
|
|
|
+ ClientboundPlayerInfoPacket.Action.ADD_PLAYER, player);
|
|
|
+ ClientboundAddPlayerPacket spawn = new ClientboundAddPlayerPacket(player);
|
|
|
|
|
|
Location center = getBukkitEntity().getLocation();
|
|
|
- for(EntityPlayer p : ((WorldServer) this.W()).z()) {
|
|
|
+
|
|
|
+ for(ServerPlayer p : ((ServerLevel) NMS.getWorld(this)).players()) {
|
|
|
double distance = center.distanceSquared(p.getBukkitEntity().getLocation());
|
|
|
if(distance < 100.0) {
|
|
|
- p.b.a(info);
|
|
|
- p.b.a(spawn);
|
|
|
+ p.connection.send(info);
|
|
|
+ p.connection.send(spawn);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -207,9 +248,24 @@ public class NMS {
|
|
|
}
|
|
|
|
|
|
public void setName(String name) {
|
|
|
- setPlayer(name, player.t);
|
|
|
+ setPlayer(name, NMS.getWorld(player));
|
|
|
sync();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void registerGoals() {
|
|
|
+ this.goalSelector.addGoal(0, new FloatGoal(this));
|
|
|
+ this.goalSelector.addGoal(1,
|
|
|
+ new LookAtPlayerGoal(this, net.minecraft.server.level.ServerPlayer.class,
|
|
|
+ 6.0f));
|
|
|
+ this.goalSelector.addGoal(2, new RandomLookAroundGoal(this));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setDeltaMovement(Vec3 velocity) {}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setDeltaMovement(double x, double y, double z) {}
|
|
|
}
|
|
|
|
|
|
public final WrapperHuman human;
|
|
@@ -222,12 +278,12 @@ public class NMS {
|
|
|
|
|
|
private RawHuman(WrapperHuman human, Location l, PlayerProfile profile) {
|
|
|
this(human);
|
|
|
- human.a(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
|
|
|
- human.W().b(human);
|
|
|
+ NMS.moveTo(human, l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
|
|
|
+ ((net.minecraft.world.level.LevelWriter) NMS.getWorld(human)).addFreshEntity(human);
|
|
|
}
|
|
|
|
|
|
public RawHuman(Location l, PlayerProfile profile) {
|
|
|
- this(HUMAN_TYPE.a(map(l.getWorld())), l, profile);
|
|
|
+ this(HUMAN_TYPE.create(map(l.getWorld())), l, profile);
|
|
|
}
|
|
|
|
|
|
public void setSkin(String texture, String signature) {
|
|
@@ -243,71 +299,71 @@ public class NMS {
|
|
|
return new RawHuman(l, Bukkit.createProfile(UUID.randomUUID(), name));
|
|
|
}
|
|
|
|
|
|
- private static class PluginConnection extends PlayerConnection {
|
|
|
- public PluginConnection(PlayerConnection c) {
|
|
|
- super(getCraftServer().getServer(), c.a, c.b);
|
|
|
+ private static class PluginConnection extends ServerGamePacketListenerImpl {
|
|
|
+ public PluginConnection(ServerGamePacketListenerImpl c) {
|
|
|
+ super(getCraftServer().getServer(), c.connection, c.player);
|
|
|
}
|
|
|
|
|
|
- @SuppressWarnings("deprecation")
|
|
|
private RawHuman.WrapperHuman getById(int id) {
|
|
|
- net.minecraft.world.entity.Entity ent = b.x().b(id);
|
|
|
+ net.minecraft.world.entity.Entity ent = player.getLevel().getEntity(id);
|
|
|
if(ent instanceof RawHuman.WrapperHuman) {
|
|
|
return (RawHuman.WrapperHuman) ent;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private boolean handle(PacketPlayOutSpawnEntityLiving p) {
|
|
|
- if(p.d() != IRegistry.Z.a(HUMAN_TYPE)) {
|
|
|
+ private boolean handle(ClientboundAddMobPacket p) {
|
|
|
+ if(p.getType() != Registry.ENTITY_TYPE.getId(HUMAN_TYPE)) {
|
|
|
return false;
|
|
|
}
|
|
|
- UUID uuid = p.c();
|
|
|
+ UUID uuid = p.getUUID();
|
|
|
Entity ent = Bukkit.getEntity(uuid);
|
|
|
if(!(ent instanceof RawHuman)) {
|
|
|
return false;
|
|
|
}
|
|
|
RawHuman raw = (RawHuman) ent;
|
|
|
- EntityPlayer player = raw.human.update(p);
|
|
|
- PacketPlayOutPlayerInfo info = new PacketPlayOutPlayerInfo(
|
|
|
- PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, player);
|
|
|
- PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(player);
|
|
|
- super.a(info);
|
|
|
- super.a(spawn);
|
|
|
+ ServerPlayer player = raw.human.update(p);
|
|
|
+ ClientboundPlayerInfoPacket info = new ClientboundPlayerInfoPacket(
|
|
|
+ ClientboundPlayerInfoPacket.Action.ADD_PLAYER, player);
|
|
|
+ ClientboundAddPlayerPacket spawn = new ClientboundAddPlayerPacket(player);
|
|
|
+
|
|
|
+ super.send(info);
|
|
|
+ super.send(spawn);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- private boolean handle(PacketPlayOutEntityMetadata p) {
|
|
|
- return getById(p.c()) != null;
|
|
|
+ private boolean handle(ClientboundSetEntityDataPacket p) {
|
|
|
+ return getById(p.getId()) != null;
|
|
|
}
|
|
|
|
|
|
- private void handle(PacketPlayOutEntityDestroy p) {
|
|
|
- for(int id : p.b()) {
|
|
|
+ private void handle(ClientboundRemoveEntitiesPacket p) {
|
|
|
+ for(int id : p.getEntityIds()) {
|
|
|
RawHuman.WrapperHuman human = getById(id);
|
|
|
if(human != null) {
|
|
|
- PacketPlayOutPlayerInfo remove = new PacketPlayOutPlayerInfo(
|
|
|
- PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, human.player);
|
|
|
- super.a(remove);
|
|
|
+ ClientboundPlayerInfoPacket remove = new ClientboundPlayerInfoPacket(
|
|
|
+ ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, human.player);
|
|
|
+ super.send(remove);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void a(Packet<?> p) {
|
|
|
- if(p instanceof PacketPlayOutSpawnEntityLiving
|
|
|
- && handle((PacketPlayOutSpawnEntityLiving) p)) {
|
|
|
+ public void send(Packet<?> p) {
|
|
|
+ if(p instanceof ClientboundAddMobPacket
|
|
|
+ && handle((ClientboundAddMobPacket) p)) {
|
|
|
return;
|
|
|
- } else if(p instanceof PacketPlayOutEntityMetadata
|
|
|
- && handle((PacketPlayOutEntityMetadata) p)) {
|
|
|
+ } else if(p instanceof ClientboundSetEntityDataPacket
|
|
|
+ && handle((ClientboundSetEntityDataPacket) p)) {
|
|
|
return;
|
|
|
- } else if(p instanceof PacketPlayOutEntityDestroy) {
|
|
|
- handle((PacketPlayOutEntityDestroy) p);
|
|
|
+ } else if(p instanceof ClientboundRemoveEntitiesPacket) {
|
|
|
+ handle((ClientboundRemoveEntitiesPacket) p);
|
|
|
}
|
|
|
- super.a(p);
|
|
|
+ super.send(p);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void patch(Player p) {
|
|
|
- map(p).b = new PluginConnection(map(p).b);
|
|
|
+ map(p).connection = new PluginConnection(map(p).connection);
|
|
|
}
|
|
|
|
|
|
public static DamageSource getCurrentDamageSource() {
|
|
@@ -315,20 +371,20 @@ public class NMS {
|
|
|
}
|
|
|
|
|
|
public static Entity getImmediateSource(DamageSource ds) {
|
|
|
- if(ds.k() == null) {
|
|
|
+ if(ds.getDirectEntity() == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- return map(ds.k());
|
|
|
+ return map(ds.getDirectEntity());
|
|
|
}
|
|
|
|
|
|
public static Entity getTrueSource(DamageSource ds) {
|
|
|
- if(ds.l() == null) {
|
|
|
+ if(ds.getEntity() == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- return map(ds.l());
|
|
|
+ return map(ds.getEntity());
|
|
|
}
|
|
|
|
|
|
- public static EntityPlayer map(Player p) {
|
|
|
+ public static ServerPlayer map(Player p) {
|
|
|
return ((CraftPlayer) p).getHandle();
|
|
|
}
|
|
|
|
|
@@ -344,31 +400,31 @@ public class NMS {
|
|
|
return e.getBukkitEntity();
|
|
|
}
|
|
|
|
|
|
- public static EntityLiving map(LivingEntity e) {
|
|
|
+ public static net.minecraft.world.entity.LivingEntity map(LivingEntity e) {
|
|
|
return ((CraftLivingEntity) e).getHandle();
|
|
|
}
|
|
|
|
|
|
- public static EntityArrow map(Arrow e) {
|
|
|
+ public static net.minecraft.world.entity.projectile.AbstractArrow map(Arrow e) {
|
|
|
return ((CraftArrow) e).getHandle();
|
|
|
}
|
|
|
|
|
|
- public static EntityFireworks map(Firework e) {
|
|
|
+ public static net.minecraft.world.entity.projectile.FireworkRocketEntity map(Firework e) {
|
|
|
return ((CraftFirework) e).getHandle();
|
|
|
}
|
|
|
|
|
|
- public static EntityFireballFireball map(LargeFireball e) {
|
|
|
+ public static net.minecraft.world.entity.projectile.LargeFireball map(LargeFireball e) {
|
|
|
return ((CraftLargeFireball) e).getHandle();
|
|
|
}
|
|
|
|
|
|
- public static EntityWitherSkull map(WitherSkull e) {
|
|
|
+ public static net.minecraft.world.entity.projectile.WitherSkull map(WitherSkull e) {
|
|
|
return ((CraftWitherSkull) e).getHandle();
|
|
|
}
|
|
|
|
|
|
- public static EntityItem map(Item e) {
|
|
|
- return (EntityItem) ((CraftItem) e).getHandle();
|
|
|
+ public static ItemEntity map(Item e) {
|
|
|
+ return (ItemEntity) ((CraftItem) e).getHandle();
|
|
|
}
|
|
|
|
|
|
- public static WorldServer map(World e) {
|
|
|
+ public static ServerLevel map(World e) {
|
|
|
return ((CraftWorld) e).getHandle();
|
|
|
}
|
|
|
|
|
@@ -376,7 +432,7 @@ public class NMS {
|
|
|
return ((CraftPlayerProfile) profile).getGameProfile();
|
|
|
}
|
|
|
|
|
|
- public static IBlockData map(Block b) {
|
|
|
+ public static net.minecraft.world.level.block.state.BlockState map(Block b) {
|
|
|
return ((CraftBlock) b).getNMS();
|
|
|
}
|
|
|
|
|
@@ -390,7 +446,7 @@ public class NMS {
|
|
|
if(f.getType() == DamageSource.class) {
|
|
|
try {
|
|
|
DamageSource ds = (DamageSource) f.get(null);
|
|
|
- DAMAGE_SOURCES.put(ds.u(), ds);
|
|
|
+ DAMAGE_SOURCES.put(ds.getMsgId(), ds);
|
|
|
} catch(Exception ex) {
|
|
|
}
|
|
|
}
|
|
@@ -400,145 +456,150 @@ public class NMS {
|
|
|
}
|
|
|
|
|
|
public static DamageSource sting(LivingEntity liv) {
|
|
|
- return DamageSource.b(map(liv));
|
|
|
+ return DamageSource.sting(map(liv));
|
|
|
}
|
|
|
|
|
|
public static DamageSource mobAttack(LivingEntity liv) {
|
|
|
- return DamageSource.c(map(liv));
|
|
|
+ return DamageSource.mobAttack(map(liv));
|
|
|
}
|
|
|
|
|
|
public static DamageSource mobIndirect(Entity ent, LivingEntity liv) {
|
|
|
- return DamageSource.a(map(ent), map(liv));
|
|
|
+ return DamageSource.indirectMobAttack(map(ent), map(liv));
|
|
|
}
|
|
|
|
|
|
public static DamageSource playerAttack(Player p) {
|
|
|
- return DamageSource.a(map(p));
|
|
|
+ return DamageSource.playerAttack(map(p));
|
|
|
}
|
|
|
|
|
|
public static DamageSource arrow(Arrow arrow, Entity ent) {
|
|
|
- return DamageSource.a(map(arrow), map(ent));
|
|
|
+ return DamageSource.arrow(map(arrow), map(ent));
|
|
|
}
|
|
|
|
|
|
public static DamageSource trident(Entity ent, Entity ent2) {
|
|
|
- return DamageSource.a(map(ent), map(ent2));
|
|
|
+ return DamageSource.trident(map(ent), map(ent2));
|
|
|
}
|
|
|
|
|
|
public static DamageSource firework(Firework firework, Entity ent) {
|
|
|
- return DamageSource.a(map(firework), map(ent));
|
|
|
+ return DamageSource.fireworks(map(firework), map(ent));
|
|
|
}
|
|
|
|
|
|
public static DamageSource fireball(LargeFireball fireball, Entity ent) {
|
|
|
- return DamageSource.a(map(fireball), map(ent));
|
|
|
+ return DamageSource.fireball(map(fireball), map(ent));
|
|
|
}
|
|
|
|
|
|
public static DamageSource witherSkull(WitherSkull witherSkull, Entity ent) {
|
|
|
- return DamageSource.a(map(witherSkull), map(ent));
|
|
|
+ return DamageSource.witherSkull(map(witherSkull), map(ent));
|
|
|
}
|
|
|
|
|
|
public static DamageSource projectile(Entity ent, Entity ent2) {
|
|
|
- return DamageSource.a(map(ent), map(ent2));
|
|
|
+ return DamageSource.thrown(map(ent), map(ent2));
|
|
|
}
|
|
|
|
|
|
public static DamageSource indirectMagic(Entity ent, Entity ent2) {
|
|
|
- return DamageSource.c(map(ent), map(ent2));
|
|
|
+ return DamageSource.indirectMagic(map(ent), map(ent2));
|
|
|
}
|
|
|
|
|
|
public static DamageSource thorns(Entity ent) {
|
|
|
- return DamageSource.a(map(ent));
|
|
|
+ return DamageSource.thorns(map(ent));
|
|
|
}
|
|
|
|
|
|
public static DamageSource explosion(LivingEntity liv) {
|
|
|
- return DamageSource.d(map(liv));
|
|
|
+ return DamageSource.explosion(map(liv));
|
|
|
}
|
|
|
|
|
|
public static DamageSource explosionBed() {
|
|
|
- return DamageSource.a();
|
|
|
+ return DamageSource.badRespawnPointExplosion();
|
|
|
}
|
|
|
|
|
|
public static void setMessageOfTheDay(String msg) {
|
|
|
- ((CraftServer) Bukkit.getServer()).getServer().e(msg);
|
|
|
+ try {
|
|
|
+ var server = ((CraftServer) Bukkit.getServer()).getServer();
|
|
|
+ server.getClass().getMethod("e", String.class).invoke(server, msg);
|
|
|
+ } catch(Exception ex) {
|
|
|
+ KajetansPlugin.warn("cannot set motd");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static String toString(ItemStack stack) {
|
|
|
- NBTTagCompound c = new NBTTagCompound();
|
|
|
- map(stack).b(c);
|
|
|
+ CompoundTag c = new CompoundTag();
|
|
|
+ map(stack).save(c);
|
|
|
return c.toString();
|
|
|
}
|
|
|
|
|
|
- private static NBTTagCompound parse(String s) throws Exception {
|
|
|
- return MojangsonParser.a(s);
|
|
|
+ private static CompoundTag parse(String s) throws Exception {
|
|
|
+ return TagParser.parseTag(s);
|
|
|
}
|
|
|
|
|
|
public static ItemStack parseItemStack(String stack) throws Exception {
|
|
|
- return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.a(parse(stack)));
|
|
|
+ return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.of(parse(stack)));
|
|
|
}
|
|
|
|
|
|
public static String toString(Entity ent) {
|
|
|
- NBTTagCompound c = new NBTTagCompound();
|
|
|
- map(ent).d(c);
|
|
|
+ CompoundTag c = new CompoundTag();
|
|
|
+ map(ent).save(c);
|
|
|
return c.toString();
|
|
|
}
|
|
|
|
|
|
public static Entity parseEntity(String stack, Location l) throws Exception {
|
|
|
- NBTTagCompound c = parse(stack);
|
|
|
+ CompoundTag c = parse(stack);
|
|
|
var nmsWorld = map(l.getWorld());
|
|
|
net.minecraft.world.entity.Entity ent =
|
|
|
- net.minecraft.world.entity.EntityTypes.a(c, nmsWorld, e -> {
|
|
|
- e.a_(UUID.randomUUID());
|
|
|
- e.a(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
|
|
|
- return nmsWorld.b(e) ? e : null;
|
|
|
+ EntityType.loadEntityRecursive(c, nmsWorld, e -> {
|
|
|
+ e.setUUID(UUID.randomUUID());
|
|
|
+ NMS.moveTo(e, l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
|
|
|
+ return nmsWorld.addFreshEntity(e) ? e : null;
|
|
|
});
|
|
|
return map(ent);
|
|
|
}
|
|
|
|
|
|
- private static BlockPosition convert(Location l) {
|
|
|
- return new BlockPosition(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
|
|
+ private static BlockPos convert(Location l) {
|
|
|
+ return new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
|
|
}
|
|
|
|
|
|
public static void copyTileEntity(Location from, Location to) {
|
|
|
var nmsFromWorld = map(from.getWorld());
|
|
|
var nmsToWorld = map(to.getWorld());
|
|
|
|
|
|
- BlockPosition posTo = convert(to);
|
|
|
- TileEntity fromEntity = nmsFromWorld.c_(convert(from));
|
|
|
- TileEntity toEntity = nmsToWorld.c_(posTo);
|
|
|
+ BlockPos posTo = convert(to);
|
|
|
+ BlockEntity fromEntity = nmsFromWorld.getBlockEntity(convert(from));
|
|
|
+ BlockEntity toEntity = nmsToWorld.getBlockEntity(posTo);
|
|
|
if(fromEntity != null && toEntity != null && fromEntity.getClass() == toEntity.getClass()) {
|
|
|
- NBTTagCompound nbtTagCompound = fromEntity.m();
|
|
|
- toEntity.a(nbtTagCompound);
|
|
|
+ CompoundTag nbtTagCompound = fromEntity.saveWithFullMetadata();
|
|
|
+ toEntity.load(nbtTagCompound);
|
|
|
Block b = to.getBlock();
|
|
|
- nmsToWorld.a(posTo, map(b), map(b), 3);
|
|
|
+ nmsToWorld.sendBlockUpdated(posTo, map(b), map(b), 3);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static NBTTagCompound getBlockEntity(String s) throws Exception {
|
|
|
+ public static CompoundTag getBlockEntity(String s) throws Exception {
|
|
|
return parse(s);
|
|
|
}
|
|
|
|
|
|
- public static NBTTagCompound getEntity(Block b) {
|
|
|
+ public static CompoundTag getEntity(Block b) {
|
|
|
Location l = b.getLocation();
|
|
|
var nmsWorld = map(l.getWorld());
|
|
|
- TileEntity te = nmsWorld.c_(convert(l));
|
|
|
+ BlockEntity te = nmsWorld.getBlockEntity(convert(l));
|
|
|
if(te == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- return te.o();
|
|
|
+ return te.saveWithoutMetadata();
|
|
|
}
|
|
|
|
|
|
- public static void setEntity(Block b, NBTTagCompound nbt) {
|
|
|
+ public static void setEntity(Block b, CompoundTag nbt) {
|
|
|
if(nbt == null) {
|
|
|
return;
|
|
|
}
|
|
|
Location l = b.getLocation();
|
|
|
var nmsWorld = map(l.getWorld());
|
|
|
- BlockPosition pos = convert(l);
|
|
|
- TileEntity te = nmsWorld.c_(pos);
|
|
|
+ BlockPos pos = convert(l);
|
|
|
+ BlockEntity te = nmsWorld.getBlockEntity(pos);
|
|
|
if(te != null) {
|
|
|
- te.a(nbt);
|
|
|
- nmsWorld.a(pos, map(b), map(b), 3);
|
|
|
+ te.load(nbt);
|
|
|
+ nmsWorld.sendBlockUpdated(pos, map(b), map(b), 3);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static NBTTagCompound toNBT(Object o) {
|
|
|
- return (NBTTagCompound) o;
|
|
|
+ public static CompoundTag toNBT(Object o) {
|
|
|
+ return (CompoundTag) o;
|
|
|
}
|
|
|
}
|