3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-26 16:12:43 +01:00

Revert "Workaround for #48"

This reverts commit df53ce3e1c.
Dieser Commit ist enthalten in:
creeper123123321 2019-03-07 14:49:54 -03:00
Ursprung df53ce3e1c
Commit ce63e5ee62
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
4 geänderte Dateien mit 37 neuen und 192 gelöschten Zeilen

Datei anzeigen

@ -15,7 +15,6 @@ import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets.*;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.storage.InventoryTracker;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
@ -45,7 +44,6 @@ public class Protocol1_11_1To1_12 extends BackwardsProtocol {
user.put(new EntityTracker(user));
user.put(new ShoulderTracker(user));
user.put(new InventoryTracker(user));
// Init protocol in EntityTracker
user.get(EntityTracker.class).initProtocol(this);

Datei anzeigen

@ -10,12 +10,10 @@
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
import com.google.common.collect.Lists;
import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.MapColorMapping;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.storage.InventoryTracker;
import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
@ -29,68 +27,14 @@ import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.DoubleTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag;
import java.util.Collections;
import java.util.Iterator;
public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12> {
@Override
protected void registerPackets(Protocol1_11_1To1_12 protocol) {
/* Item packets */
// Confirm Transaction
protocol.registerOutgoing(State.PLAY, 0x11, 0x11, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // Window id
map(Type.SHORT); // Action number
map(Type.BOOLEAN); // Accepted
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper packetWrapper) throws Exception {
byte window = packetWrapper.get(Type.BYTE, 0);
boolean accepted = packetWrapper.get(Type.BOOLEAN, 0);
short actionNumber = packetWrapper.get(Type.SHORT, 0);
InventoryTracker tracker = packetWrapper.user().get(InventoryTracker.class);
boolean clear = false;
Iterator<InventoryTracker.ClickWindow> it = Lists.reverse(tracker.getClicks()).iterator();
while (it.hasNext()) {
InventoryTracker.ClickWindow entry = it.next();
if (entry.actionNumber == actionNumber || clear) {
it.remove();
clear = true;
}
}
if (!accepted) {
if (tracker.getLastTransactionWindow() == window &&
tracker.getLastShiftTransaction() != -1) {
PacketWrapper confirm = packetWrapper.create(0x6);
confirm.write(Type.BYTE, window);
confirm.write(Type.SHORT, actionNumber);
confirm.write(Type.BOOLEAN, false);
confirm.sendToServer(Protocol1_11_1To1_12.class, true, true);
}
if (tracker.getClicks().size() != 0) {
InventoryTracker.ClickWindow entry = tracker.getClicks().get(0);
PacketWrapper click = packetWrapper.create(0x8);
click.write(Type.UNSIGNED_BYTE, entry.windowId);
click.write(Type.SHORT, entry.slot);
click.write(Type.BYTE, entry.button);
click.write(Type.SHORT, entry.actionNumber);
click.write(Type.VAR_INT, entry.mode);
CompoundTag tag = new CompoundTag("");
tag.put(new DoubleTag("force reject", Double.NaN));
click.write(Type.ITEM, new Item((short) 1, (byte) 1, (short) 1, tag));
click.sendToServer(Protocol1_11_1To1_12.class, true, true);
}
}
}
});
}
});
/* Item packets */
protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() {
@Override
@ -214,35 +158,8 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
}
});
// Confirm transaction
protocol.registerIncoming(State.PLAY, 0x6, 0x5, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.BYTE); // Window id
map(Type.SHORT); // Action number
map(Type.BOOLEAN); // Accepted
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper packetWrapper) throws Exception {
byte window = packetWrapper.get(Type.BYTE, 0);
boolean accepted = packetWrapper.get(Type.BOOLEAN, 0);
short actionNumber = packetWrapper.get(Type.SHORT, 0);
InventoryTracker tracker = packetWrapper.user().get(InventoryTracker.class);
if (tracker.getLastTransactionWindow() == window &&
tracker.getLastShiftTransaction() == actionNumber) {
tracker.setLastTransactionWindow(-1);
tracker.setLastShiftTransaction(-1);
tracker.getClicks().clear();
}
}
});
}
});
// Click window packet
protocol.registerIncoming(State.PLAY, 0x08, 0x07, new
PacketRemapper() {
protocol.registerIncoming(State.PLAY, 0x08, 0x07, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
@ -255,27 +172,6 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
InventoryTracker tracker = wrapper.user().get(InventoryTracker.class);
short window = wrapper.get(Type.UNSIGNED_BYTE, 0);
short slot = wrapper.get(Type.SHORT, 0);
byte button = wrapper.get(Type.BYTE, 0);
short actionNumber = wrapper.get(Type.SHORT, 1);
int mode = wrapper.get(Type.VAR_INT, 0);
boolean changedWindow = tracker.getLastTransactionWindow() != window;
if (changedWindow) {
tracker.setLastTransactionWindow(window);
tracker.setLastShiftTransaction(-1);
tracker.getClicks().clear();
}
if (mode == 1) { // Shift click mode
tracker.setLastShiftTransaction(actionNumber);
}
if (tracker.getLastShiftTransaction() != -1) {
if (tracker.getClicks().size() < 16) {
tracker.getClicks().add(new InventoryTracker.ClickWindow(
window, slot, button, actionNumber, mode));
}
}
Item item = wrapper.get(Type.ITEM, 0);
handleItemToServer(item);
}
@ -285,9 +181,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
);
// Creative Inventory Action
protocol.registerIncoming(State.PLAY, 0x1B, 0x18, new
PacketRemapper() {
protocol.registerIncoming(State.PLAY, 0x1B, 0x18, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.SHORT); // 0 - Slot
@ -307,9 +201,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
/* Block packets */
// Chunk packet
protocol.registerOutgoing(State.PLAY, 0x20, 0x20, new
PacketRemapper() {
protocol.registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@ -328,9 +220,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
);
// Block Change Packet
protocol.registerOutgoing(State.PLAY, 0x0B, 0x0B, new
PacketRemapper() {
protocol.registerOutgoing(State.PLAY, 0x0B, 0x0B, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION); // 0 - Block Position
@ -348,9 +238,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
);
// Multi Block Change Packet
protocol.registerOutgoing(State.PLAY, 0x10, 0x10, new
PacketRemapper() {
protocol.registerOutgoing(State.PLAY, 0x10, 0x10, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Chunk X
@ -370,59 +258,49 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
);
// Update Block Entity
protocol.registerOutgoing(State.PLAY, 0x09, 0x09, new
protocol.registerOutgoing(State.PLAY, 0x09, 0x09, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION); // 0 - Position
map(Type.UNSIGNED_BYTE); // 1 - Action
map(Type.NBT); // 2 - NBT
PacketRemapper() {
handler(new PacketHandler() {
@Override
public void registerMap() {
map(Type.POSITION); // 0 - Position
map(Type.UNSIGNED_BYTE); // 1 - Action
map(Type.NBT); // 2 - NBT
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Remove bed color
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 11)
wrapper.cancel();
}
});
public void handle(PacketWrapper wrapper) throws Exception {
// Remove bed color
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 11)
wrapper.cancel();
}
});
}
});
protocol.getEntityPackets().
protocol.getEntityPackets().registerMetaHandler().handle(e -> {
Metadata data = e.getData();
registerMetaHandler().
if (data.getMetaType().getType().equals(Type.ITEM)) // Is Item
data.setValue(handleItemToClient((Item) data.getValue()));
handle(e ->
{
Metadata data = e.getData();
if (data.getMetaType().getType().equals(Type.ITEM)) // Is Item
data.setValue(handleItemToClient((Item) data.getValue()));
return data;
});
return data;
});
// Client Status
protocol.registerIncoming(State.PLAY, 0x04, 0x03, new
protocol.registerIncoming(State.PLAY, 0x04, 0x03, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Action ID
PacketRemapper() {
handler(new PacketHandler() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Action ID
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Open Inventory
if (wrapper.get(Type.VAR_INT, 0) == 2)
wrapper.cancel(); // TODO is this replaced by something else?
}
});
public void handle(PacketWrapper wrapper) throws Exception {
// Open Inventory
if (wrapper.get(Type.VAR_INT, 0) == 2)
wrapper.cancel(); // TODO is this replaced by something else?
}
});
}
});
}
@Override

Datei anzeigen

@ -92,6 +92,7 @@ public class ChangedPacketIds1_12 extends Rewriter<Protocol1_11_1To1_12> {
p.registerIncoming(State.PLAY, 0x03, 0x02); // Chat Message (Serverbound)
// 0x04->0x03 Client Status handled in BlockItemPackets1_12.java
p.registerIncoming(State.PLAY, 0x05, 0x04); // Client Settings
p.registerIncoming(State.PLAY, 0x06, 0x05); // Confirm Transaction (Serverbound)
p.registerIncoming(State.PLAY, 0x07, 0x06); // Enchant Item
// 0x08 -> 0x07 Click Window handled in BlockItemPackets1_12.java
p.registerIncoming(State.PLAY, 0x09, 0x08); // Close Window (Serverbound)

Datei anzeigen

@ -1,32 +0,0 @@
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.storage;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import java.util.ArrayList;
@Getter
@Setter
public class InventoryTracker extends StoredObject {
private int lastTransactionWindow = -1;
private int lastShiftTransaction = -1;
// Workaround for https://github.com/Matsv/ViaBackwards/issues/48
// Resent when it is rejected
private ArrayList<ClickWindow> clicks = new ArrayList<>();
public InventoryTracker(UserConnection user) {
super(user);
}
@AllArgsConstructor
public static class ClickWindow {
public short windowId;
public short slot;
public byte button;
public short actionNumber;
public int mode;
}
}