Prevent 1.12- clients to creative-pick server-side unknown block/item (#2180)

This commit is contained in:
_tomcraft 2020-11-13 14:27:29 +01:00 committed by GitHub
parent 692e53427b
commit a041610fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_9;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
@ -43,6 +44,9 @@ public class Protocol1_10To1_9_3_4 extends Protocol<ClientboundPackets1_9_3, Cli
@Override
protected void registerPackets() {
InventoryPackets.register(this);
// Named sound effect
registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() {
@Override

View File

@ -0,0 +1,25 @@
package us.myles.ViaVersion.protocols.protocol1_10to1_9_3.packets;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
public class InventoryPackets {
public static void register(Protocol1_10To1_9_3_4 protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, item -> {}, InventoryPackets::toServerItem);
itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
}
public static void toServerItem(Item item) {
if (item == null) return;
boolean newItem = item.getIdentifier() >= 213 && item.getIdentifier() <= 217;
if (newItem) { // Replace server-side unknown items
item.setIdentifier((short) 1);
item.setData((short) 0);
}
}
}

View File

@ -1,8 +1,19 @@
package us.myles.ViaVersion.protocols.protocol1_11_1to1_11;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.protocols.protocol1_11_1to1_11.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
public class Protocol1_11_1To1_11 extends Protocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> {
public Protocol1_11_1To1_11() {
super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class);
}
@Override
protected void registerPackets() {
InventoryPackets.register(this);
}
}

View File

@ -0,0 +1,25 @@
package us.myles.ViaVersion.protocols.protocol1_11_1to1_11.packets;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_11_1to1_11.Protocol1_11_1To1_11;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
public class InventoryPackets {
public static void register(Protocol1_11_1To1_11 protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, item -> {}, InventoryPackets::toServerItem);
itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
}
public static void toServerItem(Item item) {
if (item == null) return;
boolean newItem = item.getIdentifier() == 452;
if (newItem) { // Replace server-side unknown items
item.setIdentifier((short) 1);
item.setData((short) 0);
}
}
}

View File

@ -1,6 +1,8 @@
package us.myles.ViaVersion.protocols.protocol1_11to1_10.packets;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
@ -13,7 +15,7 @@ import us.myles.ViaVersion.protocols.protocol1_11to1_10.Protocol1_11To1_10;
public class InventoryPackets {
public static void register(Protocol1_11To1_10 protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, EntityIdRewriter::toClientItem, EntityIdRewriter::toServerItem);
ItemRewriter itemRewriter = new ItemRewriter(protocol, EntityIdRewriter::toClientItem, InventoryPackets::toServerItem);
itemRewriter.registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM);
itemRewriter.registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY);
@ -53,4 +55,16 @@ public class InventoryPackets {
itemRewriter.registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM);
itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM);
}
public static void toServerItem(Item item) {
EntityIdRewriter.toServerItem(item);
if (item == null) return;
boolean newItem = item.getIdentifier() >= 218 && item.getIdentifier() <= 234;
newItem |= item.getIdentifier() == 449 || item.getIdentifier() == 450;
if (newItem) { // Replace server-side unknown items
item.setIdentifier((short) 1);
item.setData((short) 0);
}
}
}

View File

@ -7,6 +7,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_11to1_10.EntityIdRewriter;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.BedRewriter;
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
@ -16,7 +17,7 @@ import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQui
public class InventoryPackets {
public static void register(Protocol1_12To1_11_1 protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, BedRewriter::toClientItem, BedRewriter::toServerItem);
ItemRewriter itemRewriter = new ItemRewriter(protocol, BedRewriter::toClientItem, InventoryPackets::toServerItem);
itemRewriter.registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM);
itemRewriter.registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM_ARRAY);
@ -98,4 +99,15 @@ public class InventoryPackets {
// Creative Inventory Action
itemRewriter.registerCreativeInvAction(ServerboundPackets1_12.CREATIVE_INVENTORY_ACTION, Type.ITEM);
}
public static void toServerItem(Item item) {
BedRewriter.toServerItem(item);
if (item == null) return;
boolean newItem = item.getIdentifier() >= 235 && item.getIdentifier() <= 252;
newItem |= item.getIdentifier() == 453;
if (newItem) { // Replace server-side unknown items
item.setIdentifier((short) 1);
item.setData((short) 0);
}
}
}

View File

@ -186,6 +186,14 @@ public class ItemRewriter {
item.setTag(tag);
item.setData((short) data);
}
boolean newItem = item.getIdentifier() >= 198 && item.getIdentifier() <= 212;
newItem |= item.getIdentifier() == 397 && item.getData() == 5;
newItem |= item.getIdentifier() >= 432 && item.getIdentifier() <= 448;
if (newItem) { // Replace server-side unknown items
item.setIdentifier((short) 1);
item.setData((short) 0);
}
}
}