mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-22 16:57:40 +01:00
Replace some deprecated api usage
This commit is contained in:
parent
f30fdc1feb
commit
15aa25f0d2
@ -25,6 +25,8 @@ import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColor
|
||||
import com.viaversion.viabackwards.utils.Block;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
@ -182,7 +184,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
ChunkSection section = chunk.getSections()[pos.getY() >> 4];
|
||||
if (section == null) continue;
|
||||
|
||||
int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ());
|
||||
int block = section.palette(PaletteType.BLOCKS).idAt(pos.getX(), pos.getY() & 0xF, pos.getZ());
|
||||
int btype = block >> 4;
|
||||
|
||||
MappedLegacyBlockItem settings = replacementData.get(btype);
|
||||
@ -193,19 +195,22 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue;
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean hasBlockEntityHandler = false;
|
||||
|
||||
// Map blocks
|
||||
for (int j = 0; j < section.getPaletteSize(); j++) {
|
||||
int block = section.getPaletteEntry(j);
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int block = palette.idByIndex(j);
|
||||
int btype = block >> 4;
|
||||
int meta = block & 0xF;
|
||||
|
||||
Block b = handleBlock(btype, meta);
|
||||
if (b != null) {
|
||||
section.setPaletteEntry(j, (b.getId() << 4) | (b.getData() & 0xF));
|
||||
palette.setIdByIndex(j, (b.getId() << 4) | (b.getData() & 0xF));
|
||||
}
|
||||
|
||||
// We already know that is has a handler
|
||||
@ -223,7 +228,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
int block = section.getFlatBlock(x, y, z);
|
||||
int block = palette.idAt(x, y, z);
|
||||
int btype = block >> 4;
|
||||
int meta = block & 15;
|
||||
|
||||
|
@ -200,7 +200,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
|
||||
if (b == 35) {
|
||||
wrapper.clearPacket();
|
||||
wrapper.setId(0x1E); // Change Game State
|
||||
wrapper.setPacketType(ClientboundPackets1_9_3.GAME_EVENT);
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) 10); // Play Elder Guardian animation
|
||||
wrapper.write(Type.FLOAT, 0F);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class PlayerPackets1_11 {
|
||||
JsonElement message = wrapper.read(Type.COMPONENT);
|
||||
|
||||
wrapper.clearPacket();
|
||||
wrapper.setId(ClientboundPackets1_9_3.CHAT_MESSAGE.ordinal());
|
||||
wrapper.setPacketType(ClientboundPackets1_9_3.CHAT_MESSAGE);
|
||||
|
||||
// https://bugs.mojang.com/browse/MC-119145to
|
||||
String legacy = LegacyComponentSerializer.legacySection().serialize(GsonComponentSerializer.gson().deserialize(message.toString()));
|
||||
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.libs.gson.JsonArray;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
||||
|
||||
public class ChatItemRewriter {
|
||||
|
||||
public static void toClient(JsonElement element, UserConnection user) {
|
||||
if (element instanceof JsonObject) {
|
||||
JsonObject obj = (JsonObject) element;
|
||||
if (obj.has("hoverEvent")) {
|
||||
if (obj.get("hoverEvent") instanceof JsonObject) {
|
||||
JsonObject hoverEvent = (JsonObject) obj.get("hoverEvent");
|
||||
if (hoverEvent.has("action") && hoverEvent.has("value")) {
|
||||
String type = hoverEvent.get("action").getAsString();
|
||||
if (type.equals("show_item") || type.equals("show_entity")) {
|
||||
JsonElement value = hoverEvent.get("value");
|
||||
|
||||
if (value.isJsonArray()) {
|
||||
JsonArray newArray = new JsonArray();
|
||||
|
||||
int index = 0;
|
||||
for (JsonElement valueElement : value.getAsJsonArray()) {
|
||||
if (valueElement.isJsonPrimitive() && valueElement.getAsJsonPrimitive().isString()) {
|
||||
String newValue = index + ":" + valueElement.getAsString();
|
||||
newArray.add(new JsonPrimitive(newValue));
|
||||
}
|
||||
}
|
||||
|
||||
hoverEvent.add("value", newArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (obj.has("extra")) {
|
||||
toClient(obj.get("extra"), user);
|
||||
}
|
||||
} else if (element instanceof JsonArray) {
|
||||
JsonArray array = (JsonArray) element;
|
||||
for (JsonElement value : array) {
|
||||
toClient(value, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_12;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12;
|
||||
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_12, Protocol1_11_1To1_12> {
|
||||
@ -154,7 +155,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper packetWrapper) throws Exception {
|
||||
PacketWrapper wrapper = PacketWrapper.create(0x07, null, packetWrapper.user());
|
||||
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9_3.STATISTICS, packetWrapper.user());
|
||||
|
||||
wrapper.write(Type.VAR_INT, 1);
|
||||
wrapper.write(Type.STRING, "achievement.openInventory");
|
||||
|
@ -75,8 +75,8 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB
|
||||
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
|
||||
Pair<String, Byte> item = getOrDefault(blockId);
|
||||
|
||||
tag.put("Item", new StringTag(item.getKey()));
|
||||
tag.put("Data", new IntTag(item.getValue()));
|
||||
tag.put("Item", new StringTag(item.key()));
|
||||
tag.put("Data", new IntTag(item.value()));
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
@ -45,6 +47,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
@ -189,8 +192,8 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
BackwardsBlockStorage blockStorage = wrapper.user().get(BackwardsBlockStorage.class);
|
||||
blockStorage.getBlocks().entrySet().removeIf(entry -> {
|
||||
Position position = entry.getKey();
|
||||
return position.getX() >= chunkMinX && position.getZ() >= chunkMinZ
|
||||
&& position.getX() <= chunkMaxX && position.getZ() <= chunkMaxZ;
|
||||
return position.x() >= chunkMinX && position.z() >= chunkMinZ
|
||||
&& position.x() <= chunkMaxX && position.z() <= chunkMaxZ;
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -313,7 +316,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
int z = ((NumberTag) tag.get("z")).asInt();
|
||||
Position position = new Position(x, (short) y, z);
|
||||
|
||||
int block = section.getFlatBlock(x & 0xF, y & 0xF, z & 0xF);
|
||||
int block = section.palette(PaletteType.BLOCKS).idAt(x & 0xF, y & 0xF, z & 0xF);
|
||||
storage.checkAndStore(position, block);
|
||||
|
||||
provider.transform(wrapper.user(), position, tag);
|
||||
@ -326,11 +329,12 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
// Flower pots require a special treatment, they are no longer block entities :(
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
int block = section.getFlatBlock(x, y, z);
|
||||
int block = palette.idAt(x, y, z);
|
||||
|
||||
// Check if the block is a flower
|
||||
if (FlowerPotHandler.isFlowah(block)) {
|
||||
@ -350,12 +354,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
}
|
||||
|
||||
for (int p = 0; p < section.getPaletteSize(); p++) {
|
||||
int old = section.getPaletteEntry(p);
|
||||
if (old != 0) {
|
||||
int oldId = protocol.getMappingData().getNewBlockStateId(old);
|
||||
section.setPaletteEntry(p, oldId);
|
||||
}
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j));
|
||||
palette.setIdByIndex(j, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1001,19 +1002,19 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
CompoundTag nbt = beProvider.transform(user, position, "minecraft:flower_pot");
|
||||
|
||||
// Remove the flowerpot
|
||||
PacketWrapper blockUpdateRemove = PacketWrapper.create(0x0B, null, user);
|
||||
PacketWrapper blockUpdateRemove = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_CHANGE, user);
|
||||
blockUpdateRemove.write(Type.POSITION, position);
|
||||
blockUpdateRemove.write(Type.VAR_INT, 0);
|
||||
blockUpdateRemove.scheduleSend(Protocol1_12_2To1_13.class);
|
||||
|
||||
// Create the flowerpot
|
||||
PacketWrapper blockCreate = PacketWrapper.create(0x0B, null, user);
|
||||
PacketWrapper blockCreate = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_CHANGE, user);
|
||||
blockCreate.write(Type.POSITION, position);
|
||||
blockCreate.write(Type.VAR_INT, Protocol1_12_2To1_13.MAPPINGS.getNewBlockStateId(blockState));
|
||||
blockCreate.scheduleSend(Protocol1_12_2To1_13.class);
|
||||
|
||||
// Send a block entity update
|
||||
PacketWrapper wrapper = PacketWrapper.create(0x09, null, user);
|
||||
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_ENTITY_DATA, user);
|
||||
wrapper.write(Type.POSITION, position);
|
||||
wrapper.write(Type.UNSIGNED_BYTE, (short) 5);
|
||||
wrapper.write(Type.NBT, nbt);
|
||||
|
@ -37,6 +37,7 @@ import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPacke
|
||||
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||
import com.viaversion.viaversion.rewriter.CommandRewriter;
|
||||
|
||||
@ -442,14 +443,14 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
|
||||
switch (channel) {
|
||||
case "MC|BSign":
|
||||
case "MC|BEdit":
|
||||
wrapper.setId(0x0B);
|
||||
wrapper.setPacketType(ServerboundPackets1_13.EDIT_BOOK);
|
||||
Item book = wrapper.read(Type.ITEM);
|
||||
wrapper.write(Type.FLAT_ITEM, protocol.getItemRewriter().handleItemToServer(book));
|
||||
boolean signing = channel.equals("MC|BSign");
|
||||
wrapper.write(Type.BOOLEAN, signing);
|
||||
break;
|
||||
case "MC|ItemName":
|
||||
wrapper.setId(0x1C);
|
||||
wrapper.setPacketType(ServerboundPackets1_13.RENAME_ITEM);
|
||||
break;
|
||||
case "MC|AdvCmd":
|
||||
byte type = wrapper.read(Type.BYTE);
|
||||
@ -457,11 +458,11 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
|
||||
//Information from https://wiki.vg/index.php?title=Plugin_channels&oldid=14089
|
||||
//The Notchain client only uses this for command block minecarts and uses MC|AutoCmd for blocks, but the Notchian server still accepts it for either.
|
||||
//Maybe older versions used this and we need to implement this? The issues is that we would have to save the command block types
|
||||
wrapper.setId(0x22);
|
||||
wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK);
|
||||
wrapper.cancel();
|
||||
ViaBackwards.getPlatform().getLogger().warning("Client send MC|AdvCmd custom payload to update command block, weird!");
|
||||
} else if (type == 1) {
|
||||
wrapper.setId(0x23);
|
||||
wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK_MINECART);
|
||||
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Entity Id
|
||||
wrapper.passthrough(Type.STRING); //Command
|
||||
wrapper.passthrough(Type.BOOLEAN); //Track Output
|
||||
@ -471,7 +472,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
|
||||
}
|
||||
break;
|
||||
case "MC|AutoCmd": {
|
||||
wrapper.setId(0x22);
|
||||
wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK);
|
||||
|
||||
int x = wrapper.read(Type.INT);
|
||||
int y = wrapper.read(Type.INT);
|
||||
@ -496,7 +497,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
|
||||
break;
|
||||
}
|
||||
case "MC|Struct": {
|
||||
wrapper.setId(0x25);
|
||||
wrapper.setPacketType(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK);
|
||||
int x = wrapper.read(Type.INT);
|
||||
int y = wrapper.read(Type.INT);
|
||||
int z = wrapper.read(Type.INT);
|
||||
@ -537,19 +538,19 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
|
||||
break;
|
||||
}
|
||||
case "MC|Beacon":
|
||||
wrapper.setId(0x20);
|
||||
wrapper.setPacketType(ServerboundPackets1_13.SET_BEACON_EFFECT);
|
||||
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Primary Effect
|
||||
|
||||
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Secondary Effect
|
||||
|
||||
break;
|
||||
case "MC|TrSel":
|
||||
wrapper.setId(0x1F);
|
||||
wrapper.setPacketType(ServerboundPackets1_13.SELECT_TRADE);
|
||||
wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Slot
|
||||
|
||||
break;
|
||||
case "MC|PickItem":
|
||||
wrapper.setId(0x15);
|
||||
wrapper.setPacketType(ServerboundPackets1_13.PICK_ITEM);
|
||||
break;
|
||||
default:
|
||||
String newChannel = InventoryPackets.getNewPluginChannelId(channel);
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BannerHandler;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BedHandler;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler;
|
||||
@ -26,7 +25,6 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_ha
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.SkullHandler;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.SpawnerHandler;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||
@ -34,7 +32,6 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -76,18 +73,12 @@ public class BackwardsBlockEntityProvider implements Provider {
|
||||
String id = (String) idTag.getValue();
|
||||
BackwardsBlockEntityHandler handler = handlers.get(id);
|
||||
if (handler == null) {
|
||||
if (Via.getManager().isDebug()) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
BackwardsBlockStorage storage = user.get(BackwardsBlockStorage.class);
|
||||
Integer blockId = storage.get(position);
|
||||
if (blockId == null) {
|
||||
if (Via.getManager().isDebug()) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Handled BlockEntity does not have a stored block :( " + id + " full tag: " + tag);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
@ -104,9 +95,9 @@ public class BackwardsBlockEntityProvider implements Provider {
|
||||
public CompoundTag transform(UserConnection user, Position position, String id) throws Exception {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("id", new StringTag(id));
|
||||
tag.put("x", new IntTag(Math.toIntExact(position.getX())));
|
||||
tag.put("y", new IntTag(Math.toIntExact(position.getY())));
|
||||
tag.put("z", new IntTag(Math.toIntExact(position.getZ())));
|
||||
tag.put("x", new IntTag(Math.toIntExact(position.x())));
|
||||
tag.put("y", new IntTag(Math.toIntExact(position.y())));
|
||||
tag.put("z", new IntTag(Math.toIntExact(position.z())));
|
||||
|
||||
return this.transform(user, position, tag);
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLight;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLightImpl;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
@ -276,7 +278,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
if (entityType == null) return;
|
||||
|
||||
if (entityType.isOrHasParent(Entity1_14Types.ABSTRACT_HORSE)) {
|
||||
wrapper.setId(0x3F);
|
||||
wrapper.setPacketType(ClientboundPackets1_13.ENTITY_METADATA);
|
||||
wrapper.resetReader();
|
||||
wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.read(Type.VAR_INT);
|
||||
@ -452,11 +454,12 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
if (Via.getConfig().isNonFullBlockLightFix() && section.getNonAirBlocksCount() != 0 && sectionLight.hasBlockLight()) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
int id = section.getFlatBlock(x, y, z);
|
||||
int id = palette.idAt(x, y, z);
|
||||
if (Protocol1_14To1_13_2.MAPPINGS.getNonFullBlocks().contains(id)) {
|
||||
sectionLight.getBlockLightNibbleArray().set(x, y, z, 0);
|
||||
}
|
||||
@ -465,10 +468,9 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < section.getPaletteSize(); j++) {
|
||||
int old = section.getPaletteEntry(j);
|
||||
int newId = protocol.getMappingData().getNewBlockStateId(old);
|
||||
section.setPaletteEntry(j, newId);
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j));
|
||||
palette.setIdByIndex(j, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
// Cache the position for every newly tracked entity
|
||||
if (type == Entity1_14Types.PAINTING) {
|
||||
final Position position = wrapper.get(Type.POSITION, 0);
|
||||
positionHandler.cacheEntityPosition(wrapper, position.getX(), position.getY(), position.getZ(), true, false);
|
||||
positionHandler.cacheEntityPosition(wrapper, position.x(), position.y(), position.z(), true, false);
|
||||
} else if (wrapper.getId() != ClientboundPackets1_14.JOIN_GAME.getId()) { // ignore join game
|
||||
positionHandler.cacheEntityPosition(wrapper, true, false);
|
||||
}
|
||||
@ -497,7 +497,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
}
|
||||
|
||||
public int villagerDataToProfession(VillagerData data) {
|
||||
switch (data.getProfession()) {
|
||||
switch (data.profession()) {
|
||||
case 1: // Armorer
|
||||
case 10: // Mason
|
||||
case 13: // Toolsmith
|
||||
|
@ -22,6 +22,8 @@ import com.viaversion.viaversion.api.minecraft.BlockFace;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
@ -40,18 +42,19 @@ public class WorldPackets1_13_1 {
|
||||
protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld));
|
||||
handler(wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld));
|
||||
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section != null) {
|
||||
for (int i = 0; i < section.getPaletteSize(); i++) {
|
||||
section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(section.getPaletteEntry(i)));
|
||||
}
|
||||
}
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i));
|
||||
palette.setIdByIndex(i, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -20,6 +20,8 @@ package com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.packets;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
@ -99,11 +101,14 @@ public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue;
|
||||
for (int j = 0; j < section.getPaletteSize(); j++) {
|
||||
int old = section.getPaletteEntry(j);
|
||||
int newId = protocol.getMappingData().getNewBlockStateId(old);
|
||||
section.setPaletteEntry(j, newId);
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j));
|
||||
palette.setIdByIndex(j, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.storage.Biome
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -157,10 +159,14 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue;
|
||||
for (int j = 0; j < section.getPaletteSize(); j++) {
|
||||
int old = section.getPaletteEntry(j);
|
||||
section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j));
|
||||
palette.setIdByIndex(j, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ public class EntityPackets1_16 extends EntityRewriter<ClientboundPackets1_16, Pr
|
||||
int dimension = wrapper.get(Type.INT, 0);
|
||||
|
||||
// Send a dummy respawn with a different dimension if the world name was different and the same dimension was used
|
||||
if (clientWorld.getEnvironment() != null && dimension == clientWorld.getEnvironment().getId()
|
||||
if (clientWorld.getEnvironment() != null && dimension == clientWorld.getEnvironment().id()
|
||||
&& (wrapper.user().isClientSide() || Via.getPlatform().isProxy()
|
||||
|| wrapper.user().getProtocolInfo().getProtocolVersion() <= ProtocolVersion.v1_12_2.getVersion() // Hotfix for https://github.com/ViaVersion/ViaBackwards/issues/381
|
||||
|| !nextWorldName.equals(worldNameTracker.getWorldName()))) {
|
||||
|
@ -85,7 +85,7 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
|
||||
byte position = wrapper.passthrough(Type.BYTE);
|
||||
if (position == 2) { // https://bugs.mojang.com/browse/MC-119145
|
||||
wrapper.clearPacket();
|
||||
wrapper.setId(ClientboundPackets1_16.TITLE.ordinal());
|
||||
wrapper.setPacketType(ClientboundPackets1_16.TITLE);
|
||||
wrapper.write(Type.VAR_INT, 2);
|
||||
wrapper.write(Type.COMPONENT, message);
|
||||
}
|
||||
@ -104,7 +104,7 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
|
||||
if (type == 0) {
|
||||
// Shown, change to its own packet
|
||||
wrapper.passthrough(Type.STRING); // Recipe
|
||||
wrapper.setId(ServerboundPackets1_16_2.SEEN_RECIPE.ordinal());
|
||||
wrapper.setPacketType(ServerboundPackets1_16_2.SEEN_RECIPE);
|
||||
} else {
|
||||
wrapper.cancel();
|
||||
|
||||
|
@ -22,6 +22,8 @@ import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
@ -87,10 +89,14 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr
|
||||
chunk.setIgnoreOldLightData(true);
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue;
|
||||
for (int j = 0; j < section.getPaletteSize(); j++) {
|
||||
int old = section.getPaletteEntry(j);
|
||||
section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j));
|
||||
palette.setIdByIndex(j, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ public final class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPac
|
||||
|
||||
// Put them into the hardcoded order of Vanilla tags (and only those), rewrite ids
|
||||
for (RegistryType type : RegistryType.getValues()) {
|
||||
List<TagData> tagList = tags.get(type.getResourceLocation());
|
||||
List<TagData> tagList = tags.get(type.resourceLocation());
|
||||
IdRewriteFunction rewriter = tagRewriter.getRewriter(type);
|
||||
|
||||
wrapper.write(Type.VAR_INT, tagList.size());
|
||||
|
@ -28,6 +28,8 @@ import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -321,7 +323,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter<ClientboundPackets1
|
||||
map(Type.POSITION1_14);
|
||||
map(Type.VAR_INT);
|
||||
handler((wrapper) -> {
|
||||
int y = wrapper.get(Type.POSITION1_14, 0).getY();
|
||||
int y = wrapper.get(Type.POSITION1_14, 0).y();
|
||||
if (y < 0 || y > 255) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
@ -364,10 +366,14 @@ public final class BlockItemPackets1_17 extends ItemRewriter<ClientboundPackets1
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection section = sections[i];
|
||||
if (section == null) continue;
|
||||
for (int j = 0; j < section.getPaletteSize(); j++) {
|
||||
int old = section.getPaletteEntry(j);
|
||||
section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j));
|
||||
palette.setIdByIndex(j, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,7 +389,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter<ClientboundPackets1
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> {
|
||||
int y = wrapper.passthrough(Type.POSITION1_14).getY();
|
||||
int y = wrapper.passthrough(Type.POSITION1_14).y();
|
||||
if (y < 0 || y > 255) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
@ -396,7 +402,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter<ClientboundPackets1
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT);
|
||||
handler(wrapper -> {
|
||||
int y = wrapper.passthrough(Type.POSITION1_14).getY();
|
||||
int y = wrapper.passthrough(Type.POSITION1_14).y();
|
||||
if (y < 0 || y > 255) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user