mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-21 16:47:57 +01:00
Finish 23w31a
This commit is contained in:
parent
e12d491b53
commit
9df7debb7e
@ -86,7 +86,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
}
|
||||
}
|
||||
|
||||
MappedItem data = protocol.getMappingData().getMappedItem(item.identifier());
|
||||
MappedItem data = protocol.getMappingData() != null ? protocol.getMappingData().getMappedItem(item.identifier()) : null;
|
||||
if (data == null) {
|
||||
// Just rewrite the id
|
||||
return super.handleItemToClient(item);
|
||||
|
@ -55,7 +55,7 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol<ClientboundPac
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
super.registerPackets();
|
||||
Via.getManager().debugHandler().setEnabled(true);
|
||||
;
|
||||
|
||||
registerClientbound(ClientboundPackets1_20_2.SCOREBOARD_OBJECTIVE, wrapper -> {
|
||||
final int slot = wrapper.read(Type.VAR_INT);
|
||||
@ -68,13 +68,13 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol<ClientboundPac
|
||||
|
||||
// We can't set the internal state to configuration here as protocols down the line will expect the state to be play
|
||||
wrapper.user().put(new ConfigurationPacketStorage());
|
||||
System.out.println(wrapper.user().getProtocolInfo().getState());
|
||||
});
|
||||
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.FINISH_CONFIGURATION.getId(), ClientboundConfigurationPackets1_20_2.FINISH_CONFIGURATION.getId(), wrapper -> {
|
||||
wrapper.cancel();
|
||||
wrapper.create(ServerboundConfigurationPackets1_20_2.FINISH_CONFIGURATION).sendToServer(Protocol1_20To1_20_2.class);
|
||||
wrapper.user().getProtocolInfo().setState(State.PLAY);
|
||||
wrapper.user().get(ConfigurationPacketStorage.class).setFinished(true);
|
||||
});
|
||||
|
||||
registerServerbound(State.LOGIN, ServerboundLoginPackets.HELLO.getId(), ServerboundLoginPackets.HELLO.getId(), wrapper -> {
|
||||
@ -85,7 +85,7 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol<ClientboundPac
|
||||
wrapper.write(Type.UUID, uuid != null ? uuid : new UUID(0, 0));
|
||||
});
|
||||
|
||||
cancelClientbound(ClientboundPackets1_20_2.START_CONFIGURATION); // TODO
|
||||
cancelClientbound(ClientboundPackets1_20_2.START_CONFIGURATION); // TODO Implement switch back
|
||||
|
||||
// Some can be directly remapped to play packets, others need to be queued
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.DISCONNECT.getId(), ClientboundPackets1_19_4.DISCONNECT.getId());
|
||||
@ -118,7 +118,7 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol<ClientboundPac
|
||||
@Override
|
||||
public void transform(final Direction direction, final State state, final PacketWrapper wrapper) throws Exception {
|
||||
final ConfigurationPacketStorage configurationPacketStorage = wrapper.user().get(ConfigurationPacketStorage.class);
|
||||
if (configurationPacketStorage == null) {
|
||||
if (configurationPacketStorage == null || configurationPacketStorage.isFinished()) {
|
||||
super.transform(direction, state, wrapper);
|
||||
return;
|
||||
}
|
||||
@ -138,9 +138,7 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol<ClientboundPac
|
||||
} else if (id == ServerboundPackets1_19_4.RESOURCE_PACK_STATUS.getId()) {
|
||||
wrapper.setPacketType(ServerboundConfigurationPackets1_20_2.RESOURCE_PACK);
|
||||
} else {
|
||||
// Can't do
|
||||
// TODO Queue
|
||||
System.out.println("Cancelling: " + state + " - " + wrapper.getPacketType() + " " + wrapper.getId());
|
||||
// Can't do (maybe should do?)
|
||||
throw CancelException.generate();
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18T
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.rewriter.RecipeRewriter1_19_4;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.RecipeRewriter1_20_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.type.ChunkType1_20_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20to1_19_4.Protocol1_20To1_19_4;
|
||||
import com.viaversion.viaversion.util.MathUtil;
|
||||
@ -44,7 +46,13 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
@Override
|
||||
public void registerPackets() {
|
||||
protocol.cancelClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_START);
|
||||
protocol.cancelClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_FINISHED);
|
||||
protocol.registerClientbound(ClientboundPackets1_20_2.CHUNK_BATCH_FINISHED, null, wrapper -> {
|
||||
wrapper.cancel();
|
||||
|
||||
final PacketWrapper receivedPacket = wrapper.create(ServerboundPackets1_20_2.CHUNK_BATCH_RECEIVED);
|
||||
receivedPacket.write(Type.FLOAT, 500F); // Requested next batch size... arbitrary value here
|
||||
receivedPacket.sendToServer(Protocol1_20To1_20_2.class);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_20_2.UNLOAD_CHUNK, wrapper -> {
|
||||
final ChunkPosition chunkPosition = wrapper.read(Type.CHUNK_POSITION);
|
||||
@ -214,7 +222,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
}
|
||||
});
|
||||
|
||||
new RecipeRewriter1_19_4<ClientboundPackets1_20_2>(protocol) {
|
||||
new RecipeRewriter1_20_2<ClientboundPackets1_20_2>(protocol) {
|
||||
@Override
|
||||
public void handleCraftingShapeless(final PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
|
@ -47,7 +47,7 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final ConfigurationPacketStorage configurationPacketStorage = wrapper.user().get(ConfigurationPacketStorage.class);
|
||||
final ConfigurationPacketStorage configurationPacketStorage = wrapper.user().remove(ConfigurationPacketStorage.class);
|
||||
wrapper.passthrough(Type.INT); // Entity id
|
||||
wrapper.passthrough(Type.BOOLEAN); // Hardcore
|
||||
|
||||
@ -75,8 +75,8 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
|
||||
wrapper.write(Type.BOOLEAN, reducedDebugInfo);
|
||||
wrapper.write(Type.BOOLEAN, showRespawnScreen);
|
||||
|
||||
wrapper.cancel();
|
||||
wrapper.send(Protocol1_20To1_20_2.class);
|
||||
wrapper.cancel();
|
||||
|
||||
final PacketWrapper featuresPacket = wrapper.create(ClientboundPackets1_19_4.UPDATE_ENABLED_FEATURES);
|
||||
featuresPacket.write(Type.STRING_ARRAY, configurationPacketStorage.enabledFeatures());
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.storage;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.Protocol1_20To1_20_2;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
@ -33,8 +34,10 @@ public final class ConfigurationPacketStorage implements StorableObject {
|
||||
private final List<QueuedPacket> rawPackets = new ArrayList<>();
|
||||
private CompoundTag registry;
|
||||
private String[] enabledFeatures;
|
||||
private boolean finished;
|
||||
|
||||
public CompoundTag registry() {
|
||||
Preconditions.checkNotNull(registry);
|
||||
return registry;
|
||||
}
|
||||
|
||||
@ -43,6 +46,7 @@ public final class ConfigurationPacketStorage implements StorableObject {
|
||||
}
|
||||
|
||||
public String[] enabledFeatures() {
|
||||
Preconditions.checkNotNull(enabledFeatures);
|
||||
return enabledFeatures;
|
||||
}
|
||||
|
||||
@ -50,14 +54,9 @@ public final class ConfigurationPacketStorage implements StorableObject {
|
||||
this.enabledFeatures = enabledFeatures;
|
||||
}
|
||||
|
||||
public List<QueuedPacket> getRawPackets() {
|
||||
return rawPackets;
|
||||
}
|
||||
|
||||
public void addRawPacket(final PacketWrapper wrapper, final PacketType type) throws Exception {
|
||||
// It's easier to just copy it to a byte array buffer than to manually read the data
|
||||
final ByteBuf buf = Unpooled.buffer();
|
||||
final int id = wrapper.getId();
|
||||
//noinspection deprecation
|
||||
wrapper.setId(-1); // Don't write the packet id to the buffer
|
||||
wrapper.writeToBuffer(buf);
|
||||
@ -75,6 +74,14 @@ public final class ConfigurationPacketStorage implements StorableObject {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
public void setFinished(final boolean finished) {
|
||||
this.finished = finished;
|
||||
}
|
||||
|
||||
public static final class QueuedPacket {
|
||||
private final ByteBuf buf;
|
||||
private final PacketType packetType;
|
||||
|
Loading…
Reference in New Issue
Block a user