Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Fix brewing #141
Dieser Commit ist enthalten in:
Ursprung
713361f973
Commit
fe77df1434
@ -12,11 +12,8 @@ import us.myles.ViaVersion.packets.PacketType;
|
|||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
import us.myles.ViaVersion.slot.ItemSlotRewriter;
|
||||||
import us.myles.ViaVersion.util.PacketUtil;
|
import us.myles.ViaVersion.util.PacketUtil;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
|
|
||||||
public class IncomingTransformer {
|
public class IncomingTransformer {
|
||||||
private final ConnectionInfo info;
|
private final ConnectionInfo info;
|
||||||
@ -105,28 +102,32 @@ public class IncomingTransformer {
|
|||||||
|
|
||||||
byte button = input.readByte();
|
byte button = input.readByte();
|
||||||
short action = input.readShort();
|
short action = input.readShort();
|
||||||
byte mode = input.readByte();
|
int mode = input.readByte();
|
||||||
// if the action is on an elytra armour slot
|
|
||||||
if (slot == 45 && windowID == 0) {
|
|
||||||
try {
|
|
||||||
Class<?> setSlot = ReflectionUtil.nms("PacketPlayOutSetSlot");
|
|
||||||
Constructor setSlotConstruct = setSlot.getDeclaredConstructor(int.class, int.class, ReflectionUtil.nms("ItemStack"));
|
|
||||||
// properly construct
|
|
||||||
Object setSlotPacket = setSlotConstruct.newInstance(windowID, slot, null);
|
|
||||||
info.getChannel().pipeline().writeAndFlush(setSlotPacket); // slot is empty
|
|
||||||
slot = -999; // we're evil, they'll throw item on the ground
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// if the action is on an elytra armour slot
|
||||||
|
boolean throwItem = (slot == 45 && windowID == 0);
|
||||||
|
|
||||||
|
if (info.getOpenWindow() != null && windowID > 0) {
|
||||||
|
if (info.getOpenWindow().equals("minecraft:brewing_stand")) {
|
||||||
|
if (slot == 4) {
|
||||||
|
// throw
|
||||||
|
throwItem = true;
|
||||||
|
}
|
||||||
|
if (slot > 4)
|
||||||
|
slot = (short) (slot - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (throwItem) {
|
||||||
|
ByteBuf buf = info.getChannel().alloc().buffer();
|
||||||
|
PacketUtil.writeVarInt(PacketType.PLAY_SET_SLOT.getNewPacketID(), buf);
|
||||||
|
buf.writeByte(windowID);
|
||||||
|
buf.writeShort(slot);
|
||||||
|
buf.writeShort(-1); // empty
|
||||||
|
info.sendRawPacket(buf);
|
||||||
|
// Continue the packet simulating throw
|
||||||
|
mode = 0;
|
||||||
|
button = 0;
|
||||||
|
slot = -999;
|
||||||
}
|
}
|
||||||
output.writeByte(windowID);
|
output.writeByte(windowID);
|
||||||
output.writeShort(slot);
|
output.writeShort(slot);
|
||||||
|
@ -418,7 +418,7 @@ public class OutgoingTransformer {
|
|||||||
writeString(type, output);
|
writeString(type, output);
|
||||||
writeString(fixJson(windowTitle), output);
|
writeString(fixJson(windowTitle), output);
|
||||||
int slots = input.readUnsignedByte();
|
int slots = input.readUnsignedByte();
|
||||||
if(type.equals("minecraft:brewing_stand")){
|
if (type.equals("minecraft:brewing_stand")) {
|
||||||
slots = slots + 1; // new slot
|
slots = slots + 1; // new slot
|
||||||
}
|
}
|
||||||
output.writeByte(slots);
|
output.writeByte(slots);
|
||||||
@ -433,6 +433,12 @@ public class OutgoingTransformer {
|
|||||||
output.writeByte(windowId);
|
output.writeByte(windowId);
|
||||||
|
|
||||||
short slot = input.readShort();
|
short slot = input.readShort();
|
||||||
|
if (info.getOpenWindow() != null) {
|
||||||
|
if (info.getOpenWindow().equals("minecraft:brewing_stand")) {
|
||||||
|
if (slot >= 4)
|
||||||
|
slot = (short) (slot + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
output.writeShort(slot);
|
output.writeShort(slot);
|
||||||
ItemSlotRewriter.rewrite1_8To1_9(input, output);
|
ItemSlotRewriter.rewrite1_8To1_9(input, output);
|
||||||
return;
|
return;
|
||||||
@ -442,10 +448,22 @@ public class OutgoingTransformer {
|
|||||||
output.writeByte(windowId);
|
output.writeByte(windowId);
|
||||||
|
|
||||||
short count = input.readShort();
|
short count = input.readShort();
|
||||||
output.writeShort(count);
|
boolean brewing = false;
|
||||||
|
if (info.getOpenWindow() != null && windowId > 0) {
|
||||||
|
if (info.getOpenWindow().equals("minecraft:brewing_stand")) {
|
||||||
|
brewing = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output.writeShort(brewing ? (count + 1) : count);
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
|
|
||||||
ItemSlotRewriter.rewrite1_8To1_9(input, output);
|
ItemSlotRewriter.rewrite1_8To1_9(input, output);
|
||||||
|
|
||||||
|
// write "fuel" slot
|
||||||
|
if(brewing && i == 3){
|
||||||
|
output.writeShort(-1); // empty slot
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren