mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
修改packet id
This commit is contained in:
@@ -149,7 +149,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
registerNMSPacketConsumer(PacketConsumers.SIGN_UPDATE, Reflections.clazz$ServerboundSignUpdatePacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.EDIT_BOOK, Reflections.clazz$ServerboundEditBookPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.CUSTOM_PAYLOAD, Reflections.clazz$ServerboundCustomPayloadPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.SET_ENTITY_DATA, Reflections.clazz$ClientboundSetEntityDataPacket);
|
||||
// registerNMSPacketConsumer(PacketConsumers.SET_ENTITY_DATA, Reflections.clazz$ClientboundSetEntityDataPacket);
|
||||
// registerNMSPacketConsumer(PacketConsumers.OPEN_SCREEN, Reflections.clazz$ClientboundOpenScreenPacket);
|
||||
registerByteBufPacketConsumer(PacketConsumers.SECTION_BLOCK_UPDATE, this.packetIds.clientboundSectionBlocksUpdatePacket());
|
||||
registerByteBufPacketConsumer(PacketConsumers.BLOCK_UPDATE, this.packetIds.clientboundBlockUpdatePacket());
|
||||
|
||||
@@ -83,6 +83,7 @@ public class PacketConsumers {
|
||||
return mappingsMOD[stateId];
|
||||
}
|
||||
|
||||
// TODO Use bytebuffer?
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> LEVEL_CHUNK_WITH_LIGHT = (user, event, packet) -> {
|
||||
try {
|
||||
if (user.clientModEnabled()) {
|
||||
@@ -657,6 +658,7 @@ public class PacketConsumers {
|
||||
Reflections.field$ServerPlayer$connection.get(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)), FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(itemStack));
|
||||
}
|
||||
|
||||
// TODO USE bytebuffer
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> ADD_ENTITY = (user, event, packet) -> {
|
||||
try {
|
||||
Object entityType = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$type(packet);
|
||||
@@ -695,6 +697,7 @@ public class PacketConsumers {
|
||||
};
|
||||
|
||||
// 1.21.3+
|
||||
// TODO USE bytebuffer
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SYNC_ENTITY_POSITION = (user, event, packet) -> {
|
||||
try {
|
||||
int entityId = (int) Reflections.field$ClientboundEntityPositionSyncPacket$id.get(packet);
|
||||
@@ -706,6 +709,7 @@ public class PacketConsumers {
|
||||
}
|
||||
};
|
||||
|
||||
// TODO USE bytebuffer
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> MOVE_ENTITY = (user, event, packet) -> {
|
||||
try {
|
||||
int entityId = (int) Reflections.field$ClientboundMoveEntityPacket$entityId.get(packet);
|
||||
@@ -717,6 +721,7 @@ public class PacketConsumers {
|
||||
}
|
||||
};
|
||||
|
||||
// TODO USE bytebuffer
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> REMOVE_ENTITY = (user, event, packet) -> {
|
||||
try {
|
||||
IntList intList = FastNMS.INSTANCE.field$ClientboundRemoveEntitiesPacket$entityIds(packet);
|
||||
@@ -796,6 +801,7 @@ public class PacketConsumers {
|
||||
}
|
||||
};
|
||||
|
||||
// TODO USE bytebuffer
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SOUND = (user, event, packet) -> {
|
||||
try {
|
||||
Object soundEvent = FastNMS.INSTANCE.field$ClientboundSoundPacket$soundEvent(packet);
|
||||
@@ -1006,38 +1012,38 @@ public class PacketConsumers {
|
||||
}
|
||||
};
|
||||
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SET_ENTITY_DATA = (user, event, packet) -> {
|
||||
try {
|
||||
int id = FastNMS.INSTANCE.field$ClientboundSetEntityDataPacket$id(packet);
|
||||
Object entityType = user.entityView().get(id);
|
||||
if (entityType == Reflections.instance$EntityType$BLOCK_DISPLAY) {
|
||||
List<Object> packedItems = FastNMS.INSTANCE.field$ClientboundSetEntityDataPacket$packedItems(packet);
|
||||
for (int i = 0; i < packedItems.size(); i++) {
|
||||
Object packedItem = packedItems.get(i);
|
||||
int entityDataId = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$id(packedItem);
|
||||
if (entityDataId != EntityDataUtils.BLOCK_STATE_DATA_ID) {
|
||||
continue;
|
||||
}
|
||||
Object blockState = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$value(packedItem);
|
||||
int stateId = BlockStateUtils.blockStateToId(blockState);
|
||||
int newStateId;
|
||||
if (!user.clientModEnabled()) {
|
||||
newStateId = remap(stateId);
|
||||
} else {
|
||||
newStateId = remapMOD(stateId);
|
||||
}
|
||||
Object serializer = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$serializer(packedItem);
|
||||
packedItems.set(i, FastNMS.INSTANCE.constructor$SynchedEntityData$DataValue(
|
||||
entityDataId, serializer, BlockStateUtils.idToBlockState(newStateId)
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// todo修改其他实体的物品的方块谓词
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundSetEntityDataPacket", e);
|
||||
}
|
||||
};
|
||||
// TODO 使用bytebuffer
|
||||
// public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SET_ENTITY_DATA = (user, event, packet) -> {
|
||||
// try {
|
||||
// int id = FastNMS.INSTANCE.field$ClientboundSetEntityDataPacket$id(packet);
|
||||
// Object entityType = user.entityView().get(id);
|
||||
// if (entityType == Reflections.instance$EntityType$BLOCK_DISPLAY) {
|
||||
// List<Object> packedItems = FastNMS.INSTANCE.field$ClientboundSetEntityDataPacket$packedItems(packet);
|
||||
// for (int i = 0; i < packedItems.size(); i++) {
|
||||
// Object packedItem = packedItems.get(i);
|
||||
// int entityDataId = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$id(packedItem);
|
||||
// if (entityDataId != EntityDataUtils.BLOCK_STATE_DATA_ID) {
|
||||
// continue;
|
||||
// }
|
||||
// Object blockState = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$value(packedItem);
|
||||
// int stateId = BlockStateUtils.blockStateToId(blockState);
|
||||
// int newStateId;
|
||||
// if (!user.clientModEnabled()) {
|
||||
// newStateId = remap(stateId);
|
||||
// } else {
|
||||
// newStateId = remapMOD(stateId);
|
||||
// }
|
||||
// Object serializer = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$serializer(packedItem);
|
||||
// packedItems.set(i, FastNMS.INSTANCE.constructor$SynchedEntityData$DataValue(
|
||||
// entityDataId, serializer, BlockStateUtils.idToBlockState(newStateId)
|
||||
// ));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// CraftEngine.instance().logger().warn("Failed to handle ClientboundSetEntityDataPacket", e);
|
||||
// }
|
||||
// };
|
||||
|
||||
// public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> OPEN_SCREEN = (user, event, packet) -> {
|
||||
// try {
|
||||
|
||||
@@ -29,9 +29,8 @@ public class PacketIds1_20_2 implements PacketIds {
|
||||
return 1;
|
||||
}
|
||||
|
||||
//TODO TEST
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
return 49;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,8 @@ public class PacketIds1_20_3 implements PacketIds {
|
||||
return 1;
|
||||
}
|
||||
|
||||
//TODO TEST
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
return 49;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,8 @@ public class PacketIds1_20_5 implements PacketIds {
|
||||
return 1;
|
||||
}
|
||||
|
||||
//TODO TEST
|
||||
@Override
|
||||
public int clientboundOpenScreenPacket() {
|
||||
return 48;
|
||||
return 51;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.scheduler.SchedulerTask;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
@@ -112,16 +113,19 @@ public class BukkitWorldManager implements WorldManager, Listener {
|
||||
world.tick();
|
||||
}
|
||||
}, 1, 1);
|
||||
|
||||
// load loaded chunks
|
||||
this.worldMapLock.writeLock().lock();
|
||||
try {
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
CEWorld ceWorld = new BukkitCEWorld(new BukkitWorld(world), this.storageAdaptor);
|
||||
this.worlds.put(world.getUID(), ceWorld);
|
||||
this.resetWorldArray();
|
||||
for (Chunk chunk : world.getLoadedChunks()) {
|
||||
handleChunkLoad(ceWorld, chunk);
|
||||
try {
|
||||
CEWorld ceWorld = new BukkitCEWorld(new BukkitWorld(world), this.storageAdaptor);
|
||||
this.worlds.put(world.getUID(), ceWorld);
|
||||
this.resetWorldArray();
|
||||
for (Chunk chunk : world.getLoadedChunks()) {
|
||||
handleChunkLoad(ceWorld, chunk);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Error loading world: " + world.getName(), e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user