mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-01 05:58:00 +01:00
Fixed vehicles + added PlayerStartFlyingEvent & PlayerStopFlyingEvent
This commit is contained in:
parent
c73ec6f0d6
commit
e26ee1380a
@ -181,11 +181,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
Runnable runnable = () -> {
|
||||
refreshPosition(position.getX(), position.getY(), position.getZ());
|
||||
refreshView(position.getYaw(), position.getPitch());
|
||||
EntityTeleportPacket entityTeleportPacket = new EntityTeleportPacket();
|
||||
entityTeleportPacket.entityId = getEntityId();
|
||||
entityTeleportPacket.position = position;
|
||||
entityTeleportPacket.onGround = isOnGround();
|
||||
sendPacketToViewers(entityTeleportPacket);
|
||||
sendSynchronization();
|
||||
};
|
||||
|
||||
if (instance.hasEnabledAutoChunkLoad()) {
|
||||
@ -329,8 +325,6 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
velocity.setX(velocity.getX() * drag);
|
||||
velocity.setZ(velocity.getZ() * drag);
|
||||
|
||||
|
||||
sendSynchronization();
|
||||
if (shouldSendVelocityUpdate(time)) {
|
||||
sendPacketToViewers(getVelocityPacket());
|
||||
lastVelocityUpdateTime = time;
|
||||
@ -706,13 +700,6 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
position.setPitch(pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask for a synchronization (position) to happen during next entity update
|
||||
*/
|
||||
public void askSynchronization() {
|
||||
this.lastSynchronizationTime = 0;
|
||||
}
|
||||
|
||||
public void refreshSneaking(boolean sneaking) {
|
||||
this.crouched = sneaking;
|
||||
this.pose = sneaking ? Pose.SNEAKING : Pose.STANDING;
|
||||
@ -927,9 +914,13 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
entityTeleportPacket.position = getPosition();
|
||||
entityTeleportPacket.onGround = isOnGround();
|
||||
sendPacketToViewers(entityTeleportPacket);
|
||||
}
|
||||
|
||||
if (!passengers.isEmpty())
|
||||
sendPacketToViewers(getPassengersPacket());
|
||||
/**
|
||||
* Ask for a synchronization (position) to happen during next entity update
|
||||
*/
|
||||
public void askSynchronization() {
|
||||
this.lastSynchronizationTime = 0;
|
||||
}
|
||||
|
||||
private boolean shouldUpdate(long time) {
|
||||
|
@ -736,10 +736,6 @@ public class Player extends LivingEntity {
|
||||
}
|
||||
|
||||
protected void onChunkChange(Chunk lastChunk, Chunk newChunk) {
|
||||
float dx = newChunk.getChunkX() - lastChunk.getChunkX();
|
||||
float dz = newChunk.getChunkZ() - lastChunk.getChunkZ();
|
||||
double distance = Math.sqrt(dx * dx + dz * dz);
|
||||
|
||||
long[] lastVisibleChunks = ChunkUtils.getChunksInRange(new Position(16 * lastChunk.getChunkX(), 0, 16 * lastChunk.getChunkZ()), MinecraftServer.CHUNK_VIEW_DISTANCE);
|
||||
long[] updatedVisibleChunks = ChunkUtils.getChunksInRange(new Position(16 * newChunk.getChunkX(), 0, 16 * newChunk.getChunkZ()), MinecraftServer.CHUNK_VIEW_DISTANCE);
|
||||
int[] oldChunks = ArrayUtils.getDifferencesBetweenArray(lastVisibleChunks, updatedVisibleChunks);
|
||||
@ -766,7 +762,8 @@ public class Player extends LivingEntity {
|
||||
int[] chunkPos = ChunkUtils.getChunkCoord(updatedVisibleChunks[index]);
|
||||
instance.loadOptionalChunk(chunkPos[0], chunkPos[1], chunk -> {
|
||||
if (chunk == null) {
|
||||
return; // Cannot load chunk (auto load is not enabled)
|
||||
// Cannot load chunk (auto load is not enabled)
|
||||
return;
|
||||
}
|
||||
this.viewableChunks.add(chunk);
|
||||
chunk.addViewer(this);
|
||||
|
@ -0,0 +1,18 @@
|
||||
package net.minestom.server.event.player;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.Event;
|
||||
|
||||
public class PlayerStartFlyingEvent extends Event {
|
||||
|
||||
private Player player;
|
||||
|
||||
public PlayerStartFlyingEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package net.minestom.server.event.player;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.Event;
|
||||
|
||||
public class PlayerStopFlyingEvent extends Event {
|
||||
|
||||
private Player player;
|
||||
|
||||
public PlayerStopFlyingEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
@ -406,11 +406,11 @@ public class Chunk implements Viewable {
|
||||
this.biomes = null;
|
||||
this.blocksId = null;
|
||||
this.customBlocksId = null;
|
||||
this.blocksData.clear();
|
||||
this.updatableBlocks.clear();
|
||||
this.updatableBlocksLastUpdate.clear();
|
||||
this.blockEntities.clear();
|
||||
this.viewers.clear();
|
||||
this.blocksData = null;
|
||||
this.updatableBlocks = null;
|
||||
this.updatableBlocksLastUpdate = null;
|
||||
this.blockEntities = null;
|
||||
this.viewers = null;
|
||||
}
|
||||
|
||||
private int getBlockIndex(int x, int y, int z) {
|
||||
|
@ -73,6 +73,9 @@ public class BlockBatch implements InstanceBatch {
|
||||
boolean isLast = counter == data.size();
|
||||
batchesPool.execute(() -> {
|
||||
synchronized (chunk) {
|
||||
if (!chunk.isLoaded())
|
||||
return;
|
||||
|
||||
for (BlockData data : dataList) {
|
||||
data.apply(chunk);
|
||||
}
|
||||
|
@ -94,6 +94,9 @@ public class ChunkBatch implements InstanceBatch {
|
||||
|
||||
private void singleThreadFlush(Consumer<Chunk> callback) {
|
||||
synchronized (chunk) {
|
||||
if (!chunk.isLoaded())
|
||||
return;
|
||||
|
||||
for (BlockData data : dataList) {
|
||||
data.apply(chunk);
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package net.minestom.server.listener;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.player.PlayerStartFlyingEvent;
|
||||
import net.minestom.server.event.player.PlayerStopFlyingEvent;
|
||||
import net.minestom.server.network.packet.client.play.ClientPlayerAbilitiesPacket;
|
||||
|
||||
public class AbilitiesListener {
|
||||
|
||||
public static void listener(ClientPlayerAbilitiesPacket packet, Player player) {
|
||||
final boolean canFly = player.isAllowFlying() || player.isCreative();
|
||||
|
||||
if (canFly) {
|
||||
boolean isFlying = (packet.flags & 0x2) > 0;
|
||||
|
||||
if (isFlying) {
|
||||
PlayerStartFlyingEvent startFlyingEvent = new PlayerStartFlyingEvent(player);
|
||||
player.callEvent(PlayerStartFlyingEvent.class, startFlyingEvent);
|
||||
} else {
|
||||
PlayerStopFlyingEvent stopFlyingEvent = new PlayerStopFlyingEvent(player);
|
||||
player.callEvent(PlayerStopFlyingEvent.class, stopFlyingEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ import net.minestom.server.entity.type.EntityBoat;
|
||||
import net.minestom.server.network.packet.client.play.ClientSteerBoatPacket;
|
||||
import net.minestom.server.network.packet.client.play.ClientSteerVehiclePacket;
|
||||
import net.minestom.server.network.packet.client.play.ClientVehicleMovePacket;
|
||||
import net.minestom.server.network.packet.server.play.VehicleMovePacket;
|
||||
import net.minestom.server.utils.Position;
|
||||
|
||||
public class PlayerVehicleListener {
|
||||
@ -29,13 +28,14 @@ public class PlayerVehicleListener {
|
||||
vehicle.refreshView(packet.yaw, packet.pitch);
|
||||
vehicle.askSynchronization();
|
||||
|
||||
VehicleMovePacket vehicleMovePacket = new VehicleMovePacket();
|
||||
// This packet causes weird screen distortion
|
||||
/*VehicleMovePacket vehicleMovePacket = new VehicleMovePacket();
|
||||
vehicleMovePacket.x = packet.x;
|
||||
vehicleMovePacket.y = packet.y;
|
||||
vehicleMovePacket.z = packet.z;
|
||||
vehicleMovePacket.yaw = packet.yaw;
|
||||
vehicleMovePacket.pitch = packet.pitch;
|
||||
player.getPlayerConnection().sendPacket(vehicleMovePacket);
|
||||
player.getPlayerConnection().sendPacket(vehicleMovePacket);*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ public class PacketListenerManager {
|
||||
addListener(ClientCraftRecipeRequest.class, RecipeListener::listener);
|
||||
addListener(ClientTabCompletePacket.class, TabCompleteListener::listener);
|
||||
addListener(ClientPluginMessagePacket.class, PluginMessageListener::listener);
|
||||
addListener(ClientPlayerAbilitiesPacket.class, AbilitiesListener::listener);
|
||||
}
|
||||
|
||||
public <T extends ClientPlayPacket> void process(T packet, Player player) {
|
||||
|
@ -24,7 +24,7 @@ public class PacketUtils {
|
||||
Utils.writeVarIntBuf(buffer, length);
|
||||
buffer.writeBytes(bytes);
|
||||
|
||||
//System.out.println("WRITE PACKET: " + id + " " + serverPacket.getClass().getSimpleName() + " size: " + length);
|
||||
//System.out.println("WRITE PACKET: " + id + " " + serverPacket.getClass().getSimpleName());
|
||||
|
||||
return Unpooled.copiedBuffer(buffer);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user