mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 12:29:15 +00:00
Improved Head Rotate & Fix 1.20.1 NPC Not Spawning & Minor Improvements
This commit is contained in:
@@ -3,13 +3,14 @@ package net.momirealms.craftengine.bukkit.entity.data;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
|
||||
public class PlayerData<T> extends LivingEntityData<T> {
|
||||
public static final PlayerData<Object> Pose = new PlayerData<>(6, EntityDataValue.Serializers$POSE, CoreReflections.instance$Pose$STANDING);
|
||||
public static final PlayerData<Byte> Skin = new PlayerData<>(17, EntityDataValue.Serializers$BYTE, (byte) 0);
|
||||
public static final PlayerData<Byte> Hand = new PlayerData<>(18, EntityDataValue.Serializers$BYTE, (byte) 0);
|
||||
public static final PlayerData<Object> LShoulder = new PlayerData<>(19, EntityDataValue.Serializers$COMPOUND_TAG, CoreReflections.instance$CompoundTag$Empty);
|
||||
public static final PlayerData<Object> RShoulder = new PlayerData<>(20, EntityDataValue.Serializers$COMPOUND_TAG, CoreReflections.instance$CompoundTag$Empty);
|
||||
public static final PlayerData<Float> PlayerAbsorption = new PlayerData<>(PlayerData.class, EntityDataValue.Serializers$FLOAT, 0.0f);
|
||||
public static final PlayerData<Integer> Score = new PlayerData<>(PlayerData.class, EntityDataValue.Serializers$INT, 0);
|
||||
public static final PlayerData<Byte> PlayerModeCustomisation = new PlayerData<>(PlayerData.class, EntityDataValue.Serializers$BYTE, (byte) 0);
|
||||
public static final PlayerData<Byte> PlayerMainHand = new PlayerData<>(PlayerData.class, EntityDataValue.Serializers$BYTE, (byte) 1);
|
||||
public static final PlayerData<Object> ShoulderLeft = new PlayerData<>(PlayerData.class, EntityDataValue.Serializers$COMPOUND_TAG, CoreReflections.instance$CompoundTag$Empty);
|
||||
public static final PlayerData<Object> ShoulderRight = new PlayerData<>(PlayerData.class, EntityDataValue.Serializers$COMPOUND_TAG, CoreReflections.instance$CompoundTag$Empty);
|
||||
|
||||
public PlayerData(int id, Object serializer, T defaultValue) {
|
||||
super(id, serializer, defaultValue);
|
||||
public PlayerData(Class<?> clazz, Object serializer, T defaultValue) {
|
||||
super(clazz, serializer, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.network.BukkitNetworkManager;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
import net.momirealms.craftengine.bukkit.util.EntityUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LegacyAttributeUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.PlayerUtils;
|
||||
import net.momirealms.craftengine.core.entity.furniture.*;
|
||||
@@ -15,11 +17,13 @@ import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.ArrayUtils;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.QuaternionUtils;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.craftengine.core.world.WorldPosition;
|
||||
import net.momirealms.craftengine.core.world.collision.AABB;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -29,6 +33,7 @@ import org.joml.Vector3f;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BukkitFurniture implements Furniture {
|
||||
private final Key id;
|
||||
@@ -286,6 +291,10 @@ public class BukkitFurniture implements Furniture {
|
||||
@Override
|
||||
public void spawnSeatEntityForPlayer(net.momirealms.craftengine.core.entity.player.Player player, Seat seat) {
|
||||
BukkitSeatEntity seatEntity = (BukkitSeatEntity) seat.spawn(player, this);
|
||||
if (seatEntity == null) {
|
||||
this.removeOccupiedSeat(seat.offset());
|
||||
return;
|
||||
}
|
||||
this.seats.put(seatEntity.playerID(), seatEntity);
|
||||
player.setSeat(seatEntity);
|
||||
BukkitServerPlayer serverPlayer = (BukkitServerPlayer) player;
|
||||
@@ -314,10 +323,31 @@ public class BukkitFurniture implements Furniture {
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnSeatEntityForPlayer(org.bukkit.entity.Player player, Seat seat) {
|
||||
Location location = this.calculateSeatLocation(seat);
|
||||
Entity seatEntity = seat.limitPlayerRotation() ?
|
||||
EntityUtils.spawnEntity(player.getWorld(), VersionHelper.isOrAbove1_20_2() ? location.subtract(0,0.9875,0) : location.subtract(0,0.990625,0), EntityType.ARMOR_STAND, entity -> {
|
||||
public Location calculateSeatLocation(Seat seat) {
|
||||
Vector3f offset = QuaternionUtils.toQuaternionf(0, Math.toRadians(180 - this.location.getYaw()), 0).conjugate().transform(new Vector3f(seat.offset()));
|
||||
double yaw = seat.yaw() + this.location.getYaw();
|
||||
if (yaw < -180) yaw += 360;
|
||||
Location newLocation = this.location.clone();
|
||||
newLocation.setYaw((float) yaw);
|
||||
newLocation.add(offset.x, offset.y + 0.6, -offset.z);
|
||||
return newLocation;
|
||||
}
|
||||
|
||||
public BukkitSeatEntity seatByPlayerId(int playerId) {
|
||||
return this.seats.get(playerId);
|
||||
}
|
||||
|
||||
public void removeSeatEntity(int playerId) {
|
||||
this.seats.remove(playerId);
|
||||
}
|
||||
|
||||
public static Entity spawnSeatEntity(Furniture furniture, World world, Location loc, boolean limitPlayerRotation, Consumer<Entity> function) {
|
||||
EntityType type;
|
||||
if (limitPlayerRotation) {
|
||||
type = EntityType.ARMOR_STAND;
|
||||
loc = VersionHelper.isOrAbove1_20_2() ? loc.subtract(0,0.9875,0) : loc.subtract(0,0.990625,0);
|
||||
if (function == null) {
|
||||
function = entity -> {
|
||||
ArmorStand armorStand = (ArmorStand) entity;
|
||||
if (VersionHelper.isOrAbove1_21_3()) {
|
||||
Objects.requireNonNull(armorStand.getAttribute(Attribute.MAX_HEALTH)).setBaseValue(0.01);
|
||||
@@ -333,37 +363,22 @@ public class BukkitFurniture implements Furniture {
|
||||
armorStand.setAI(false);
|
||||
armorStand.setGravity(false);
|
||||
armorStand.setPersistent(false);
|
||||
armorStand.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_BASE_ENTITY_KEY, PersistentDataType.INTEGER, this.baseEntityId());
|
||||
armorStand.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_VECTOR_3F_KEY, PersistentDataType.STRING, seat.offset().x + ", " + seat.offset().y + ", " + seat.offset().z);
|
||||
}) :
|
||||
EntityUtils.spawnEntity(player.getWorld(), VersionHelper.isOrAbove1_20_2() ? location : location.subtract(0,0.25,0), EntityType.ITEM_DISPLAY, entity -> {
|
||||
armorStand.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_BASE_ENTITY_KEY, PersistentDataType.INTEGER, furniture.baseEntityId());
|
||||
//armorStand.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_VECTOR_3F_KEY, PersistentDataType.STRING, seat.offset().x + ", " + seat.offset().y + ", " + seat.offset().z);
|
||||
};
|
||||
}
|
||||
} else {
|
||||
type = EntityType.ITEM_DISPLAY;
|
||||
loc = VersionHelper.isOrAbove1_20_2() ? loc : loc.subtract(0,0.25,0);
|
||||
if (function == null) {
|
||||
function = entity -> {
|
||||
ItemDisplay itemDisplay = (ItemDisplay) entity;
|
||||
itemDisplay.setPersistent(false);
|
||||
itemDisplay.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_BASE_ENTITY_KEY, PersistentDataType.INTEGER, this.baseEntityId());
|
||||
itemDisplay.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_VECTOR_3F_KEY, PersistentDataType.STRING, seat.offset().x + ", " + seat.offset().y + ", " + seat.offset().z);
|
||||
});
|
||||
this.seats.add(new WeakReference<>(seatEntity));
|
||||
if (!seatEntity.addPassenger(player)) {
|
||||
seatEntity.remove();
|
||||
this.removeOccupiedSeat(seat.offset());
|
||||
itemDisplay.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_BASE_ENTITY_KEY, PersistentDataType.INTEGER, furniture.baseEntityId());
|
||||
//itemDisplay.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_VECTOR_3F_KEY, PersistentDataType.STRING, seat.offset().x + ", " + seat.offset().y + ", " + seat.offset().z);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Location calculateSeatLocation(Seat seat) {
|
||||
Vector3f offset = QuaternionUtils.toQuaternionf(0, Math.toRadians(180 - this.location.getYaw()), 0).conjugate().transform(new Vector3f(seat.offset()));
|
||||
double yaw = seat.yaw() + this.location.getYaw();
|
||||
if (yaw < -180) yaw += 360;
|
||||
Location newLocation = this.location.clone();
|
||||
newLocation.setYaw((float) yaw);
|
||||
newLocation.add(offset.x, offset.y + 0.6, -offset.z);
|
||||
return newLocation;
|
||||
}
|
||||
|
||||
public BukkitSeatEntity seatByEntityId(int id) {
|
||||
return this.seats.get(id);
|
||||
}
|
||||
|
||||
public void removeSeatEntity(int id) {
|
||||
this.seats.remove(id);
|
||||
return EntityUtils.spawnEntity(world, loc, type, function);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.momirealms.craftengine.bukkit.util.EntityUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
import net.momirealms.craftengine.core.entity.furniture.*;
|
||||
import net.momirealms.craftengine.core.entity.seat.SeatEntity;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.sound.SoundData;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -336,6 +337,21 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
|
||||
protected void tryLeavingSeat(@NotNull Player player, @NotNull Entity vehicle) {
|
||||
net.momirealms.craftengine.core.entity.player.Player serverPlayer = BukkitAdaptors.adapt(player);
|
||||
if (serverPlayer == null) {
|
||||
Integer baseFurniture = vehicle.getPersistentDataContainer().get(FURNITURE_SEAT_BASE_ENTITY_KEY, PersistentDataType.INTEGER);
|
||||
if (baseFurniture == null) return;
|
||||
BukkitFurniture furniture = loadedFurnitureByRealEntityId(baseFurniture);
|
||||
if (furniture == null) {
|
||||
vehicle.remove();
|
||||
return;
|
||||
}
|
||||
SeatEntity seatEntity = furniture.seatByPlayerId(player.getEntityId());
|
||||
if (seatEntity != null && !seatEntity.destroyed()) {
|
||||
seatEntity.destroy();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
BukkitSeatEntity seatEntity = (BukkitSeatEntity) serverPlayer.seat();
|
||||
if (seatEntity == null || seatEntity.literalObject() != vehicle) return;
|
||||
|
||||
|
||||
@@ -4,17 +4,12 @@ import net.momirealms.craftengine.core.entity.furniture.HitBoxTypes;
|
||||
|
||||
public class BukkitHitBoxTypes extends HitBoxTypes {
|
||||
|
||||
public static void init() {
|
||||
public static void init() {}
|
||||
|
||||
static {
|
||||
register(INTERACTION, InteractionHitBox.FACTORY);
|
||||
register(SHULKER, ShulkerHitBox.FACTORY);
|
||||
register(HAPPY_GHAST, HappyGhastHitBox.FACTORY);
|
||||
register(CUSTOM, CustomHitBox.FACTORY);
|
||||
}
|
||||
|
||||
static {
|
||||
//register(INTERACTION, InteractionHitBox.FACTORY);
|
||||
//register(SHULKER, ShulkerHitBox.FACTORY);
|
||||
//register(HAPPY_GHAST, HappyGhastHitBox.FACTORY);
|
||||
//register(CUSTOM, CustomHitBox.FACTORY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public abstract class BukkitSeatEntity extends BukkitEntity implements SeatEntit
|
||||
private final BukkitFurniture furniture;
|
||||
private final Vector3f vector3f;
|
||||
private final int playerID;
|
||||
private boolean destroyed = false;
|
||||
|
||||
public BukkitSeatEntity(Entity entity, Furniture furniture, Vector3f vector3f, int playerID) {
|
||||
super(entity);
|
||||
@@ -27,28 +28,45 @@ public abstract class BukkitSeatEntity extends BukkitEntity implements SeatEntit
|
||||
|
||||
@Override
|
||||
public void dismount(Player player) {
|
||||
if (player == null || destroyed) return;
|
||||
player.setSeat(null);
|
||||
onDismount(player);
|
||||
destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismount(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void event(Player player, Object event) {}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (destroyed) return;
|
||||
destroyed = true;
|
||||
|
||||
org.bukkit.entity.Entity entity = this.literalObject();
|
||||
if (entity == null) return;
|
||||
|
||||
for (org.bukkit.entity.Entity passenger : entity.getPassengers()) {
|
||||
entity.removePassenger(passenger);
|
||||
if (passenger instanceof org.bukkit.entity.Player p && p.getEntityId() == this.playerID) {
|
||||
dismount(BukkitAdaptors.adapt(p));
|
||||
return;
|
||||
Player cePlayer = BukkitAdaptors.adapt(p);
|
||||
if (cePlayer != null && cePlayer.entityID() == playerID()) {
|
||||
cePlayer.setSeat(null);
|
||||
onDismount(cePlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
entity.remove();
|
||||
furniture.removeSeatEntity(playerID());
|
||||
furniture.removeOccupiedSeat(vector3f());
|
||||
entity.remove();
|
||||
}
|
||||
|
||||
public boolean destroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,12 +12,8 @@ import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MAttributeH
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityTypes;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.NetworkReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
import net.momirealms.craftengine.bukkit.util.EntityUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.PlayerUtils;
|
||||
import net.momirealms.craftengine.core.entity.furniture.AbstractSeat;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Seat;
|
||||
import net.momirealms.craftengine.core.entity.furniture.SeatFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.*;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.entity.seat.SeatEntity;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
@@ -61,15 +57,17 @@ public class CrawlSeat extends AbstractSeat {
|
||||
public SeatEntity spawn(org.bukkit.entity.Player player, Furniture furniture) {
|
||||
Location location = ((BukkitFurniture)furniture).calculateSeatLocation(this);
|
||||
|
||||
org.bukkit.entity.Entity seatEntity = EntityUtils.spawnSeatEntity(furniture, this, player.getWorld(), location, this.limitPlayerRotation, null);
|
||||
seatEntity.addPassenger(player);
|
||||
org.bukkit.entity.Entity seatEntity = BukkitFurniture.spawnSeatEntity(furniture, player.getWorld(), location, this.limitPlayerRotation, null);
|
||||
if (!seatEntity.addPassenger(player)) {
|
||||
return null;
|
||||
};
|
||||
|
||||
// Fix Rider Pose
|
||||
int visualId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
||||
int entityId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
||||
List<Object> packets = new ArrayList<>();
|
||||
packets.add(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(visualId, UUID.randomUUID(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(),
|
||||
MEntityTypes.instance$EntityType$SHULKER, 0, CoreReflections.instance$Vec3$Zero, 0));
|
||||
packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(visualId, List.copyOf(visualData)));
|
||||
packets.add(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(entityId, UUID.randomUUID(), location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(),
|
||||
MEntityTypes.SHULKER, 0, CoreReflections.instance$Vec3$Zero, 0));
|
||||
packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityId, List.copyOf(visualData)));
|
||||
|
||||
try {
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
@@ -77,9 +75,9 @@ public class CrawlSeat extends AbstractSeat {
|
||||
CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, 0.6);
|
||||
packets.add(
|
||||
NetworkReflections.constructor$ClientboundUpdateAttributesPacket0
|
||||
.newInstance(visualId, Collections.singletonList(attributeInstance))
|
||||
.newInstance(entityId, Collections.singletonList(attributeInstance))
|
||||
);
|
||||
packets.add(FastNMS.INSTANCE.constructor$ClientboundSetPassengersPacket(seatEntity.getEntityId(), visualId));
|
||||
packets.add(FastNMS.INSTANCE.constructor$ClientboundSetPassengersPacket(seatEntity.getEntityId(), entityId));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to add crawl seat attributes", e);
|
||||
@@ -109,17 +107,17 @@ public class CrawlSeat extends AbstractSeat {
|
||||
}
|
||||
}, 1, location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
|
||||
return new CrawlEntity(seatEntity, furniture, offset(), player.getEntityId(), visualId, syncPosePacket);
|
||||
return new CrawlEntity(seatEntity, furniture, offset(), player.getEntityId(), entityId, syncPosePacket);
|
||||
}
|
||||
|
||||
private static class CrawlEntity extends BukkitSeatEntity {
|
||||
private final int visualId;
|
||||
private final int entityId;
|
||||
private final Object syncPosePacket;
|
||||
|
||||
|
||||
public CrawlEntity(Entity entity, Furniture furniture, Vector3f vector3f, int playerID, int visualId, Object fixPosePacket) {
|
||||
public CrawlEntity(Entity entity, Furniture furniture, Vector3f vector3f, int playerID, int entityId, Object fixPosePacket) {
|
||||
super(entity, furniture, vector3f, playerID);
|
||||
this.visualId = visualId;
|
||||
this.entityId = entityId;
|
||||
this.syncPosePacket = fixPosePacket;
|
||||
}
|
||||
|
||||
@@ -129,20 +127,21 @@ public class CrawlSeat extends AbstractSeat {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismount(Player player) {
|
||||
super.dismount(player);
|
||||
((org.bukkit.entity.Player) player.platformPlayer()).setPose(Pose.STANDING, false);
|
||||
public void onDismount(Player player) {
|
||||
if (player == null) return;
|
||||
org.bukkit.entity.Player bukkitPlayer = (org.bukkit.entity.Player) player.platformPlayer();
|
||||
bukkitPlayer.setPose(Pose.STANDING, false);
|
||||
try {
|
||||
Object packet = NetworkReflections.constructor$ClientboundRemoveEntitiesPacket.newInstance((Object) new int[]{visualId});
|
||||
Object packet = NetworkReflections.constructor$ClientboundRemoveEntitiesPacket.newInstance((Object) new int[]{entityId});
|
||||
player.sendPacket(packet, false);
|
||||
} catch (Exception e) {
|
||||
BukkitCraftEngine.instance().logger().warn("Failed to remove crawl entity", e);
|
||||
BukkitCraftEngine.instance().logger().warn("Failed to dismount from CrawlEntity", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return Key.of("craftengine", "crawl");
|
||||
return SeatType.CRAWL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.bukkit.entity.furniture.seat;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
|
||||
import net.momirealms.craftengine.bukkit.entity.data.LivingEntityData;
|
||||
import net.momirealms.craftengine.bukkit.entity.data.PlayerData;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurniture;
|
||||
@@ -18,13 +17,11 @@ import net.momirealms.craftengine.bukkit.plugin.scheduler.impl.FoliaTask;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
import net.momirealms.craftengine.bukkit.util.*;
|
||||
import net.momirealms.craftengine.core.entity.EquipmentSlot;
|
||||
import net.momirealms.craftengine.core.entity.furniture.AbstractSeat;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Seat;
|
||||
import net.momirealms.craftengine.core.entity.furniture.SeatFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.*;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.entity.seat.SeatEntity;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.network.ByteBufPacketEvent;
|
||||
import net.momirealms.craftengine.core.plugin.network.NMSPacketEvent;
|
||||
import net.momirealms.craftengine.core.plugin.network.NetWorkUser;
|
||||
import net.momirealms.craftengine.core.plugin.scheduler.SchedulerTask;
|
||||
@@ -41,6 +38,8 @@ import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerAnimationType;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.joml.Vector3f;
|
||||
@@ -49,12 +48,43 @@ import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static net.momirealms.craftengine.core.plugin.network.ProtocolVersion.V1_21_2;
|
||||
|
||||
public class LaySeat extends AbstractSeat {
|
||||
public static final SeatFactory FACTORY = new Factory();
|
||||
private static final List<Pair<Object, Object>> emptyEquipments;
|
||||
private static final List<Pair<Object, ItemStack>> emptyBukkitEquipments;
|
||||
private static Method method$InventoryView$convertSlot;
|
||||
private static Method method$InventoryView$getTopInventory;
|
||||
private static Method method$InventoryView$getType;
|
||||
private final Direction facing;
|
||||
private final boolean sleep;
|
||||
private final boolean phantom;
|
||||
|
||||
static {
|
||||
if (!VersionHelper.isOrAbove1_21_1()) {
|
||||
method$InventoryView$convertSlot = ReflectionUtils.getMethod(InventoryView.class, new String[]{"convertSlot"}, int.class);
|
||||
method$InventoryView$getTopInventory = ReflectionUtils.getMethod(InventoryView.class, new String[]{"getTopInventory"});
|
||||
method$InventoryView$getType = ReflectionUtils.getMethod(Inventory.class, new String[]{"getType"});
|
||||
}
|
||||
emptyEquipments = List.of(
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$MAINHAND, MItems.AIR$Item),
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$OFFHAND, MItems.AIR$Item),
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, MItems.AIR$Item),
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$CHEST, MItems.AIR$Item),
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$LEGS, MItems.AIR$Item),
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$FEET, MItems.AIR$Item)
|
||||
);
|
||||
emptyBukkitEquipments = List.of(
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$MAINHAND, ItemUtils.AIR),
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$OFFHAND, ItemUtils.AIR),
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, ItemUtils.AIR),
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$CHEST, ItemUtils.AIR),
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$LEGS, ItemUtils.AIR),
|
||||
Pair.of(CoreReflections.instance$EquipmentSlot$FEET, ItemUtils.AIR)
|
||||
);
|
||||
}
|
||||
|
||||
public LaySeat(Vector3f offset, Direction facing, boolean sleep, boolean phantom) {
|
||||
super(offset, 0);
|
||||
this.facing = facing;
|
||||
@@ -96,9 +126,14 @@ public class LaySeat extends AbstractSeat {
|
||||
}
|
||||
int npcId = FastNMS.INSTANCE.method$Entity$getId(npc);
|
||||
CoreReflections.method$Entity$absSnapTo.invoke(npc, loc.getX(), loc.getY(), loc.getZ(), 0, 0);
|
||||
Object npcSpawnPacket = FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(npcId, uuid,
|
||||
loc.getX(), loc.getY(), loc.getZ(), 0, 0,
|
||||
MEntityTypes.instance$EntityType$PLAYER, 0, CoreReflections.instance$Vec3$Zero, 0);
|
||||
Object npcSpawnPacket;
|
||||
if (!VersionHelper.isOrAbove1_20_2()) {
|
||||
npcSpawnPacket = NetworkReflections.constructor$ClientboundAddPlayerPacket.newInstance(npc);
|
||||
} else {
|
||||
npcSpawnPacket = FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(npcId, uuid,
|
||||
loc.getX(), loc.getY(), loc.getZ(), 0, 0,
|
||||
MEntityTypes.PLAYER, 0, CoreReflections.instance$Vec3$Zero, 0);
|
||||
}
|
||||
|
||||
// Info
|
||||
EnumSet enumSet = EnumSet.noneOf((Class<? extends Enum>) NetworkReflections.clazz$ClientboundPlayerInfoUpdatePacket$Action);
|
||||
@@ -132,12 +167,12 @@ public class LaySeat extends AbstractSeat {
|
||||
CoreReflections.method$Entity$setInvisible.invoke(serverPlayer, true);
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(npcData, PlayerData.Pose.entityDataAccessor(), CoreReflections.instance$Pose$SLEEPING);
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(npcData, LivingEntityData.SleepingPos.entityDataAccessor(), Optional.of(bedPos));
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(npcData, PlayerData.Skin.entityDataAccessor(), CoreReflections.method$SynchedEntityData$get.invoke(playerData, PlayerData.Skin.entityDataAccessor()));
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(npcData, PlayerData.Hand.entityDataAccessor(), CoreReflections.method$SynchedEntityData$get.invoke(playerData, PlayerData.Hand.entityDataAccessor()));
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(npcData, PlayerData.LShoulder.entityDataAccessor(), CoreReflections.method$SynchedEntityData$get.invoke(playerData, PlayerData.LShoulder.entityDataAccessor()));
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(npcData, PlayerData.RShoulder.entityDataAccessor(), CoreReflections.method$SynchedEntityData$get.invoke(playerData, PlayerData.RShoulder.entityDataAccessor()));
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(playerData, PlayerData.LShoulder.entityDataAccessor(), CoreReflections.instance$CompoundTag$Empty);
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(playerData, PlayerData.RShoulder.entityDataAccessor(), CoreReflections.instance$CompoundTag$Empty);
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(npcData, PlayerData.PlayerModeCustomisation.entityDataAccessor(), CoreReflections.method$SynchedEntityData$get.invoke(playerData, PlayerData.PlayerModeCustomisation.entityDataAccessor()));
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(npcData, PlayerData.PlayerMainHand.entityDataAccessor(), CoreReflections.method$SynchedEntityData$get.invoke(playerData, PlayerData.PlayerMainHand.entityDataAccessor()));
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(npcData, PlayerData.ShoulderLeft.entityDataAccessor(), CoreReflections.method$SynchedEntityData$get.invoke(playerData, PlayerData.ShoulderLeft.entityDataAccessor()));
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(npcData, PlayerData.ShoulderRight.entityDataAccessor(), CoreReflections.method$SynchedEntityData$get.invoke(playerData, PlayerData.ShoulderRight.entityDataAccessor()));
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(playerData, PlayerData.ShoulderLeft.entityDataAccessor(), CoreReflections.instance$CompoundTag$Empty);
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(playerData, PlayerData.ShoulderRight.entityDataAccessor(), CoreReflections.instance$CompoundTag$Empty);
|
||||
|
||||
// SetData
|
||||
CoreReflections.method$Entity$setInvisible.invoke(serverPlayer, true);
|
||||
@@ -157,17 +192,8 @@ public class LaySeat extends AbstractSeat {
|
||||
npcTeleportPacket = NetworkReflections.constructor$ClientboundTeleportEntityPacket.newInstance(npc);
|
||||
}
|
||||
|
||||
|
||||
// Equipment
|
||||
List<Pair<Object, Object>> emptySlots = new ArrayList<>();
|
||||
|
||||
emptySlots.add(Pair.of(CoreReflections.instance$EquipmentSlot$MAINHAND, MItems.Air$ItemStack));
|
||||
emptySlots.add(Pair.of(CoreReflections.instance$EquipmentSlot$OFFHAND, MItems.Air$ItemStack));
|
||||
emptySlots.add(Pair.of(CoreReflections.instance$EquipmentSlot$HEAD, MItems.Air$ItemStack));
|
||||
emptySlots.add(Pair.of(CoreReflections.instance$EquipmentSlot$CHEST, MItems.Air$ItemStack));
|
||||
emptySlots.add(Pair.of(CoreReflections.instance$EquipmentSlot$LEGS, MItems.Air$ItemStack));
|
||||
emptySlots.add(Pair.of(CoreReflections.instance$EquipmentSlot$FEET, MItems.Air$ItemStack));
|
||||
Object emptyEquipPacket = NetworkReflections.constructor$ClientboundSetEquipmentPacket.newInstance(player.getEntityId(), emptySlots);
|
||||
Object emptyEquipPacket = NetworkReflections.constructor$ClientboundSetEquipmentPacket.newInstance(player.getEntityId(), emptyEquipments);
|
||||
|
||||
Map<EquipmentSlot, ItemStack> equipments = new HashMap<>();
|
||||
EntityEquipment equipment = player.getEquipment();
|
||||
@@ -184,6 +210,9 @@ public class LaySeat extends AbstractSeat {
|
||||
equipments.forEach((slot, item) -> npcSlots.add(Pair.of(EntityUtils.fromEquipmentSlot(slot), FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(item))));
|
||||
Object fullEquipPacket = NetworkReflections.constructor$ClientboundSetEquipmentPacket.newInstance(npcId, npcSlots);
|
||||
|
||||
// Animation
|
||||
Object npcLeftAnimatePacket = NetworkReflections.constructor$ClientboundAnimatePacket.newInstance(npc, 0);
|
||||
Object npcRightAnimatePacket = NetworkReflections.constructor$ClientboundAnimatePacket.newInstance(npc, 3);
|
||||
|
||||
packets.add(npcInfoPacket);
|
||||
packets.add(npcSpawnPacket);
|
||||
@@ -191,39 +220,33 @@ public class LaySeat extends AbstractSeat {
|
||||
packets.add(npcDataPacket);
|
||||
packets.add(npcTeleportPacket);
|
||||
packets.add(emptyEquipPacket);
|
||||
packets.add(npcLeftAnimatePacket);
|
||||
Object npcInitPackets = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets);
|
||||
|
||||
// Spawn
|
||||
org.bukkit.entity.Entity seatEntity = EntityUtils.spawnSeatEntity(furniture, this, player.getWorld(), loc, false, null);
|
||||
seatEntity.addPassenger(player); // 0.5 higher
|
||||
org.bukkit.entity.Entity seatEntity = BukkitFurniture.spawnSeatEntity(furniture, player.getWorld(), loc, false, null);
|
||||
if (!seatEntity.addPassenger(player)) { // 0.5 higher
|
||||
return null;
|
||||
}
|
||||
cePlayer.sendPacket(npcInitPackets, true);
|
||||
cePlayer.sendPacket(fullEquipPacket, true);
|
||||
if (player.getY() > 0) {
|
||||
if (player.getY() > 0 && cePlayer.protocolVersion().isVersionNewerThan(V1_21_2)) {
|
||||
BukkitCraftEngine.instance().scheduler().asyncLater(() -> cePlayer.sendPacket(npcTeleportPacket, true),
|
||||
50, TimeUnit.MILLISECONDS); // over height 0 cost 2 npcTeleportPacket
|
||||
}
|
||||
|
||||
for (org.bukkit.entity.Player p : PlayerUtils.getTrackedBy(player)) {
|
||||
BukkitNetworkManager.instance().getOnlineUser(p).sendPacket(npcInitPackets, false);
|
||||
BukkitNetworkManager.instance().getOnlineUser(p).sendPacket(fullEquipPacket, false);
|
||||
if (player.getY() > 0) {
|
||||
BukkitCraftEngine.instance().scheduler().asyncLater(() -> BukkitNetworkManager.instance().getOnlineUser(p).sendPacket(npcTeleportPacket, false),
|
||||
for (org.bukkit.entity.Player o : PlayerUtils.getTrackedBy(player)) {
|
||||
NetWorkUser tracker = BukkitNetworkManager.instance().getOnlineUser(o);
|
||||
tracker.sendPacket(npcInitPackets, false);
|
||||
tracker.sendPacket(fullEquipPacket, false);
|
||||
if (player.getY() > 0 && tracker.protocolVersion().isVersionNewerThan(V1_21_2)) {
|
||||
BukkitCraftEngine.instance().scheduler().asyncLater(() -> tracker.sendPacket(npcTeleportPacket, false),
|
||||
50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
// HeadRot
|
||||
Direction npcDir = bedDir.opposite();
|
||||
float npcYawOffset = 0.0f;
|
||||
if (player.getY() > 0.0874218749) {
|
||||
if (VersionHelper.isOrAbove1_21_2()) {
|
||||
double offset = loc.x() - Math.floor(loc.x()) - 0.5;
|
||||
|
||||
if (Math.abs(offset) > 0.05005) {
|
||||
npcYawOffset = offset > 0 ? +27f : -26f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sleep) {
|
||||
player.setSleepingIgnored(true);
|
||||
@@ -240,12 +263,13 @@ public class LaySeat extends AbstractSeat {
|
||||
npcInitPackets,
|
||||
npcRemovePacket,
|
||||
npcTeleportPacket,
|
||||
npcLeftAnimatePacket,
|
||||
npcRightAnimatePacket,
|
||||
(BukkitServerPlayer) cePlayer,
|
||||
bedLoc,
|
||||
npc,
|
||||
npcId,
|
||||
npcDir,
|
||||
npcYawOffset,
|
||||
equipments,
|
||||
emptyEquipPacket,
|
||||
fullEquipPacket,
|
||||
@@ -261,12 +285,13 @@ public class LaySeat extends AbstractSeat {
|
||||
private final Object npcInitPackets;
|
||||
private final Object npcRemovePacket;
|
||||
private final Object npcTPPacket;
|
||||
private final Object npcLeftAnimatePacket;
|
||||
private final Object npcRightAnimatePacket;
|
||||
private final BukkitServerPlayer serverPlayer;
|
||||
private final Object npc;
|
||||
private final Location bedLoc;
|
||||
private final int npcID;
|
||||
private final Direction npcDir;
|
||||
private final float npcYawOffset;
|
||||
|
||||
// Equipment
|
||||
private final PlayerMonitorTask task;
|
||||
@@ -286,12 +311,13 @@ public class LaySeat extends AbstractSeat {
|
||||
Object npcInitPackets,
|
||||
Object npcRemovePacket,
|
||||
Object npcTPPacket,
|
||||
Object npcLeftAnimatePacket,
|
||||
Object npcRightAnimatePacket,
|
||||
BukkitServerPlayer serverPlayer,
|
||||
Location bedLoc,
|
||||
Object npc,
|
||||
int npcID,
|
||||
Direction npcDir,
|
||||
float npcYawOffset,
|
||||
Map<EquipmentSlot, ItemStack> equipments,
|
||||
Object emptyEquipPacket,
|
||||
Object fullEquipPacket,
|
||||
@@ -301,12 +327,13 @@ public class LaySeat extends AbstractSeat {
|
||||
this.npcInitPackets = npcInitPackets;
|
||||
this.npcRemovePacket = npcRemovePacket;
|
||||
this.npcTPPacket = npcTPPacket;
|
||||
this.npcLeftAnimatePacket = npcLeftAnimatePacket;
|
||||
this.npcRightAnimatePacket = npcRightAnimatePacket;
|
||||
this.serverPlayer = serverPlayer;
|
||||
this.bedLoc = bedLoc;
|
||||
this.npc = npc;
|
||||
this.npcID = npcID;
|
||||
this.npcDir = npcDir;
|
||||
this.npcYawOffset = npcYawOffset;
|
||||
|
||||
this.task = new PlayerMonitorTask();
|
||||
this.equipments = equipments;
|
||||
@@ -314,23 +341,17 @@ public class LaySeat extends AbstractSeat {
|
||||
this.fullEquipPacket = fullEquipPacket;
|
||||
|
||||
this.sleep = sleep;
|
||||
updateNpcYaw(serverPlayer.xRot());
|
||||
updateNpcInvisible();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(NetWorkUser from, NetWorkUser to) {
|
||||
to.sendPacket(this.npcInitPackets, false);
|
||||
to.sendPacket(this.fullEquipPacket, false);
|
||||
if (serverPlayer.y() > 0) {
|
||||
BukkitCraftEngine.instance().scheduler().asyncLater(() -> {
|
||||
to.sendPacket(this.npcTPPacket, false);
|
||||
to.sendPacket(this.npcRotHeadPacket, false);
|
||||
if (npcDataPacket != null) to.sendPacket(this.npcDataPacket, false);
|
||||
}, 50, TimeUnit.MILLISECONDS);
|
||||
} else {
|
||||
to.sendPacket(this.npcRotHeadPacket, false);
|
||||
if (npcDataPacket != null) to.sendPacket(this.npcDataPacket, false);
|
||||
to.sendPacket(this.npcRotHeadPacket, false);
|
||||
if (npcDataPacket != null) to.sendPacket(this.npcDataPacket, false);
|
||||
if (serverPlayer.y() > 0 && to.protocolVersion().isVersionNewerThan(V1_21_2)) {
|
||||
BukkitCraftEngine.instance().scheduler().asyncLater(() ->
|
||||
to.sendPacket(this.npcTPPacket, false), 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,42 +362,58 @@ public class LaySeat extends AbstractSeat {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismount(Player from) {
|
||||
super.dismount(from);
|
||||
public void onDismount(Player player) {
|
||||
if (player == null) return;
|
||||
|
||||
this.task.task.cancel();
|
||||
org.bukkit.entity.Player player = (org.bukkit.entity.Player) from.platformPlayer();
|
||||
|
||||
org.bukkit.entity.Player bukkitPlayer = (org.bukkit.entity.Player) player.platformPlayer();
|
||||
Object blockPos = LocationUtils.toBlockPos(bedLoc.getBlockX(), bedLoc.getBlockY(), bedLoc.getBlockZ());
|
||||
Object blockState = BlockStateUtils.blockDataToBlockState(bedLoc.getBlock().getBlockData());
|
||||
|
||||
try {
|
||||
Object blockUpdatePacket = NetworkReflections.constructor$ClientboundBlockUpdatePacket.newInstance(blockPos, blockState);
|
||||
if (player.getPotionEffect(PotionEffectType.INVISIBILITY) == null) CoreReflections.method$Entity$setInvisible.invoke(serverPlayer.serverPlayer(), false);
|
||||
from.sendPacket(this.npcRemovePacket, true);
|
||||
from.sendPacket(blockUpdatePacket, true);
|
||||
player.sendPacket(this.npcRemovePacket, true);
|
||||
player.sendPacket(blockUpdatePacket, true);
|
||||
|
||||
if (bukkitPlayer.getPotionEffect(PotionEffectType.INVISIBILITY) == null) {
|
||||
CoreReflections.method$Entity$setInvisible.invoke(serverPlayer.serverPlayer(), false);
|
||||
}
|
||||
|
||||
Object npcData = CoreReflections.method$Entity$getEntityData.invoke(npc);
|
||||
Object playerData = CoreReflections.method$Entity$getEntityData.invoke(serverPlayer.serverPlayer());
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(playerData, PlayerData.LShoulder.entityDataAccessor(), CoreReflections.method$SynchedEntityData$get.invoke(npcData, PlayerData.LShoulder.entityDataAccessor()));
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(playerData, PlayerData.RShoulder.entityDataAccessor(), CoreReflections.method$SynchedEntityData$get.invoke(npcData, PlayerData.RShoulder.entityDataAccessor()));
|
||||
if (player.getPotionEffect(PotionEffectType.INVISIBILITY) == null) CoreReflections.method$Entity$setInvisible.invoke(serverPlayer.serverPlayer(), false);
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(
|
||||
playerData,
|
||||
PlayerData.ShoulderLeft.entityDataAccessor(),
|
||||
CoreReflections.method$SynchedEntityData$get.invoke(npcData, PlayerData.ShoulderLeft.entityDataAccessor())
|
||||
);
|
||||
CoreReflections.method$SynchedEntityData$set.invoke(
|
||||
playerData,
|
||||
PlayerData.ShoulderRight.entityDataAccessor(),
|
||||
CoreReflections.method$SynchedEntityData$get.invoke(npcData, PlayerData.ShoulderRight.entityDataAccessor())
|
||||
);
|
||||
if (bukkitPlayer.getPotionEffect(PotionEffectType.INVISIBILITY) == null) {
|
||||
CoreReflections.method$Entity$setInvisible.invoke(serverPlayer.serverPlayer(), false);
|
||||
}
|
||||
|
||||
player.updateInventory();
|
||||
bukkitPlayer.updateInventory();
|
||||
|
||||
if (sleep) {
|
||||
player.setSleepingIgnored(false);
|
||||
bukkitPlayer.setSleepingIgnored(false);
|
||||
}
|
||||
|
||||
Object fullSlots = NetworkReflections.method$ClientboundSetEquipmentPacket$getSlots.invoke(this.fullEquipPacket);
|
||||
Object recoverEquip = NetworkReflections.constructor$ClientboundSetEquipmentPacket.newInstance(player.getEntityId(), fullSlots);
|
||||
Object recoverEquip = NetworkReflections.constructor$ClientboundSetEquipmentPacket.newInstance(bukkitPlayer.getEntityId(), fullSlots);
|
||||
|
||||
for (org.bukkit.entity.Player p : PlayerUtils.getTrackedBy(player)) {
|
||||
BukkitServerPlayer sp = BukkitAdaptors.adapt(p);
|
||||
sp.entityPacketHandlers().remove(playerID());
|
||||
sp.sendPacket(this.npcRemovePacket, false);
|
||||
sp.sendPacket(blockUpdatePacket, false);
|
||||
sp.sendPacket(recoverEquip, false);
|
||||
for (org.bukkit.entity.Player o : PlayerUtils.getTrackedBy(bukkitPlayer)) {
|
||||
BukkitServerPlayer tracker = (BukkitServerPlayer) BukkitNetworkManager.instance().getOnlineUser(o);
|
||||
tracker.entityPacketHandlers().remove(playerID());
|
||||
tracker.sendPacket(this.npcRemovePacket, false);
|
||||
tracker.sendPacket(blockUpdatePacket, false);
|
||||
tracker.sendPacket(recoverEquip, false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to dismount LayEntity", e);
|
||||
CraftEngine.instance().logger().warn("Failed to dismount from LayEntity", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,14 +444,14 @@ public class LaySeat extends AbstractSeat {
|
||||
serverPlayer.sendPacket(this.emptyEquipPacket, false);
|
||||
serverPlayer.sendPacket(this.updateEquipPacket, false);
|
||||
|
||||
for (org.bukkit.entity.Player p : PlayerUtils.getTrackedBy(player)) {
|
||||
BukkitNetworkManager.instance().getOnlineUser(p).sendPacket(this.updateEquipPacket, false);
|
||||
for (org.bukkit.entity.Player o : PlayerUtils.getTrackedBy(player)) {
|
||||
BukkitNetworkManager.instance().getOnlineUser(o).sendPacket(this.updateEquipPacket, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSetEquipment(NetWorkUser user, NMSPacketEvent event, Object packet) {
|
||||
if (this.emptyEquipPacket == packet) return;
|
||||
public void handleSetEquipment(NetWorkUser user, ByteBufPacketEvent event, Object slots) {
|
||||
if (emptyBukkitEquipments.equals(slots)) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@@ -428,15 +465,10 @@ public class LaySeat extends AbstractSeat {
|
||||
boolean isPlayerInv;
|
||||
|
||||
if (!VersionHelper.isOrAbove1_21_1()) {
|
||||
Object openInventory = player.getClass().getMethod("getOpenInventory").invoke(player);
|
||||
|
||||
Method convertSlotMethod = openInventory.getClass().getMethod("convertSlot", int.class);
|
||||
convertSlot = (int) convertSlotMethod.invoke(openInventory, slot);
|
||||
|
||||
Method getTopInventoryMethod = openInventory.getClass().getMethod("getTopInventory");
|
||||
Object topInventory = getTopInventoryMethod.invoke(openInventory);
|
||||
Method getTypeMethod = topInventory.getClass().getMethod("getType");
|
||||
Object type = getTypeMethod.invoke(topInventory);
|
||||
Object openInventory = player.getOpenInventory();
|
||||
convertSlot = (int) method$InventoryView$convertSlot.invoke(openInventory, slot);
|
||||
Object topInventory = method$InventoryView$getTopInventory.invoke(openInventory);
|
||||
Object type = method$InventoryView$getType.invoke(topInventory);
|
||||
isPlayerInv = type == InventoryType.CRAFTING;
|
||||
} else {
|
||||
convertSlot = player.getOpenInventory().convertSlot(slot);
|
||||
@@ -446,7 +478,7 @@ public class LaySeat extends AbstractSeat {
|
||||
if (!(convertSlot == player.getInventory().getHeldItemSlot() || (isPlayerInv && (slot == 45 || (slot >= 5 && slot <= 8))))) return;
|
||||
int containerId = (int) NetworkReflections.method$ClientboundContainerSetSlotPacket$getContainerId.invoke(packet);
|
||||
int stateId = (int) NetworkReflections.method$ClientboundContainerSetSlotPacket$getStateId.invoke(packet);
|
||||
Object replacePacket = NetworkReflections.constructor$ClientboundContainerSetSlotPacket.newInstance(containerId, stateId, slot, MItems.Air$ItemStack);
|
||||
Object replacePacket = NetworkReflections.constructor$ClientboundContainerSetSlotPacket.newInstance(containerId, stateId, slot, MItems.AIR$Item);
|
||||
event.replacePacket(replacePacket);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handleContainerSetSlotPacket", e);
|
||||
@@ -459,13 +491,13 @@ public class LaySeat extends AbstractSeat {
|
||||
try {
|
||||
Object animatePacket;
|
||||
if (e.getAnimationType() == PlayerAnimationType.ARM_SWING) {
|
||||
animatePacket = NetworkReflections.constructor$ClientboundAnimatePacket.newInstance(npc, 0);
|
||||
animatePacket = npcLeftAnimatePacket;
|
||||
} else {
|
||||
animatePacket = NetworkReflections.constructor$ClientboundAnimatePacket.newInstance(npc, 3);
|
||||
animatePacket = npcRightAnimatePacket;
|
||||
}
|
||||
serverPlayer.sendPacket(animatePacket, true);
|
||||
for (org.bukkit.entity.Player other : PlayerUtils.getTrackedBy(serverPlayer.platformPlayer())) {
|
||||
BukkitNetworkManager.instance().getOnlineUser(other).sendPacket(animatePacket, true);
|
||||
for (org.bukkit.entity.Player o : PlayerUtils.getTrackedBy(serverPlayer.platformPlayer())) {
|
||||
BukkitNetworkManager.instance().getOnlineUser(o).sendPacket(animatePacket, true);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle PlayerAnimationEvent", exception);
|
||||
@@ -480,7 +512,7 @@ public class LaySeat extends AbstractSeat {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return Key.of("craftengine", "lay");
|
||||
return SeatType.LAY;
|
||||
}
|
||||
|
||||
private class PlayerMonitorTask implements Runnable {
|
||||
@@ -494,7 +526,7 @@ public class LaySeat extends AbstractSeat {
|
||||
if (VersionHelper.isFolia()) {
|
||||
this.task = new FoliaTask(p.getScheduler().runAtFixedRate(plugin.javaPlugin(), (t) -> this.run(), () -> {}, 1, 1));
|
||||
} else {
|
||||
this.task = plugin.scheduler().sync().runRepeating(this, 1, 1);
|
||||
this.task = plugin.scheduler().sync().runRepeating(this, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,8 +551,9 @@ public class LaySeat extends AbstractSeat {
|
||||
if (lastYaw != playerYaw) {
|
||||
updateNpcYaw(playerYaw);
|
||||
serverPlayer.sendPacket(npcRotHeadPacket, false);
|
||||
for (org.bukkit.entity.Player other : PlayerUtils.getTrackedBy(player)) {
|
||||
BukkitNetworkManager.instance().getOnlineUser(other).sendPacket(npcRotHeadPacket, true);
|
||||
for (org.bukkit.entity.Player o : PlayerUtils.getTrackedBy(player)) {
|
||||
NetWorkUser tracker = BukkitNetworkManager.instance().getOnlineUser(o);
|
||||
tracker.sendPacket(npcRotHeadPacket, true);
|
||||
}
|
||||
this.lastYaw = playerYaw;
|
||||
}
|
||||
@@ -574,8 +607,7 @@ public class LaySeat extends AbstractSeat {
|
||||
mappedYaw = deltaYaw;
|
||||
}
|
||||
|
||||
float limitedYaw = Math.max(-45, Math.min(45, mappedYaw));
|
||||
float finalYaw = limitedYaw + npcYawOffset;
|
||||
float finalYaw = Math.max(-45, Math.min(45, mappedYaw));
|
||||
return MCUtils.packDegrees(finalYaw);
|
||||
}
|
||||
|
||||
@@ -597,8 +629,8 @@ public class LaySeat extends AbstractSeat {
|
||||
Object dataValue = CoreReflections.method$SynchedEntityData$DataItem$value.invoke(dataItem);
|
||||
Object packet = FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(npcID, List.of(dataValue));
|
||||
serverPlayer.sendPacket(packet, false);
|
||||
for (org.bukkit.entity.Player p : PlayerUtils.getTrackedBy(player)) {
|
||||
BukkitNetworkManager.instance().getOnlineUser(p).sendPacket(packet, false);
|
||||
for (org.bukkit.entity.Player o : PlayerUtils.getTrackedBy(player)) {
|
||||
BukkitNetworkManager.instance().getOnlineUser(o).sendPacket(packet, false);
|
||||
}
|
||||
} else if (player.getPotionEffect(PotionEffectType.INVISIBILITY) != null && npcDataPacket == null) {
|
||||
CoreReflections.method$Entity$setInvisible.invoke(npc, true);
|
||||
@@ -607,8 +639,8 @@ public class LaySeat extends AbstractSeat {
|
||||
Object dataValue = CoreReflections.method$SynchedEntityData$DataItem$value.invoke(dataItem);
|
||||
npcDataPacket = FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(npcID, List.of(dataValue));
|
||||
serverPlayer.sendPacket(npcDataPacket, false);
|
||||
for (org.bukkit.entity.Player p : PlayerUtils.getTrackedBy(player)) {
|
||||
BukkitNetworkManager.instance().getOnlineUser(p).sendPacket(npcDataPacket, false);
|
||||
for (org.bukkit.entity.Player o : PlayerUtils.getTrackedBy(player)) {
|
||||
BukkitNetworkManager.instance().getOnlineUser(o).sendPacket(npcDataPacket, false);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.entity.furniture.seat;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurniture;
|
||||
import net.momirealms.craftengine.bukkit.util.EntityUtils;
|
||||
import net.momirealms.craftengine.core.entity.furniture.AbstractSeat;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Seat;
|
||||
import net.momirealms.craftengine.core.entity.furniture.SeatFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.*;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.entity.seat.SeatEntity;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -32,8 +28,10 @@ public class SitSeat extends AbstractSeat {
|
||||
|
||||
public SeatEntity spawn(org.bukkit.entity.Player player, Furniture furniture) {
|
||||
Location location = ((BukkitFurniture)furniture).calculateSeatLocation(this);
|
||||
org.bukkit.entity.Entity seatEntity = EntityUtils.spawnSeatEntity(furniture, this, player.getWorld(), location, this.limitPlayerRotation, null);
|
||||
seatEntity.addPassenger(player);
|
||||
org.bukkit.entity.Entity seatEntity = BukkitFurniture.spawnSeatEntity(furniture, player.getWorld(), location, this.limitPlayerRotation, null);
|
||||
if (!seatEntity.addPassenger(player)) {
|
||||
return null;
|
||||
};
|
||||
return new SitEntity(seatEntity, furniture, offset(), player.getEntityId());
|
||||
}
|
||||
|
||||
@@ -45,7 +43,7 @@ public class SitSeat extends AbstractSeat {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return Key.of("craftengine", "sit") ;
|
||||
return SeatType.SIT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -162,9 +162,6 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
registerNMSPacketConsumer(PacketConsumers.MOVE_POS_ENTITY, NetworkReflections.clazz$ClientboundMoveEntityPacket$Pos);
|
||||
registerNMSPacketConsumer(PacketConsumers.ROTATE_HEAD, NetworkReflections.clazz$ClientboundRotateHeadPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SET_ENTITY_MOTION, NetworkReflections.clazz$ClientboundSetEntityMotionPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SET_EQUIPMENT_NMS, Reflections.clazz$ClientboundSetEquipmentPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SET_CONTAINER_SLOT, Reflections.clazz$ClientboundContainerSetSlotPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SET_EQUIPMENT_NMS, NetworkReflections.clazz$ClientboundSetEquipmentPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SET_CONTAINER_SLOT, NetworkReflections.clazz$ClientboundContainerSetSlotPacket);
|
||||
registerS2CByteBufPacketConsumer(PacketConsumers.LEVEL_CHUNK_WITH_LIGHT, this.packetIds.clientboundLevelChunkWithLightPacket());
|
||||
registerS2CByteBufPacketConsumer(PacketConsumers.SECTION_BLOCK_UPDATE, this.packetIds.clientboundSectionBlocksUpdatePacket());
|
||||
|
||||
@@ -182,7 +182,7 @@ public class PacketConsumers {
|
||||
user.entityPacketHandlers().put(id, FurnitureCollisionPacketHandler.INSTANCE);
|
||||
}
|
||||
};
|
||||
ADD_ENTITY_HANDLERS[MEntityTypes.instance$EntityType$PLAYER$registryId] = (user, event) -> {
|
||||
ADD_ENTITY_HANDLERS[MEntityTypes.PLAYER$registryId] = (user, event) -> {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
buf.readVarInt();
|
||||
UUID uuid = buf.readUUID();
|
||||
@@ -2198,6 +2198,10 @@ public class PacketConsumers {
|
||||
FastNMS.INSTANCE.method$FriendlyByteBuf$writeItem(newFriendlyBuf, pair.getSecond());
|
||||
}
|
||||
}
|
||||
EntityPacketHandler handler = user.entityPacketHandlers().get(entity);
|
||||
if (handler != null) {
|
||||
handler.handleSetEquipment(user, event, slots);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundSetEquipmentPacket", e);
|
||||
}
|
||||
@@ -2436,18 +2440,6 @@ public class PacketConsumers {
|
||||
}
|
||||
};
|
||||
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SET_EQUIPMENT_NMS = (user, event, packet) -> {
|
||||
try {
|
||||
int entityId = (int) NetworkReflections.method$ClientboundSetEquipmentPacket$getEntity.invoke(packet);
|
||||
EntityPacketHandler handler = user.entityPacketHandlers().get(entityId);
|
||||
if (handler != null) {
|
||||
handler.handleSetEquipment(user, event, packet);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundSetEquipmentPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SET_CONTAINER_SLOT = (user, event, packet) -> {
|
||||
try {
|
||||
SeatEntity seat = ((BukkitServerPlayer) user).seat();
|
||||
|
||||
@@ -3540,9 +3540,9 @@ public final class CoreReflections {
|
||||
);
|
||||
|
||||
// 1.20.2 +
|
||||
public static final Method method$ServerPlayer$clientInformation = VersionHelper.isOrAbove1_20_2() ? requireNonNull(ReflectionUtils.getMethod(
|
||||
clazz$ServerPlayer, clazz$ClientInformation, 0
|
||||
)) : null;
|
||||
public static final Method method$ServerPlayer$clientInformation = Optional.ofNullable(clazz$ClientInformation)
|
||||
.map(it -> ReflectionUtils.getMethod(clazz$ServerPlayer, it, 0))
|
||||
.orElse(null);
|
||||
|
||||
public static final Class<?> clazz$CompoundTag = requireNonNull(
|
||||
BukkitReflectionUtils.findReobfOrMojmapClass(
|
||||
@@ -3634,11 +3634,13 @@ public final class CoreReflections {
|
||||
}
|
||||
|
||||
// 1.21.3 +
|
||||
public static final Class<?> clazz$PositionMoveRotation = VersionHelper.isOrAbove1_21_3() ? ReflectionUtils.getClazz(
|
||||
requireNonNull(BukkitReflectionUtils.assembleMCClass("world.entity.PositionMoveRotation"))) : null;
|
||||
public static final Class<?> clazz$PositionMoveRotation = ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("world.entity.PositionMoveRotation")
|
||||
);
|
||||
|
||||
public static final Method method$PositionMoveRotation$of = VersionHelper.isOrAbove1_21_3() ? requireNonNull(
|
||||
ReflectionUtils.getStaticMethod(clazz$PositionMoveRotation, clazz$PositionMoveRotation, clazz$Entity)) : null;
|
||||
public static final Method method$PositionMoveRotation$of = Optional.ofNullable(clazz$PositionMoveRotation)
|
||||
.map(it -> ReflectionUtils.getStaticMethod(it, it, clazz$Entity))
|
||||
.orElse(null);
|
||||
|
||||
public static final Method method$Entity$absSnapTo = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.plugin.reflection.minecraft;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.ReflectionInitException;
|
||||
import net.momirealms.craftengine.bukkit.util.ItemUtils;
|
||||
|
||||
public final class MItems {
|
||||
private MItems() {}
|
||||
@@ -22,4 +23,6 @@ public final class MItems {
|
||||
throw new ReflectionInitException("Failed to init Items", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static final Object AIR$Item = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(ItemUtils.AIR);
|
||||
}
|
||||
|
||||
@@ -178,6 +178,10 @@ public final class NetworkReflections {
|
||||
"network.protocol.game.ClientboundAddPlayerPacket"
|
||||
);
|
||||
|
||||
public static final Constructor<?> constructor$ClientboundAddPlayerPacket = Optional.ofNullable(clazz$ClientboundAddPlayerPacket)
|
||||
.map(it -> ReflectionUtils.getConstructor(clazz$ClientboundAddPlayerPacket, CoreReflections.clazz$Player))
|
||||
.orElse(null);
|
||||
|
||||
public static final Class<?> clazz$ClientboundRemoveEntitiesPacket = requireNonNull(
|
||||
BukkitReflectionUtils.findReobfOrMojmapClass(
|
||||
"network.protocol.game.PacketPlayOutEntityDestroy",
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurnitureManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.core.entity.EquipmentSlot;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||
import net.momirealms.craftengine.core.entity.furniture.Seat;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static net.momirealms.craftengine.core.entity.EquipmentSlot.BODY;
|
||||
@@ -43,47 +39,6 @@ public class EntityUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Entity spawnSeatEntity(Furniture furniture, Seat seat, World world, Location loc, boolean limitPlayerRotation, Consumer<Entity> function) {
|
||||
EntityType type;
|
||||
if (limitPlayerRotation) {
|
||||
type = EntityType.ARMOR_STAND;
|
||||
loc = VersionHelper.isOrAbove1_20_2() ? loc.subtract(0,0.9875,0) : loc.subtract(0,0.990625,0);
|
||||
if (function == null) {
|
||||
function = entity -> {
|
||||
ArmorStand armorStand = (ArmorStand) entity;
|
||||
if (VersionHelper.isOrAbove1_21_3()) {
|
||||
Objects.requireNonNull(armorStand.getAttribute(Attribute.MAX_HEALTH)).setBaseValue(0.01);
|
||||
} else {
|
||||
LegacyAttributeUtils.setMaxHealth(armorStand);
|
||||
}
|
||||
armorStand.setSmall(true);
|
||||
armorStand.setInvisible(true);
|
||||
armorStand.setSilent(true);
|
||||
armorStand.setInvulnerable(true);
|
||||
armorStand.setArms(false);
|
||||
armorStand.setCanTick(false);
|
||||
armorStand.setAI(false);
|
||||
armorStand.setGravity(false);
|
||||
armorStand.setPersistent(false);
|
||||
armorStand.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_BASE_ENTITY_KEY, PersistentDataType.INTEGER, furniture.baseEntityId());
|
||||
//armorStand.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_VECTOR_3F_KEY, PersistentDataType.STRING, seat.offset().x + ", " + seat.offset().y + ", " + seat.offset().z);
|
||||
};
|
||||
}
|
||||
} else {
|
||||
type = EntityType.ITEM_DISPLAY;
|
||||
loc = VersionHelper.isOrAbove1_20_2() ? loc : loc.subtract(0,0.25,0);
|
||||
if (function == null) {
|
||||
function = entity -> {
|
||||
ItemDisplay itemDisplay = (ItemDisplay) entity;
|
||||
itemDisplay.setPersistent(false);
|
||||
itemDisplay.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_BASE_ENTITY_KEY, PersistentDataType.INTEGER, furniture.baseEntityId());
|
||||
//itemDisplay.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_SEAT_VECTOR_3F_KEY, PersistentDataType.STRING, seat.offset().x + ", " + seat.offset().y + ", " + seat.offset().z);
|
||||
};
|
||||
}
|
||||
}
|
||||
return spawnEntity(world, loc, type, function);
|
||||
}
|
||||
|
||||
public static org.bukkit.inventory.EquipmentSlot toBukkitEquipmentSlot(EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case MAIN_HAND -> org.bukkit.inventory.EquipmentSlot.HAND;
|
||||
@@ -109,18 +64,6 @@ public class EntityUtils {
|
||||
};
|
||||
}
|
||||
|
||||
public static Object fromEquipmentSlot(org.bukkit.inventory.EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case HAND -> CoreReflections.instance$EquipmentSlot$MAINHAND;
|
||||
case OFF_HAND -> CoreReflections.instance$EquipmentSlot$OFFHAND;
|
||||
case HEAD -> CoreReflections.instance$EquipmentSlot$HEAD;
|
||||
case CHEST -> CoreReflections.instance$EquipmentSlot$CHEST;
|
||||
case LEGS -> CoreReflections.instance$EquipmentSlot$LEGS;
|
||||
case FEET -> CoreReflections.instance$EquipmentSlot$FEET;
|
||||
default -> new Object();
|
||||
};
|
||||
};
|
||||
|
||||
public static Object fromEquipmentSlot(EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case MAIN_HAND -> CoreReflections.instance$EquipmentSlot$MAINHAND;
|
||||
|
||||
Reference in New Issue
Block a user