|
|
|
|
@@ -6,10 +6,12 @@ import net.momirealms.craftengine.bukkit.entity.seat.BukkitSeatManager;
|
|
|
|
|
import net.momirealms.craftengine.bukkit.nms.CollisionEntity;
|
|
|
|
|
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
|
|
|
|
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
|
|
|
|
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
|
|
|
|
import net.momirealms.craftengine.bukkit.world.BukkitWorld;
|
|
|
|
|
import net.momirealms.craftengine.core.entity.furniture.AnchorType;
|
|
|
|
|
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
|
|
|
|
import net.momirealms.craftengine.core.entity.furniture.FurnitureConfig;
|
|
|
|
|
import net.momirealms.craftengine.core.entity.furniture.FurnitureDataAccessor;
|
|
|
|
|
import net.momirealms.craftengine.core.entity.player.InteractionHand;
|
|
|
|
|
import net.momirealms.craftengine.core.item.Item;
|
|
|
|
|
import net.momirealms.craftengine.core.loot.LootTable;
|
|
|
|
|
@@ -19,11 +21,13 @@ import net.momirealms.craftengine.core.util.Key;
|
|
|
|
|
import net.momirealms.craftengine.core.world.World;
|
|
|
|
|
import net.momirealms.craftengine.core.world.WorldPosition;
|
|
|
|
|
import net.momirealms.sparrow.nbt.CompoundTag;
|
|
|
|
|
import org.bukkit.FluidCollisionMode;
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
import org.bukkit.persistence.PersistentDataType;
|
|
|
|
|
import org.bukkit.util.RayTraceResult;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
|
|
@@ -59,6 +63,45 @@ public final class CraftEngineFurniture {
|
|
|
|
|
return BukkitFurnitureManager.instance().furnitureById(id).orElse(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Performs ray tracing to find the furniture entity that the player is currently targeting
|
|
|
|
|
*
|
|
|
|
|
* @param player The player performing the ray trace
|
|
|
|
|
* @param maxDistance Maximum ray trace distance (in blocks)
|
|
|
|
|
* @return The furniture being targeted by the player, or null if no furniture is found
|
|
|
|
|
*/
|
|
|
|
|
@Nullable
|
|
|
|
|
public static BukkitFurniture rayTrace(Player player, double maxDistance) {
|
|
|
|
|
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(player);
|
|
|
|
|
Location eyeLocation = serverPlayer.getEyeLocation();
|
|
|
|
|
RayTraceResult result = player.getWorld().rayTrace(eyeLocation, eyeLocation.getDirection(), maxDistance, FluidCollisionMode.NEVER, true, 0d, CraftEngineFurniture::isCollisionEntity);
|
|
|
|
|
if (result == null)
|
|
|
|
|
return null;
|
|
|
|
|
Entity hitEntity = result.getHitEntity();
|
|
|
|
|
if (hitEntity == null)
|
|
|
|
|
return null;
|
|
|
|
|
return getLoadedFurnitureByCollider(hitEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Performs ray tracing to find the furniture entity that the player is currently targeting
|
|
|
|
|
*
|
|
|
|
|
* @param player The player performing the ray trace
|
|
|
|
|
* @return The furniture being targeted by the player, or null if no furniture is found
|
|
|
|
|
*/
|
|
|
|
|
@Nullable
|
|
|
|
|
public static BukkitFurniture rayTrace(Player player) {
|
|
|
|
|
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(player);
|
|
|
|
|
Location eyeLocation = serverPlayer.getEyeLocation();
|
|
|
|
|
RayTraceResult result = player.getWorld().rayTrace(eyeLocation, eyeLocation.getDirection(), serverPlayer.getCachedInteractionRange(), FluidCollisionMode.NEVER, true, 0d, CraftEngineFurniture::isCollisionEntity);
|
|
|
|
|
if (result == null)
|
|
|
|
|
return null;
|
|
|
|
|
Entity hitEntity = result.getHitEntity();
|
|
|
|
|
if (hitEntity == null)
|
|
|
|
|
return null;
|
|
|
|
|
return getLoadedFurnitureByCollider(hitEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Places furniture at certain location
|
|
|
|
|
*
|
|
|
|
|
@@ -70,9 +113,7 @@ public final class CraftEngineFurniture {
|
|
|
|
|
public static BukkitFurniture place(Location location, Key furnitureId) {
|
|
|
|
|
FurnitureConfig furniture = byId(furnitureId);
|
|
|
|
|
if (furniture == null) return null;
|
|
|
|
|
// fixme API
|
|
|
|
|
// return place(location, furnitureId, furniture.getAnyAnchorType());
|
|
|
|
|
return null;
|
|
|
|
|
return place(location, furniture, furniture.anyVariantName(), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -86,11 +127,22 @@ public final class CraftEngineFurniture {
|
|
|
|
|
@Nullable
|
|
|
|
|
@Deprecated(since = "0.0.66", forRemoval = true)
|
|
|
|
|
public static BukkitFurniture place(Location location, Key furnitureId, AnchorType anchorType) {
|
|
|
|
|
return place(location, furnitureId, anchorType.variantName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Places furniture at certain location
|
|
|
|
|
*
|
|
|
|
|
* @param location location
|
|
|
|
|
* @param furnitureId furniture to place
|
|
|
|
|
* @param variant variant type
|
|
|
|
|
* @return the loaded furniture
|
|
|
|
|
*/
|
|
|
|
|
@Nullable
|
|
|
|
|
public static BukkitFurniture place(Location location, Key furnitureId, String variant) {
|
|
|
|
|
FurnitureConfig furniture = byId(furnitureId);
|
|
|
|
|
if (furniture == null) return null;
|
|
|
|
|
// fixme API
|
|
|
|
|
// return BukkitFurnitureManager.instance().place(location, furniture, FurnitureDataAccessor.builder().anchorType(anchorType).build(), true);
|
|
|
|
|
return null;
|
|
|
|
|
return BukkitFurnitureManager.instance().place(location, furniture, FurnitureDataAccessor.ofVariant(variant), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -104,9 +156,7 @@ public final class CraftEngineFurniture {
|
|
|
|
|
@NotNull
|
|
|
|
|
@Deprecated(since = "0.0.66", forRemoval = true)
|
|
|
|
|
public static BukkitFurniture place(Location location, FurnitureConfig furniture, AnchorType anchorType) {
|
|
|
|
|
// fixme API
|
|
|
|
|
// return BukkitFurnitureManager.instance().place(location, furniture, FurnitureDataAccessor.builder().anchorType(anchorType).build(), true);
|
|
|
|
|
return null;
|
|
|
|
|
return place(location, furniture, anchorType.variantName(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -123,9 +173,23 @@ public final class CraftEngineFurniture {
|
|
|
|
|
public static BukkitFurniture place(Location location, Key furnitureId, AnchorType anchorType, boolean playSound) {
|
|
|
|
|
FurnitureConfig furniture = byId(furnitureId);
|
|
|
|
|
if (furniture == null) return null;
|
|
|
|
|
// fixme API
|
|
|
|
|
// return BukkitFurnitureManager.instance().place(location, furniture, FurnitureDataAccessor.builder().anchorType(anchorType).build(), playSound);
|
|
|
|
|
return null;
|
|
|
|
|
return place(location, furniture, anchorType.variantName(), playSound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Places furniture at certain location
|
|
|
|
|
*
|
|
|
|
|
* @param location location
|
|
|
|
|
* @param furnitureId furniture to place
|
|
|
|
|
* @param variant variant
|
|
|
|
|
* @param playSound whether to play place sounds
|
|
|
|
|
* @return the loaded furniture
|
|
|
|
|
*/
|
|
|
|
|
@Nullable
|
|
|
|
|
public static BukkitFurniture place(Location location, Key furnitureId, String variant, boolean playSound) {
|
|
|
|
|
FurnitureConfig furniture = byId(furnitureId);
|
|
|
|
|
if (furniture == null) return null;
|
|
|
|
|
return place(location, furniture, variant, playSound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -140,9 +204,49 @@ public final class CraftEngineFurniture {
|
|
|
|
|
@NotNull
|
|
|
|
|
@Deprecated(since = "0.0.66", forRemoval = true)
|
|
|
|
|
public static BukkitFurniture place(Location location, FurnitureConfig furniture, AnchorType anchorType, boolean playSound) {
|
|
|
|
|
// fixme API
|
|
|
|
|
// return BukkitFurnitureManager.instance().place(location, furniture, FurnitureDataAccessor.builder().anchorType(anchorType).build(), playSound);
|
|
|
|
|
return null;
|
|
|
|
|
return place(location, furniture, anchorType.variantName(), playSound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Places furniture at certain location
|
|
|
|
|
*
|
|
|
|
|
* @param location location
|
|
|
|
|
* @param furniture furniture to place
|
|
|
|
|
* @param variant variant
|
|
|
|
|
* @param playSound whether to play place sounds
|
|
|
|
|
* @return the loaded furniture
|
|
|
|
|
*/
|
|
|
|
|
@NotNull
|
|
|
|
|
public static BukkitFurniture place(Location location, FurnitureConfig furniture, String variant, boolean playSound) {
|
|
|
|
|
return BukkitFurnitureManager.instance().place(location, furniture, FurnitureDataAccessor.ofVariant(variant), playSound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Places furniture at certain location
|
|
|
|
|
*
|
|
|
|
|
* @param location location
|
|
|
|
|
* @param furniture furniture to place
|
|
|
|
|
* @param data furniture data
|
|
|
|
|
* @param playSound whether to play place sounds
|
|
|
|
|
* @return the loaded furniture
|
|
|
|
|
*/
|
|
|
|
|
@NotNull
|
|
|
|
|
public static BukkitFurniture place(Location location, FurnitureConfig furniture, CompoundTag data, boolean playSound) {
|
|
|
|
|
return BukkitFurnitureManager.instance().place(location, furniture, FurnitureDataAccessor.of(data), playSound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Places furniture at certain location
|
|
|
|
|
*
|
|
|
|
|
* @param location location
|
|
|
|
|
* @param furniture furniture to place
|
|
|
|
|
* @param dataAccessor furniture data accessor
|
|
|
|
|
* @param playSound whether to play place sounds
|
|
|
|
|
* @return the loaded furniture
|
|
|
|
|
*/
|
|
|
|
|
@NotNull
|
|
|
|
|
public static BukkitFurniture place(Location location, FurnitureConfig furniture, FurnitureDataAccessor dataAccessor, boolean playSound) {
|
|
|
|
|
return BukkitFurnitureManager.instance().place(location, furniture, dataAccessor, playSound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -178,18 +282,30 @@ public final class CraftEngineFurniture {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the base furniture by the base entity
|
|
|
|
|
* Gets the furniture by the meta entity
|
|
|
|
|
*
|
|
|
|
|
* @param baseEntity base entity
|
|
|
|
|
* @return the loaded furniture
|
|
|
|
|
*/
|
|
|
|
|
@Nullable
|
|
|
|
|
public static BukkitFurniture getLoadedFurnitureByBaseEntity(@NotNull Entity baseEntity) {
|
|
|
|
|
public static BukkitFurniture getLoadedFurnitureByMetaEntity(@NotNull Entity baseEntity) {
|
|
|
|
|
return BukkitFurnitureManager.instance().loadedFurnitureByMetaEntityId(baseEntity.getEntityId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the base furniture by the seat entity
|
|
|
|
|
* Gets the furniture by the meta entity
|
|
|
|
|
*
|
|
|
|
|
* @param baseEntity base entity
|
|
|
|
|
* @return the loaded furniture
|
|
|
|
|
*/
|
|
|
|
|
@Nullable
|
|
|
|
|
@Deprecated(since = "0.0.66")
|
|
|
|
|
public static BukkitFurniture getLoadedFurnitureByBaseEntity(@NotNull Entity baseEntity) {
|
|
|
|
|
return getLoadedFurnitureByMetaEntity(baseEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the furniture by the seat entity
|
|
|
|
|
*
|
|
|
|
|
* @param seat seat entity
|
|
|
|
|
* @return the loaded furniture
|
|
|
|
|
@@ -204,6 +320,21 @@ public final class CraftEngineFurniture {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the furniture by the collider entity
|
|
|
|
|
*
|
|
|
|
|
* @param collider collider entity
|
|
|
|
|
* @return the loaded furniture
|
|
|
|
|
*/
|
|
|
|
|
@Nullable
|
|
|
|
|
public static BukkitFurniture getLoadedFurnitureByCollider(@NotNull Entity collider) {
|
|
|
|
|
Object nmsEntity = FastNMS.INSTANCE.method$CraftEntity$getHandle(collider);
|
|
|
|
|
if (nmsEntity instanceof CollisionEntity collisionEntity) {
|
|
|
|
|
return BukkitFurnitureManager.instance().loadedFurnitureByColliderEntityId(collisionEntity.getId());
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes furniture
|
|
|
|
|
*
|
|
|
|
|
|