fixed: Исправлены координаты с плавающей точкой & добавлен isValid в ServerPlayerTick
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package com.reider745.api;
|
||||
|
||||
import cn.nukkit.entity.Entity;
|
||||
import cn.nukkit.level.format.FullChunk;
|
||||
import cn.nukkit.nbt.tag.CompoundTag;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -111,6 +111,10 @@ public class EntityMethod {
|
||||
return entity != null && entity.isValid();
|
||||
}
|
||||
|
||||
public static boolean isValid(long entity) {
|
||||
return isValid(getEntityById(entity));
|
||||
}
|
||||
|
||||
private static <T> T validateThen(long entityUid, Function<Entity, T> then, T defaultValue) {
|
||||
Entity entity = getEntityById(entityUid);
|
||||
if (isValid(entity)) {
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.zhekasmirnov.apparatus.multiplayer.Network;
|
||||
import oshi.hardware.NetworkIF;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.reider745.api.CallbackHelper;
|
||||
import com.reider745.api.CustomManager;
|
||||
@@ -96,6 +97,16 @@ public class EventListener implements Listener {
|
||||
level.sendBlocks(players, new Vector3[]{new Vector3(x, y, z)}, UpdateBlockPacket.FLAG_ALL);
|
||||
}
|
||||
|
||||
private static final ConcurrentHashMap<Player, Vector3> vectorPositions = new ConcurrentHashMap<>();
|
||||
|
||||
public static void setPosition(Player player, Vector3 pos){
|
||||
vectorPositions.put(player, pos);
|
||||
}
|
||||
|
||||
public static void remove(Player player){
|
||||
vectorPositions.remove(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
if (event.equals(dealingEvent) || Boolean.TRUE.equals(dealingEvent)) {
|
||||
@@ -106,7 +117,7 @@ public class EventListener implements Listener {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (event.getAction() == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
|
||||
final Vector3 pos = event.getTouchVector();
|
||||
final Vector3 pos = vectorPositions.get(player);
|
||||
|
||||
pos.x = Math.abs(pos.x) + block.x;
|
||||
pos.y = Math.abs(pos.y) + block.y;
|
||||
|
||||
@@ -18,6 +18,8 @@ import cn.nukkit.level.ChunkLoader;
|
||||
import cn.nukkit.level.GameRule;
|
||||
import cn.nukkit.level.Level;
|
||||
import cn.nukkit.level.Position;
|
||||
import cn.nukkit.level.format.LevelProvider;
|
||||
import cn.nukkit.level.format.anvil.Anvil;
|
||||
import cn.nukkit.level.format.generic.BaseFullChunk;
|
||||
import cn.nukkit.level.format.generic.BaseLevelProvider;
|
||||
import cn.nukkit.level.particle.DestroyBlockParticle;
|
||||
@@ -411,4 +413,20 @@ public class LevelHooks implements HookClass {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public static void useItemOn(Level self, Vector3 vector, Item item, BlockFace face, float fx, float fy, float fz, Player player, boolean playSound) {
|
||||
// TODO: Событие нажатия на блок от Nukkit-Mot не дает координаты с плавающей точкой
|
||||
EventListener.setPosition(player, new Vector3(fx, fy, fz));
|
||||
}
|
||||
|
||||
// TODO: Удаление поддержки leveldb(не стабилен, ломает пользовательские биомы)
|
||||
/*
|
||||
Ломает сохранение пользовательских биомов
|
||||
Имеет утечки памяти
|
||||
*/
|
||||
@Inject(className = "cn.nukkit.level.format.LevelProviderManager")
|
||||
public static Class<? extends LevelProvider> getProviderByName(String name){
|
||||
return Anvil.class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ public class PlayerHooks implements HookClass {
|
||||
@Inject(type = TypeHook.BEFORE_NOT_REPLACE)
|
||||
public static void close(Player player, TextContainer message, String reason, boolean notify) {
|
||||
NetworkHooks.close(player);
|
||||
EventListener.remove(player);
|
||||
ConnectedClient client = getForPlayer(player);
|
||||
try {
|
||||
if (client != null)
|
||||
|
||||
@@ -80,12 +80,13 @@ public class BiomesMethods {
|
||||
return json;
|
||||
}
|
||||
|
||||
// TODO: Проблема клиент не правильно обрабатывает пользовательские биомы(вероятнее всего проблема на стороне клиента)
|
||||
public static long nativeRegister(String name) {
|
||||
if(AvailableIDS.isEmpty()){
|
||||
throw new RuntimeException("MAX BIOMES!");
|
||||
}
|
||||
NukkitCustomBiome biome = new NukkitCustomBiome(null, name);
|
||||
biome.reg(AvailableIDS.remove(AvailableIDS.size()-1));
|
||||
biome.reg(AvailableIDS.remove(0));
|
||||
customBiomes.put(biome.getId(), biome);
|
||||
|
||||
// без этого дерьма работает
|
||||
|
||||
@@ -53,7 +53,7 @@ public class NetworkPlayerHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isTickCallbackDisabled) {
|
||||
if (!isTickCallbackDisabled && EntityMethod.isValid(actor.getUid())) {
|
||||
try {
|
||||
Callback.invokeCallback(isLocal ? "LocalPlayerTick" : "ServerPlayerTick", actor.getUid(), isDead);
|
||||
} catch (Throwable err) {
|
||||
|
||||
Reference in New Issue
Block a user