3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-26 16:12:43 +01:00
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-02-12 11:02:55 +01:00
Ursprung 9241213fb5
Commit b60464296b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
20 geänderte Dateien mit 59 neuen und 125 gelöschten Zeilen

Datei anzeigen

@ -1,34 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 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.api.exceptions;
import java.io.IOException;
public class RemovedValueException extends IOException {
/**
* May be cached since it is never actually printed, only checked.
*/
public static final RemovedValueException EX = new RemovedValueException() {
@Override
public Throwable fillInStackTrace() {
return this;
}
};
}

Datei anzeigen

@ -29,6 +29,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag;
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.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -118,7 +119,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
if (item.tag() != null) {
Tag originalId = item.tag().remove(nbtTagName + "|id");
if (originalId instanceof IntTag) {
item.setIdentifier(((IntTag) originalId).asInt());
item.setIdentifier(((NumberTag) originalId).asInt());
}
}
return item;

Datei anzeigen

@ -35,7 +35,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
protected final String nbtTagName;
protected final boolean jsonNameFormat;
public ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, boolean jsonNameFormat) {
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, boolean jsonNameFormat) {
super(protocol, itemType, itemArrayType);
this.jsonNameFormat = jsonNameFormat;
nbtTagName = "VB|" + protocol.getClass().getSimpleName();

Datei anzeigen

@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
@ -34,7 +33,7 @@ public class BannerHandler implements BackwardsBlockEntityHandler {
private static final int BANNER_STOP = 7109;
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
public CompoundTag transform(int blockId, CompoundTag tag) {
// Normal banners
if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
int color = (blockId - BANNER_START) >> 4;

Datei anzeigen

@ -19,13 +19,12 @@
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
public CompoundTag transform(int blockId, CompoundTag tag) {
int offset = blockId - 748;
int color = offset >> 4;

Datei anzeigen

@ -19,7 +19,6 @@
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
@ -70,7 +69,7 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB
// TODO THIS IS NEVER CALLED BECAUSE ITS NO LONGER A BLOCK ENTITY :(
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
public CompoundTag transform(int blockId, CompoundTag tag) {
Pair<String, Byte> item = getOrDefault(blockId);
tag.putString("Item", item.key());

Datei anzeigen

@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap;
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap;
@ -77,7 +76,7 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc
}
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
public CompoundTag transform(int blockId, CompoundTag tag) {
CompoundTag blockState = tag.getCompoundTag("blockState");
if (blockState == null) return tag;

Datei anzeigen

@ -19,14 +19,13 @@
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
public class SkullHandler implements BackwardsBlockEntityHandler {
private static final int SKULL_START = 5447;
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
public CompoundTag transform(int blockId, CompoundTag tag) {
int diff = blockId - SKULL_START;
int pos = diff % 20;
byte type = (byte) Math.floor(diff / 20f);

Datei anzeigen

@ -20,14 +20,13 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.EntityNameRewrites;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
public CompoundTag transform(int blockId, CompoundTag tag) {
CompoundTag dataTag = tag.getCompoundTag("SpawnData");
if (dataTag != null) {
StringTag idTag = dataTag.getStringTag("id");

Datei anzeigen

@ -711,7 +711,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
tag.putInt("HideFlags", value);
}
if (noMapped.size() != 0) {
if (!noMapped.isEmpty()) {
tag.put(extraNbtTag + "|" + key, noMapped);
if (!lore.isEmpty()) {

Datei anzeigen

@ -61,12 +61,10 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
public void register() {
handler(packetWrapper -> {
packetWrapper.cancel();
packetWrapper.create(0x02, new PacketHandler() { // Plugin response
@Override
public void handle(PacketWrapper newWrapper) throws Exception {
newWrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id
newWrapper.write(Type.BOOLEAN, false); // Success
}
// Plugin response
packetWrapper.create(0x02, wrapper -> {
wrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id
wrapper.write(Type.BOOLEAN, false); // Success
}).sendToServer(Protocol1_12_2To1_13.class);
});
}
@ -392,7 +390,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
if (type == 0) {
//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
//Maybe older versions used this and we need to implement this? The issue is that we would have to save the command block types
wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK);
wrapper.cancel();
ViaBackwards.getPlatform().getLogger().warning("Client send MC|AdvCmd custom payload to update command block, weird!");

Datei anzeigen

@ -80,7 +80,7 @@ public class BackwardsBlockEntityProvider implements Provider {
return tag;
}
return handler.transform(user, blockId, tag);
return handler.transform(blockId, tag);
}
/**
@ -102,6 +102,7 @@ public class BackwardsBlockEntityProvider implements Provider {
@FunctionalInterface
public interface BackwardsBlockEntityHandler {
CompoundTag transform(UserConnection user, int blockId, CompoundTag tag);
CompoundTag transform(int blockId, CompoundTag tag);
}
}

Datei anzeigen

@ -24,6 +24,7 @@ import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet;
import com.viaversion.viaversion.libs.fastutil.ints.IntSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.checkerframework.checker.nullness.qual.Nullable;
public class BackwardsBlockStorage implements StorableObject {
// This BlockStorage is very exclusive (;
@ -77,11 +78,7 @@ public class BackwardsBlockStorage implements StorableObject {
blocks.put(position, block);
}
public boolean isWelcome(int block) {
return WHITELIST.contains(block);
}
public Integer get(Position position) {
public @Nullable Integer get(Position position) {
return blocks.get(position);
}

Datei anzeigen

@ -20,7 +20,4 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage;
import com.viaversion.viabackwards.api.entities.storage.PlayerPositionStorage;
public class PlayerPositionStorage1_13 extends PlayerPositionStorage {
public PlayerPositionStorage1_13() {
}
}

Datei anzeigen

@ -103,9 +103,7 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr
public void register() {
map(Type.POSITION1_14);
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
handleBlockEntity(wrapper.passthrough(Type.NAMED_COMPOUND_TAG));
});
handler(wrapper -> handleBlockEntity(wrapper.passthrough(Type.NAMED_COMPOUND_TAG)));
}
});

Datei anzeigen

@ -37,6 +37,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_3;
import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider;
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
@ -59,6 +60,7 @@ import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Pair;
import java.util.BitSet;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol<ClientboundPackets1_19_3, ClientboundPackets1_19_1, ServerboundPackets1_19_3, ServerboundPackets1_19_1> {
@ -91,60 +93,19 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol<ClientboundP
final SoundRewriter<ClientboundPackets1_19_3> soundRewriter = new SoundRewriter<>(this);
soundRewriter.registerStopSound(ClientboundPackets1_19_3.STOP_SOUND);
registerClientbound(ClientboundPackets1_19_3.SOUND, wrapper -> {
final int soundId = wrapper.read(Type.VAR_INT) - 1; // Normalize the id
if (soundId != -1) {
final int mappedId = MAPPINGS.getSoundMappings().getNewId(soundId);
if (mappedId == -1) {
wrapper.cancel();
return;
}
wrapper.write(Type.VAR_INT, mappedId);
return;
}
String soundIdentifier = wrapper.read(Type.STRING);
wrapper.read(Type.OPTIONAL_FLOAT); // Fixed range
final String mappedIdentifier = MAPPINGS.getMappedNamedSound(soundIdentifier);
final String mappedIdentifier = rewriteSound(wrapper);
if (mappedIdentifier != null) {
if (mappedIdentifier.isEmpty()) {
wrapper.cancel();
return;
}
soundIdentifier = mappedIdentifier;
}
wrapper.write(Type.STRING, soundIdentifier);
wrapper.write(Type.STRING, mappedIdentifier);
wrapper.setPacketType(ClientboundPackets1_19_1.NAMED_SOUND);
}
});
registerClientbound(ClientboundPackets1_19_3.ENTITY_SOUND, wrapper -> {
final int soundId = wrapper.read(Type.VAR_INT) - 1; // Normalize the id
if (soundId != -1) {
final int mappedId = MAPPINGS.getSoundMappings().getNewId(soundId);
if (mappedId == -1) {
wrapper.cancel();
final String mappedIdentifier = rewriteSound(wrapper);
if (mappedIdentifier == null) {
return;
}
wrapper.write(Type.VAR_INT, mappedId);
return;
}
// Convert the resource location to the corresponding integer id
String soundIdentifier = wrapper.read(Type.STRING);
wrapper.read(Type.OPTIONAL_FLOAT); // Fixed range
final String mappedIdentifier = MAPPINGS.getMappedNamedSound(soundIdentifier);
if (mappedIdentifier != null) {
if (mappedIdentifier.isEmpty()) {
wrapper.cancel();
return;
}
soundIdentifier = mappedIdentifier;
}
final int mappedId = MAPPINGS.mappedSound(soundIdentifier);
final int mappedId = MAPPINGS.mappedSound(mappedIdentifier);
if (mappedId == -1) {
wrapper.cancel();
return;
@ -387,6 +348,35 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol<ClientboundP
cancelServerbound(ServerboundPackets1_19_1.CHAT_ACK);
}
private @Nullable String rewriteSound(final PacketWrapper wrapper) throws Exception {
final int soundId = wrapper.read(Type.VAR_INT) - 1; // Normalize the id
if (soundId != -1) {
final int mappedId = MAPPINGS.getSoundMappings().getNewId(soundId);
if (mappedId == -1) {
wrapper.cancel();
return null;
}
wrapper.write(Type.VAR_INT, mappedId);
return null;
}
// Convert the resource location to the corresponding integer id
final String soundIdentifier = wrapper.read(Type.STRING);
wrapper.read(Type.OPTIONAL_FLOAT); // Fixed range
final String mappedIdentifier = MAPPINGS.getMappedNamedSound(soundIdentifier);
if (mappedIdentifier == null) {
return soundIdentifier;
}
if (mappedIdentifier.isEmpty()) {
wrapper.cancel();
return null;
}
return mappedIdentifier;
}
@Override
public void init(final UserConnection user) {
user.put(new ChatSessionStorage());

Datei anzeigen

@ -27,11 +27,6 @@ public class Block {
this.data = (short) data;
}
public Block(int id) {
this.id = id;
this.data = 0;
}
public int getId() {
return id;
}

Datei anzeigen

@ -22,7 +22,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
public class ChatUtil {
public final class ChatUtil {
private static final Pattern UNUSED_COLOR_PATTERN = Pattern.compile("(?>(?>§[0-fk-or])*(§r|\\Z))|(?>(?>§[0-f])*(§[0-f]))");
private static final Pattern UNUSED_COLOR_PATTERN_PREFIX = Pattern.compile("(?>(?>§[0-fk-or])*(§r))|(?>(?>§[0-f])*(§[0-f]))");

Datei anzeigen

@ -21,7 +21,6 @@ package com.viaversion.viabackwards;
import com.google.inject.Inject;
import com.viaversion.viabackwards.api.ViaBackwardsPlatform;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.sponge.util.LoggerWrapper;
import java.io.File;
import java.nio.file.Path;
@ -39,7 +38,6 @@ public class SpongePlugin implements ViaBackwardsPlatform {
@ConfigDir(sharedRoot = false)
private Path configPath;
@SuppressWarnings("SpongeInjection")
@Inject
SpongePlugin(final org.apache.logging.log4j.Logger logger) {
this.logger = new LoggerWrapper(logger);

Datei anzeigen

@ -28,7 +28,6 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.viaversion.viabackwards.api.ViaBackwardsPlatform;
import com.viaversion.viabackwards.utils.VersionInfo;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.velocity.util.LoggerWrapper;
import java.io.File;
import java.nio.file.Path;