9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-27 19:09:08 +00:00

优化发送的网络包

This commit is contained in:
jhqwqmc
2025-10-28 08:39:25 +08:00
parent f84bf4a218
commit 986b5984bc

View File

@@ -2,7 +2,6 @@ package net.momirealms.craftengine.bukkit.plugin.network.payload.protocol;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
import net.momirealms.craftengine.bukkit.util.RegistryUtils;
import net.momirealms.craftengine.core.block.ImmutableBlockState;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.network.ModPacket;
@@ -35,11 +34,13 @@ public record VisualBlockStatePacket(int[] data) implements ModPacket {
}
public static VisualBlockStatePacket create() {
int[] mappings = new int[RegistryUtils.currentBlockRegistrySize()];
for (int i = 0; i < Config.serverSideBlocks(); i++) {
ImmutableBlockState state = BukkitBlockManager.instance().getImmutableBlockStateUnsafe(i + BlockStateUtils.vanillaBlockStateCount());
int vanillaBlockStateCount = BlockStateUtils.vanillaBlockStateCount();
int serverSideBlockCount = Config.serverSideBlocks();
int[] mappings = new int[serverSideBlockCount];
for (int i = 0; i < serverSideBlockCount; i++) {
ImmutableBlockState state = BukkitBlockManager.instance().getImmutableBlockStateUnsafe(i + vanillaBlockStateCount);
if (state.isEmpty()) continue;
mappings[state.customBlockState().registryId()] = state.vanillaBlockState().registryId();
mappings[state.customBlockState().registryId() - vanillaBlockStateCount] = state.vanillaBlockState().registryId();
}
return new VisualBlockStatePacket(mappings);
}