mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-23 08:59:27 +00:00
0.0.55.1
This commit is contained in:
@@ -4,6 +4,7 @@ import com.mojang.datafixers.util.Pair;
|
|||||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||||
import net.momirealms.craftengine.bukkit.plugin.network.BukkitNetworkManager;
|
import net.momirealms.craftengine.bukkit.plugin.network.BukkitNetworkManager;
|
||||||
|
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||||
import net.momirealms.craftengine.core.util.RandomUtils;
|
import net.momirealms.craftengine.core.util.RandomUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
@@ -20,29 +21,44 @@ import java.util.List;
|
|||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
public class PlayerUtils {
|
public final class PlayerUtils {
|
||||||
|
private PlayerUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
private PlayerUtils() {}
|
public static void resendItemInHand(@NotNull final Player player) {
|
||||||
|
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||||
|
if (ItemUtils.isEmpty(itemInHand)) return;
|
||||||
|
Object serverPlayer = FastNMS.INSTANCE.method$CraftPlayer$getHandle(player);
|
||||||
|
try {
|
||||||
|
Object inventoryMenu = Reflections.field$Player$inventoryMenu.get(serverPlayer);
|
||||||
|
int containerId = Reflections.field$AbstractContainerMenu$containerId.getInt(inventoryMenu);
|
||||||
|
int heldItemSlot = player.getInventory().getHeldItemSlot();
|
||||||
|
int stateId = (int) Reflections.method$AbstractContainerMenu$incrementStateId.invoke(inventoryMenu);
|
||||||
|
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
CraftEngine.instance().logger().warn("Failed to resend item in hand", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void dropItem(@NotNull Player player, @NotNull ItemStack itemStack, boolean retainOwnership, boolean noPickUpDelay, boolean throwRandomly) {
|
public static void dropItem(@NotNull Player player, @NotNull ItemStack itemStack, boolean retainOwnership, boolean noPickUpDelay, boolean throwRandomly) {
|
||||||
requireNonNull(player, "player");
|
requireNonNull(player, "player");
|
||||||
requireNonNull(itemStack, "itemStack");
|
requireNonNull(itemStack, "itemStack");
|
||||||
Location location = player.getLocation().clone();
|
Location location = player.getLocation().clone();
|
||||||
Item item = player.getWorld().dropItem(player.getEyeLocation().clone().subtract(new Vector(0,0.3,0)), itemStack);
|
Item item = player.getWorld().dropItem(player.getEyeLocation().clone().subtract(new Vector(0, 0.3, 0)), itemStack);
|
||||||
item.setPickupDelay(noPickUpDelay ? 0 : 40);
|
item.setPickupDelay(noPickUpDelay ? 0 : 40);
|
||||||
item.setOwner(player.getUniqueId());
|
item.setOwner(player.getUniqueId());
|
||||||
if (retainOwnership) {
|
if (retainOwnership) {
|
||||||
item.setThrower(player.getUniqueId());
|
item.setThrower(player.getUniqueId());
|
||||||
}
|
}
|
||||||
if (throwRandomly) {
|
if (throwRandomly) {
|
||||||
double d1 = RandomUtils.generateRandomDouble(0,1) * 0.5f;
|
double d1 = RandomUtils.generateRandomDouble(0, 1) * 0.5f;
|
||||||
double d2 = RandomUtils.generateRandomDouble(0,1) * (Math.PI * 2);
|
double d2 = RandomUtils.generateRandomDouble(0, 1) * (Math.PI * 2);
|
||||||
item.setVelocity(new Vector(-Math.sin(d2) * d1, 0.2f, Math.cos(d2) * d1));
|
item.setVelocity(new Vector(-Math.sin(d2) * d1, 0.2f, Math.cos(d2) * d1));
|
||||||
} else {
|
} else {
|
||||||
double d1 = Math.sin(location.getPitch() * (Math.PI/180));
|
double d1 = Math.sin(location.getPitch() * (Math.PI / 180));
|
||||||
double d2 = RandomUtils.generateRandomDouble(0, 0.02);
|
double d2 = RandomUtils.generateRandomDouble(0, 0.02);
|
||||||
double d3 = RandomUtils.generateRandomDouble(0,1) * (Math.PI * 2);
|
double d3 = RandomUtils.generateRandomDouble(0, 1) * (Math.PI * 2);
|
||||||
Vector vector = location.getDirection().multiply(0.3).setY(-d1 * 0.3 + 0.1 + (RandomUtils.generateRandomDouble(0,1) - RandomUtils.generateRandomDouble(0,1)) * 0.1);
|
Vector vector = location.getDirection().multiply(0.3).setY(-d1 * 0.3 + 0.1 + (RandomUtils.generateRandomDouble(0, 1) - RandomUtils.generateRandomDouble(0, 1)) * 0.1);
|
||||||
vector.add(new Vector(Math.cos(d3) * d2, 0, Math.sin(d3) * d2));
|
vector.add(new Vector(Math.cos(d3) * d2, 0, Math.sin(d3) * d2));
|
||||||
item.setVelocity(vector);
|
item.setVelocity(vector);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6982,4 +6982,21 @@ public class Reflections {
|
|||||||
"nbt.Tag"
|
"nbt.Tag"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static final Class<?> clazz$InventoryMenu = requireNonNull(
|
||||||
|
BukkitReflectionUtils.findReobfOrMojmapClass(
|
||||||
|
"world.inventory.ContainerPlayer",
|
||||||
|
"world.inventory.InventoryMenu"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final Field field$Player$inventoryMenu = requireNonNull(
|
||||||
|
ReflectionUtils.getDeclaredField(clazz$Player, clazz$InventoryMenu, 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final Method method$AbstractContainerMenu$incrementStateId = requireNonNull(
|
||||||
|
ReflectionUtils.getMethod(
|
||||||
|
clazz$AbstractContainerMenu, int.class, new String[]{"incrementStateId", "k"}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
|
|
||||||
# Project settings
|
# Project settings
|
||||||
# Rule: [major update].[feature update].[bug fix]
|
# Rule: [major update].[feature update].[bug fix]
|
||||||
project_version=0.0.55
|
project_version=0.0.55.1
|
||||||
config_version=34
|
config_version=34
|
||||||
lang_version=14
|
lang_version=14
|
||||||
project_group=net.momirealms
|
project_group=net.momirealms
|
||||||
|
|||||||
Reference in New Issue
Block a user