use of com.github.steveice10.opennbt.tag.builtin.ListTag in project ViaVersion by ViaVersion.
the class PlayerPackets method register.
public static void register(Protocol protocol) {
protocol.registerClientbound(ClientboundPackets1_13.OPEN_SIGN_EDITOR, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION, Type.POSITION1_14);
}
});
protocol.registerServerbound(ServerboundPackets1_14.QUERY_BLOCK_NBT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.POSITION1_14, Type.POSITION);
}
});
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
protocol.getItemRewriter().handleItemToServer(item);
if (item == null)
return;
CompoundTag tag = item.tag();
if (tag == null)
return;
Tag pages = tag.get("pages");
// Fix for https://github.com/ViaVersion/ViaVersion/issues/2660
if (pages == null) {
tag.put("pages", new ListTag(Collections.singletonList(new StringTag())));
}
// Client limit when editing a book was upped from 50 to 100 in 1.14, but some anti-exploit plugins ban with a size higher than the old client limit
if (Via.getConfig().isTruncate1_14Books() && pages instanceof ListTag) {
ListTag listTag = (ListTag) pages;
if (listTag.size() > 50) {
listTag.setValue(listTag.getValue().subList(0, 50));
}
}
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_14.PLAYER_DIGGING, new PacketRemapper() {
@Override
public void registerMap() {
// Action
map(Type.VAR_INT);
// Position
map(Type.POSITION1_14, Type.POSITION);
}
});
protocol.registerServerbound(ServerboundPackets1_14.RECIPE_BOOK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 0);
if (type == 0) {
wrapper.passthrough(Type.STRING);
} else if (type == 1) {
// Crafting Recipe Book Open
wrapper.passthrough(Type.BOOLEAN);
// Crafting Recipe Filter Active
wrapper.passthrough(Type.BOOLEAN);
// Smelting Recipe Book Open
wrapper.passthrough(Type.BOOLEAN);
// Smelting Recipe Filter Active
wrapper.passthrough(Type.BOOLEAN);
// Unknown new booleans
wrapper.read(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN);
}
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_14.UPDATE_COMMAND_BLOCK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
protocol.registerServerbound(ServerboundPackets1_14.UPDATE_STRUCTURE_BLOCK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
protocol.registerServerbound(ServerboundPackets1_14.UPDATE_SIGN, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14, Type.POSITION);
}
});
protocol.registerServerbound(ServerboundPackets1_14.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int hand = wrapper.read(Type.VAR_INT);
Position position = wrapper.read(Type.POSITION1_14);
int face = wrapper.read(Type.VAR_INT);
float x = wrapper.read(Type.FLOAT);
float y = wrapper.read(Type.FLOAT);
float z = wrapper.read(Type.FLOAT);
// new unknown boolean
wrapper.read(Type.BOOLEAN);
wrapper.write(Type.POSITION, position);
wrapper.write(Type.VAR_INT, face);
wrapper.write(Type.VAR_INT, hand);
wrapper.write(Type.FLOAT, x);
wrapper.write(Type.FLOAT, y);
wrapper.write(Type.FLOAT, z);
}
});
}
});
}
use of com.github.steveice10.opennbt.tag.builtin.ListTag in project ViaVersion by ViaVersion.
the class MappingData method loadExtras.
@Override
public void loadExtras(JsonObject oldMappings, JsonObject newMappings, JsonObject diffMappings) {
try {
dimensionRegistry = BinaryTagIO.readCompressedInputStream(MappingDataLoader.getResource("dimension-registry-1.16.2.nbt"));
} catch (IOException e) {
Via.getPlatform().getLogger().severe("Error loading dimension registry:");
e.printStackTrace();
}
// Data of each dimension
ListTag dimensions = ((CompoundTag) dimensionRegistry.get("minecraft:dimension_type")).get("value");
for (Tag dimension : dimensions) {
CompoundTag dimensionCompound = (CompoundTag) dimension;
// Copy with an empty name
CompoundTag dimensionData = new CompoundTag(((CompoundTag) dimensionCompound.get("element")).getValue());
dimensionDataMap.put(((StringTag) dimensionCompound.get("name")).getValue(), dimensionData);
}
}
use of com.github.steveice10.opennbt.tag.builtin.ListTag in project ViaVersion by ViaVersion.
the class InventoryPackets method newToOldAttributes.
public static void newToOldAttributes(Item item) {
if (item.tag() == null)
return;
ListTag attributes = item.tag().get("AttributeModifiers");
if (attributes == null)
return;
for (Tag tag : attributes) {
CompoundTag attribute = (CompoundTag) tag;
rewriteAttributeName(attribute, "AttributeName", true);
rewriteAttributeName(attribute, "Name", true);
IntArrayTag uuidTag = attribute.get("UUID");
if (uuidTag != null && uuidTag.getValue().length == 4) {
UUID uuid = UUIDIntArrayType.uuidFromIntArray(uuidTag.getValue());
attribute.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
attribute.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
}
}
}
use of com.github.steveice10.opennbt.tag.builtin.ListTag in project ViaVersion by ViaVersion.
the class InventoryPackets method oldToNewAttributes.
public static void oldToNewAttributes(Item item) {
if (item.tag() == null)
return;
ListTag attributes = item.tag().get("AttributeModifiers");
if (attributes == null)
return;
for (Tag tag : attributes) {
CompoundTag attribute = (CompoundTag) tag;
rewriteAttributeName(attribute, "AttributeName", false);
rewriteAttributeName(attribute, "Name", false);
Tag leastTag = attribute.get("UUIDLeast");
if (leastTag != null) {
Tag mostTag = attribute.get("UUIDMost");
int[] uuidIntArray = UUIDIntArrayType.bitsToIntArray(((NumberTag) leastTag).asLong(), ((NumberTag) mostTag).asLong());
attribute.put("UUID", new IntArrayTag(uuidIntArray));
}
}
}
use of com.github.steveice10.opennbt.tag.builtin.ListTag in project ViaVersion by ViaVersion.
the class Protocol1_17_1To1_17 method registerPackets.
@Override
protected void registerPackets() {
registerClientbound(ClientboundPackets1_17.REMOVE_ENTITY, ClientboundPackets1_17_1.REMOVE_ENTITIES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Aaaaand back to an array again!
int entityId = wrapper.read(Type.VAR_INT);
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { entityId });
});
}
});
registerClientbound(ClientboundPackets1_17.SET_SLOT, new PacketRemapper() {
@Override
public void registerMap() {
// Container id
map(Type.UNSIGNED_BYTE);
// Add arbitrary state id
create(Type.VAR_INT, 0);
}
});
registerClientbound(ClientboundPackets1_17.WINDOW_ITEMS, new PacketRemapper() {
@Override
public void registerMap() {
// Container id
map(Type.UNSIGNED_BYTE);
// Add arbitrary state id
create(Type.VAR_INT, 0);
handler(wrapper -> {
// Length encoded as var int now
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY));
// Carried item - should work like this
wrapper.write(Type.FLAT_VAR_INT_ITEM, null);
});
}
});
registerServerbound(ServerboundPackets1_17.CLICK_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
// Container id
map(Type.UNSIGNED_BYTE);
// Remove state id
read(Type.VAR_INT);
}
});
registerServerbound(ServerboundPackets1_17.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
CompoundTag tag = new CompoundTag();
// Magic value for writable books
Item item = new DataItem(942, (byte) 1, (short) 0, tag);
// Write the item, edit the tag down the line
wrapper.write(Type.FLAT_VAR_INT_ITEM, item);
int slot = wrapper.read(Type.VAR_INT);
// Save pages to tag
int pages = wrapper.read(Type.VAR_INT);
ListTag pagesTag = new ListTag(StringTag.class);
for (int i = 0; i < pages; i++) {
String page = wrapper.read(PAGE_STRING_TYPE);
pagesTag.add(new StringTag(page));
}
// Legacy servers don't like an empty pages list
if (pagesTag.size() == 0) {
pagesTag.add(new StringTag(""));
}
tag.put("pages", pagesTag);
if (wrapper.read(Type.BOOLEAN)) {
// Save the title to tag
String title = wrapper.read(TITLE_STRING_TYPE);
tag.put("title", new StringTag(title));
// Even if unused, legacy servers check for the author tag
tag.put("author", new StringTag(wrapper.user().getProtocolInfo().getUsername()));
// Write signing
wrapper.write(Type.BOOLEAN, true);
} else {
wrapper.write(Type.BOOLEAN, false);
}
// Write the slot
wrapper.write(Type.VAR_INT, slot);
});
}
});
}
Aggregations