fix: getVelocity
getVelocity теперь нормально возвращает ускорение(только вот hover в джетпаке всё равно не работает)
This commit is contained in:
@@ -69,6 +69,15 @@ socket-server-enable: on
|
||||
socket-port: 2304
|
||||
```
|
||||
|
||||
## Консольные команды
|
||||
|
||||
+ custom_items - вывводит список кастумных предметов
|
||||
+ custom_blocks - вывводит список кастумных блоков
|
||||
+ mods - вывводит список модификаций на сервере
|
||||
+ inner_core_network - вывводит список игроков подключенных к иннеру на сервере
|
||||
+ state - вывводит state блока по runtimeId
|
||||
+ player_info - вывводит доп информацию об игроке
|
||||
|
||||
## Лицензия
|
||||
|
||||

|
||||
|
||||
@@ -22,6 +22,7 @@ import cn.nukkit.potion.Effect;
|
||||
import com.reider745.api.ReflectHelper;
|
||||
import com.reider745.hooks.ItemUtils;
|
||||
import com.reider745.world.BlockSourceMethods;
|
||||
import io.netty.util.collection.LongObjectHashMap;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -337,14 +338,15 @@ public class EntityMethod {
|
||||
}
|
||||
|
||||
public static void getVelocity(long unwrapEntity, float[] pos) {
|
||||
Entity entity = getEntityToLong(unwrapEntity);
|
||||
final Entity entity = getEntityToLong(unwrapEntity);
|
||||
if(entity != null){
|
||||
if(entity.lastX == 0 || entity.lastY == 0 || entity.lastZ == 0)
|
||||
return;
|
||||
final double[] velocity = EntityMotion.getVelocity(entity);
|
||||
|
||||
pos[0] = (float) (entity.x - entity.lastX);
|
||||
pos[1] = (float) (entity.y - entity.lastY);
|
||||
pos[2] = (float) (entity.z - entity.lastZ);
|
||||
pos[0] = (float) velocity[0];
|
||||
pos[1] = (float) velocity[1];
|
||||
pos[2] = (float) velocity[2];
|
||||
|
||||
System.out.println(Arrays.toString(pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.reider745.entity;
|
||||
|
||||
import cn.nukkit.entity.Entity;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class EntityMotion {
|
||||
private static final ConcurrentHashMap<Entity, double[]> positionsLast = new ConcurrentHashMap<>();
|
||||
private static final ConcurrentHashMap<Entity, double[]> positionsCurrent = new ConcurrentHashMap<>();
|
||||
private static final double[] EMPTY = new double[]{0, 0, 0};
|
||||
|
||||
public static double[] getVelocity(final Entity entity){
|
||||
final double[] lastPos = positionsLast.get(entity);
|
||||
final double[] currentPos = positionsCurrent.get(entity);
|
||||
if(lastPos != null && currentPos != null)
|
||||
return new double[]{
|
||||
currentPos[0] - lastPos[0],
|
||||
currentPos[1] - lastPos[1],
|
||||
currentPos[2] - lastPos[2]
|
||||
};
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
public static void tick(){
|
||||
for (final Entity entity : positionsCurrent.keySet())
|
||||
positionsLast.put(entity, positionsCurrent.put(entity, new double[]{entity.x, entity.y, entity.z}));
|
||||
}
|
||||
|
||||
public static void added(final Entity entity){
|
||||
final double[] pos = new double[]{entity.x, entity.y, entity.z};
|
||||
positionsLast.put(entity, pos);
|
||||
positionsCurrent.put(entity, pos);
|
||||
}
|
||||
|
||||
public static void remove(final Entity entity){
|
||||
positionsLast.remove(entity);
|
||||
positionsCurrent.remove(entity);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import cn.nukkit.math.Vector3;
|
||||
|
||||
import com.reider745.api.CallbackHelper;
|
||||
import com.reider745.entity.EntityMethod;
|
||||
import com.reider745.entity.EntityMotion;
|
||||
import com.reider745.hooks.ItemUtils;
|
||||
import com.zhekasmirnov.horizon.runtime.logger.Logger;
|
||||
import com.zhekasmirnov.innercore.api.NativeCallback;
|
||||
@@ -145,6 +146,8 @@ public class EventListener implements Listener {
|
||||
public void onEntitySpawn(EntitySpawnEvent event) {
|
||||
final Entity entity = event.getEntity();
|
||||
|
||||
EntityMotion.added(entity);
|
||||
|
||||
if (entity instanceof EntityXPOrb xpOrb) {
|
||||
NativeCallback.onExpOrbsSpawned(entity.getLevel(), xpOrb.getExp(), (float) entity.x, (float) entity.y,
|
||||
(float) entity.z, entity.getId());
|
||||
@@ -154,7 +157,10 @@ public class EventListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onEntityDespawn(EntityDespawnEvent event) {
|
||||
NativeCallback.onEntityRemoved(event.getEntity().getId());
|
||||
final Entity entity = event.getEntity();
|
||||
|
||||
EntityMotion.remove(entity);
|
||||
NativeCallback.onEntityRemoved(entity.getId());
|
||||
}
|
||||
|
||||
private static int convertDamageCauseToEnum(DamageCause cause) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.reider745.api.hooks.HookClass;
|
||||
import com.reider745.api.hooks.TypeHook;
|
||||
import com.reider745.api.hooks.annotation.Inject;
|
||||
import com.reider745.api.hooks.annotation.Hooks;
|
||||
import com.reider745.entity.EntityMotion;
|
||||
import com.zhekasmirnov.innercore.api.NativeCallback;
|
||||
|
||||
@Hooks(className = "cn.nukkit.Server")
|
||||
@@ -54,6 +55,7 @@ public class ServerHooks implements HookClass {
|
||||
|
||||
@Inject
|
||||
public static void checkTickUpdates(Server server, int tick) {
|
||||
EntityMotion.tick();
|
||||
NativeCallback.onTick();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user