mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-27 02:49:15 +00:00
拆分particle包
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.Locale;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class MMOItemsProvider implements ExternalItemProvider<ItemStack> {
|
||||
|
||||
@Override
|
||||
public String plugin() {
|
||||
return "MMOItems";
|
||||
|
||||
@@ -145,7 +145,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
registerNMSPacketConsumer(PacketConsumers.CUSTOM_PAYLOAD, Reflections.clazz$ServerboundCustomPayloadPacket);
|
||||
registerByteBufPacketConsumer(PacketConsumers.SECTION_BLOCK_UPDATE, this.packetIds.clientboundSectionBlocksUpdatePacket());
|
||||
registerByteBufPacketConsumer(PacketConsumers.BLOCK_UPDATE, this.packetIds.clientboundBlockUpdatePacket());
|
||||
registerByteBufPacketConsumer(PacketConsumers.LEVEL_PARTICLE, this.packetIds.clientboundLevelParticlesPacket());
|
||||
registerByteBufPacketConsumer(VersionHelper.isVersionNewerThan1_21_3() ? PacketConsumers.LEVEL_PARTICLE_1_21_3 : (VersionHelper.isVersionNewerThan1_20_5() ? PacketConsumers.LEVEL_PARTICLE_1_20_5 : PacketConsumers.LEVEL_PARTICLE_1_20), this.packetIds.clientboundLevelParticlesPacket());
|
||||
registerByteBufPacketConsumer(PacketConsumers.LEVEL_EVENT, this.packetIds.clientboundLevelEventPacket());
|
||||
registerByteBufPacketConsumer(VersionHelper.isVersionNewerThan1_20_3() ? PacketConsumers.OPEN_SCREEN_1_20_3 : PacketConsumers.OPEN_SCREEN_1_20, this.packetIds.clientboundOpenScreenPacket());
|
||||
registerByteBufPacketConsumer(VersionHelper.isVersionNewerThan1_20_3() ? PacketConsumers.SET_TITLE_TEXT_1_20_3 : PacketConsumers.SET_TITLE_TEXT_1_20, this.packetIds.clientboundSetTitleTextPacket());
|
||||
|
||||
@@ -913,110 +913,122 @@ public class PacketConsumers {
|
||||
}
|
||||
};
|
||||
|
||||
public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> LEVEL_PARTICLE = (user, event) -> {
|
||||
public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> LEVEL_PARTICLE_1_21_3 = (user, event) -> {
|
||||
try {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
if (VersionHelper.isVersionNewerThan1_21_3()) {
|
||||
boolean overrideLimiter = buf.readBoolean();
|
||||
boolean alwaysShow = buf.readBoolean();
|
||||
double x = buf.readDouble();
|
||||
double y = buf.readDouble();
|
||||
double z = buf.readDouble();
|
||||
float xDist = buf.readFloat();
|
||||
float yDist = buf.readFloat();
|
||||
float zDist = buf.readFloat();
|
||||
float maxSpeed = buf.readFloat();
|
||||
int count = buf.readInt();
|
||||
Object option = FastNMS.INSTANCE.method$ParticleTypes$STREAM_CODEC$decode(buf);
|
||||
if (option == null) return;
|
||||
if (!Reflections.clazz$BlockParticleOption.isInstance(option)) return;
|
||||
Object blockState = FastNMS.INSTANCE.field$BlockParticleOption$blockState(option);
|
||||
int id = BlockStateUtils.blockStateToId(blockState);
|
||||
int remapped = remap(id);
|
||||
if (remapped == id) return;
|
||||
Object type = FastNMS.INSTANCE.method$BlockParticleOption$getType(option);
|
||||
Object remappedOption = FastNMS.INSTANCE.constructor$BlockParticleOption(type, BlockStateUtils.idToBlockState(remapped));
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeBoolean(overrideLimiter);
|
||||
buf.writeBoolean(alwaysShow);
|
||||
buf.writeDouble(x);
|
||||
buf.writeDouble(y);
|
||||
buf.writeDouble(z);
|
||||
buf.writeFloat(xDist);
|
||||
buf.writeFloat(yDist);
|
||||
buf.writeFloat(zDist);
|
||||
buf.writeFloat(maxSpeed);
|
||||
buf.writeInt(count);
|
||||
FastNMS.INSTANCE.method$ParticleTypes$STREAM_CODEC$encode(buf, remappedOption);
|
||||
} else if (VersionHelper.isVersionNewerThan1_20_5()) {
|
||||
boolean overrideLimiter = buf.readBoolean();
|
||||
double x = buf.readDouble();
|
||||
double y = buf.readDouble();
|
||||
double z = buf.readDouble();
|
||||
float xDist = buf.readFloat();
|
||||
float yDist = buf.readFloat();
|
||||
float zDist = buf.readFloat();
|
||||
float maxSpeed = buf.readFloat();
|
||||
int count = buf.readInt();
|
||||
Object option = FastNMS.INSTANCE.method$ParticleTypes$STREAM_CODEC$decode(buf);
|
||||
if (option == null) return;
|
||||
if (!Reflections.clazz$BlockParticleOption.isInstance(option)) return;
|
||||
Object blockState = FastNMS.INSTANCE.field$BlockParticleOption$blockState(option);
|
||||
int id = BlockStateUtils.blockStateToId(blockState);
|
||||
int remapped = remap(id);
|
||||
if (remapped == id) return;
|
||||
Object type = FastNMS.INSTANCE.method$BlockParticleOption$getType(option);
|
||||
Object remappedOption = FastNMS.INSTANCE.constructor$BlockParticleOption(type, BlockStateUtils.idToBlockState(remapped));
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeBoolean(overrideLimiter);
|
||||
buf.writeDouble(x);
|
||||
buf.writeDouble(y);
|
||||
buf.writeDouble(z);
|
||||
buf.writeFloat(xDist);
|
||||
buf.writeFloat(yDist);
|
||||
buf.writeFloat(zDist);
|
||||
buf.writeFloat(maxSpeed);
|
||||
buf.writeInt(count);
|
||||
FastNMS.INSTANCE.method$ParticleTypes$STREAM_CODEC$encode(buf, remappedOption);
|
||||
} else {
|
||||
Object particleType = FastNMS.INSTANCE.method$FriendlyByteBuf$readById(buf, Reflections.instance$BuiltInRegistries$PARTICLE_TYPE);
|
||||
boolean overrideLimiter = buf.readBoolean();
|
||||
double x = buf.readDouble();
|
||||
double y = buf.readDouble();
|
||||
double z = buf.readDouble();
|
||||
float xDist = buf.readFloat();
|
||||
float yDist = buf.readFloat();
|
||||
float zDist = buf.readFloat();
|
||||
float maxSpeed = buf.readFloat();
|
||||
int count = buf.readInt();
|
||||
Object option = FastNMS.INSTANCE.method$ClientboundLevelParticlesPacket$readParticle(buf, particleType);
|
||||
if (option == null) return;
|
||||
if (!Reflections.clazz$BlockParticleOption.isInstance(option)) return;
|
||||
Object blockState = FastNMS.INSTANCE.field$BlockParticleOption$blockState(option);
|
||||
int id = BlockStateUtils.blockStateToId(blockState);
|
||||
int remapped = remap(id);
|
||||
if (remapped == id) return;
|
||||
Object type = FastNMS.INSTANCE.method$BlockParticleOption$getType(option);
|
||||
Object remappedOption = FastNMS.INSTANCE.constructor$BlockParticleOption(type, BlockStateUtils.idToBlockState(remapped));
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
FastNMS.INSTANCE.method$FriendlyByteBuf$writeId(buf, remappedOption, Reflections.instance$BuiltInRegistries$PARTICLE_TYPE);
|
||||
buf.writeBoolean(overrideLimiter);
|
||||
buf.writeDouble(x);
|
||||
buf.writeDouble(y);
|
||||
buf.writeDouble(z);
|
||||
buf.writeFloat(xDist);
|
||||
buf.writeFloat(yDist);
|
||||
buf.writeFloat(zDist);
|
||||
buf.writeFloat(maxSpeed);
|
||||
buf.writeInt(count);
|
||||
FastNMS.INSTANCE.method$ParticleOptions$writeToNetwork(remappedOption, buf);
|
||||
}
|
||||
boolean overrideLimiter = buf.readBoolean();
|
||||
boolean alwaysShow = buf.readBoolean();
|
||||
double x = buf.readDouble();
|
||||
double y = buf.readDouble();
|
||||
double z = buf.readDouble();
|
||||
float xDist = buf.readFloat();
|
||||
float yDist = buf.readFloat();
|
||||
float zDist = buf.readFloat();
|
||||
float maxSpeed = buf.readFloat();
|
||||
int count = buf.readInt();
|
||||
Object option = FastNMS.INSTANCE.method$ParticleTypes$STREAM_CODEC$decode(buf);
|
||||
if (option == null) return;
|
||||
if (!Reflections.clazz$BlockParticleOption.isInstance(option)) return;
|
||||
Object blockState = FastNMS.INSTANCE.field$BlockParticleOption$blockState(option);
|
||||
int id = BlockStateUtils.blockStateToId(blockState);
|
||||
int remapped = remap(id);
|
||||
if (remapped == id) return;
|
||||
Object type = FastNMS.INSTANCE.method$BlockParticleOption$getType(option);
|
||||
Object remappedOption = FastNMS.INSTANCE.constructor$BlockParticleOption(type, BlockStateUtils.idToBlockState(remapped));
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeBoolean(overrideLimiter);
|
||||
buf.writeBoolean(alwaysShow);
|
||||
buf.writeDouble(x);
|
||||
buf.writeDouble(y);
|
||||
buf.writeDouble(z);
|
||||
buf.writeFloat(xDist);
|
||||
buf.writeFloat(yDist);
|
||||
buf.writeFloat(zDist);
|
||||
buf.writeFloat(maxSpeed);
|
||||
buf.writeInt(count);
|
||||
FastNMS.INSTANCE.method$ParticleTypes$STREAM_CODEC$encode(buf, remappedOption);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundLevelParticlesPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> LEVEL_PARTICLE_1_20_5 = (user, event) -> {
|
||||
try {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
boolean overrideLimiter = buf.readBoolean();
|
||||
double x = buf.readDouble();
|
||||
double y = buf.readDouble();
|
||||
double z = buf.readDouble();
|
||||
float xDist = buf.readFloat();
|
||||
float yDist = buf.readFloat();
|
||||
float zDist = buf.readFloat();
|
||||
float maxSpeed = buf.readFloat();
|
||||
int count = buf.readInt();
|
||||
Object option = FastNMS.INSTANCE.method$ParticleTypes$STREAM_CODEC$decode(buf);
|
||||
if (option == null) return;
|
||||
if (!Reflections.clazz$BlockParticleOption.isInstance(option)) return;
|
||||
Object blockState = FastNMS.INSTANCE.field$BlockParticleOption$blockState(option);
|
||||
int id = BlockStateUtils.blockStateToId(blockState);
|
||||
int remapped = remap(id);
|
||||
if (remapped == id) return;
|
||||
Object type = FastNMS.INSTANCE.method$BlockParticleOption$getType(option);
|
||||
Object remappedOption = FastNMS.INSTANCE.constructor$BlockParticleOption(type, BlockStateUtils.idToBlockState(remapped));
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeBoolean(overrideLimiter);
|
||||
buf.writeDouble(x);
|
||||
buf.writeDouble(y);
|
||||
buf.writeDouble(z);
|
||||
buf.writeFloat(xDist);
|
||||
buf.writeFloat(yDist);
|
||||
buf.writeFloat(zDist);
|
||||
buf.writeFloat(maxSpeed);
|
||||
buf.writeInt(count);
|
||||
FastNMS.INSTANCE.method$ParticleTypes$STREAM_CODEC$encode(buf, remappedOption);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundLevelParticlesPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> LEVEL_PARTICLE_1_20 = (user, event) -> {
|
||||
try {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
Object particleType = FastNMS.INSTANCE.method$FriendlyByteBuf$readById(buf, Reflections.instance$BuiltInRegistries$PARTICLE_TYPE);
|
||||
boolean overrideLimiter = buf.readBoolean();
|
||||
double x = buf.readDouble();
|
||||
double y = buf.readDouble();
|
||||
double z = buf.readDouble();
|
||||
float xDist = buf.readFloat();
|
||||
float yDist = buf.readFloat();
|
||||
float zDist = buf.readFloat();
|
||||
float maxSpeed = buf.readFloat();
|
||||
int count = buf.readInt();
|
||||
Object option = FastNMS.INSTANCE.method$ClientboundLevelParticlesPacket$readParticle(buf, particleType);
|
||||
if (option == null) return;
|
||||
if (!Reflections.clazz$BlockParticleOption.isInstance(option)) return;
|
||||
Object blockState = FastNMS.INSTANCE.field$BlockParticleOption$blockState(option);
|
||||
int id = BlockStateUtils.blockStateToId(blockState);
|
||||
int remapped = remap(id);
|
||||
if (remapped == id) return;
|
||||
Object type = FastNMS.INSTANCE.method$BlockParticleOption$getType(option);
|
||||
Object remappedOption = FastNMS.INSTANCE.constructor$BlockParticleOption(type, BlockStateUtils.idToBlockState(remapped));
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
FastNMS.INSTANCE.method$FriendlyByteBuf$writeId(buf, remappedOption, Reflections.instance$BuiltInRegistries$PARTICLE_TYPE);
|
||||
buf.writeBoolean(overrideLimiter);
|
||||
buf.writeDouble(x);
|
||||
buf.writeDouble(y);
|
||||
buf.writeDouble(z);
|
||||
buf.writeFloat(xDist);
|
||||
buf.writeFloat(yDist);
|
||||
buf.writeFloat(zDist);
|
||||
buf.writeFloat(maxSpeed);
|
||||
buf.writeInt(count);
|
||||
FastNMS.INSTANCE.method$ParticleOptions$writeToNetwork(remappedOption, buf);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundLevelParticlesPacket", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user