Skip to content

Commit

Permalink
23w51b
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Dec 18, 2023
1 parent 4fe53f5 commit ba725df
Show file tree
Hide file tree
Showing 14 changed files with 438 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.Protocol1_19_4To1_20;
import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1;
import com.viaversion.viabackwards.protocol.protocol1_20_2to1_20_3.Protocol1_20_2To1_20_3;
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.Protocol1_20_3To1_20_5;
import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.Protocol1_20To1_20_2;
import com.viaversion.viabackwards.protocol.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4;
import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
Expand All @@ -67,7 +68,7 @@

public interface ViaBackwardsPlatform {

String MINIMUM_VV_VERSION = "4.9.3";
String MINIMUM_VV_VERSION = "4.10.0";

/**
* Initialize ViaBackwards.
Expand Down Expand Up @@ -136,6 +137,7 @@ default void init(final File configFile) {
protocolManager.registerProtocol(new Protocol1_19_4To1_20(), ProtocolVersion.v1_19_4, ProtocolVersion.v1_20);
protocolManager.registerProtocol(new Protocol1_20To1_20_2(), ProtocolVersion.v1_20, ProtocolVersion.v1_20_2);
protocolManager.registerProtocol(new Protocol1_20_2To1_20_3(), ProtocolVersion.v1_20_2, ProtocolVersion.v1_20_3);
protocolManager.registerProtocol(new Protocol1_20_3To1_20_5(), ProtocolVersion.v1_20_3, ProtocolVersion.v1_20_5);
}

/**
Expand All @@ -149,7 +151,7 @@ default boolean isOutdated() {
String vvVersion = Via.getPlatform().getPluginVersion();
if (vvVersion != null && new Version(vvVersion).compareTo(new Version(MINIMUM_VV_VERSION + "--")) < 0) {
getLogger().severe("================================");
getLogger().severe("YOUR VIAVERSION IS OUTDATED");
getLogger().severe("YOUR VIAVERSION IS OUTDATED (you are running " + vvVersion + ")");
getLogger().severe("PLEASE USE VIAVERSION " + MINIMUM_VV_VERSION + " OR NEWER");
getLogger().severe("LINK: https://ci.viaversion.com/");
getLogger().severe("VIABACKWARDS WILL NOW DISABLE");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,36 @@ public void registerMetaTypeHandler(
} else if (type == particleType) {
rewriteParticle(meta.value());
} else if (type == optionalComponentType || type == componentType) {

JsonElement text = meta.value();
if (text != null) {
protocol.getTranslatableRewriter().processText(text);
protocol.getTranslatableRewriter().processText(text);
}
});
}

public void registerMetaTypeHandler1_20_3(
@Nullable MetaType itemType,
@Nullable MetaType blockStateType,
@Nullable MetaType optionalBlockStateType,
@Nullable MetaType particleType,
@Nullable MetaType componentType,
@Nullable MetaType optionalComponentType
) {
filter().handler((event, meta) -> {
MetaType type = meta.metaType();
if (type == itemType) {
protocol.getItemRewriter().handleItemToClient(meta.value());
} else if (type == blockStateType) {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (type == optionalBlockStateType) {
int data = meta.value();
if (data != 0) {
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
} else if (type == particleType) {
rewriteParticle(meta.value());
} else if (type == optionalComponentType || type == componentType) {
protocol.getTranslatableRewriter().processTag(meta.value());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public BackwardsMappings() {
@Override
protected void loadExtras(final CompoundTag data) {
super.loadExtras(data);
for (Map.Entry<String, String> entry : Protocol1_16To1_15_2.MAPPINGS.getAttributeMappings().entrySet()) {
for (Map.Entry<String, String> entry : Protocol1_16To1_15_2.MAPPINGS.attributeIdentifierMappings().entrySet()) {
attributeMappings.put(entry.getValue(), entry.getKey());
}
}

public Map<String, String> getAttributeMappings() {
public Map<String, String> attributeIdentifierMappings() {
return attributeMappings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void register() {
int size = wrapper.passthrough(Type.INT);
for (int i = 0; i < size; i++) {
String attributeIdentifier = wrapper.read(Type.STRING);
String oldKey = protocol.getMappingData().getAttributeMappings().get(attributeIdentifier);
String oldKey = protocol.getMappingData().attributeIdentifierMappings().get(attributeIdentifier);
wrapper.write(Type.STRING, oldKey != null ? oldKey : Key.stripMinecraftNamespace(attributeIdentifier));

wrapper.passthrough(Type.DOUBLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 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_20_3to1_20_5;

import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.BackwardsMappings;
import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter.BlockItemPacketRewriter1_20_5;
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter.EntityPacketRewriter1_20_5;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3;
import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;

public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol<ClientboundPackets1_20_3, ClientboundPackets1_20_3, ServerboundPackets1_20_3, ServerboundPackets1_20_3> {

public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.20.5", "1.20.3", Protocol1_20_5To1_20_3.class);
private final EntityPacketRewriter1_20_5 entityRewriter = new EntityPacketRewriter1_20_5(this);
private final BlockItemPacketRewriter1_20_5 itemRewriter = new BlockItemPacketRewriter1_20_5(this);
private final TranslatableRewriter<ClientboundPackets1_20_3> translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT);

public Protocol1_20_3To1_20_5() {
super(ClientboundPackets1_20_3.class, ClientboundPackets1_20_3.class, ServerboundPackets1_20_3.class, ServerboundPackets1_20_3.class);
}

@Override
protected void registerPackets() {
super.registerPackets();

final TagRewriter<ClientboundPackets1_20_3> tagRewriter = new TagRewriter<>(this);
tagRewriter.registerGeneric(ClientboundPackets1_20_3.TAGS);
tagRewriter.registerGeneric(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.UPDATE_TAGS);

final SoundRewriter<ClientboundPackets1_20_3> soundRewriter = new SoundRewriter<>(this);
soundRewriter.register1_19_3Sound(ClientboundPackets1_20_3.SOUND);
soundRewriter.registerSound(ClientboundPackets1_20_3.ENTITY_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_20_3.STOP_SOUND);

new StatisticsRewriter<>(this).register(ClientboundPackets1_20_3.STATISTICS);

translatableRewriter.registerComponentPacket(ClientboundPackets1_20_3.ACTIONBAR);
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_3.TITLE_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_3.TITLE_SUBTITLE);
translatableRewriter.registerBossBar(ClientboundPackets1_20_3.BOSSBAR);
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_3.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_20_3.TAB_LIST);
translatableRewriter.registerCombatKill1_20(ClientboundPackets1_20_3.COMBAT_KILL);
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_3.SYSTEM_CHAT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_3.DISGUISED_CHAT);
translatableRewriter.registerPing();
}

@Override
public void init(final UserConnection user) {
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_20_5.PLAYER));
}

@Override
public BackwardsMappings getMappingData() {
return MAPPINGS;
}

@Override
public EntityPacketRewriter1_20_5 getEntityRewriter() {
return entityRewriter;
}

@Override
public BlockItemPacketRewriter1_20_5 getItemRewriter() {
return itemRewriter;
}

@Override
public TranslatableRewriter<ClientboundPackets1_20_3> getTranslatableRewriter() {
return translatableRewriter;
}

@Override
protected ClientboundPacketType clientboundFinishConfigurationPacket() {
return ClientboundConfigurationPackets1_20_3.FINISH_CONFIGURATION;
}

@Override
protected ServerboundPacketType serverboundFinishConfigurationPacket() {
return ServerboundConfigurationPackets1_20_2.FINISH_CONFIGURATION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 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_20_3to1_20_5.rewriter;

import com.viaversion.viabackwards.api.rewriters.ItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.Protocol1_20_3To1_20_5;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter.RecipeRewriter1_20_3;
import com.viaversion.viaversion.rewriter.BlockRewriter;

public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<ClientboundPackets1_20_3, ServerboundPackets1_20_3, Protocol1_20_3To1_20_5> {

public BlockItemPacketRewriter1_20_5(final Protocol1_20_3To1_20_5 protocol) {
super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY);
}

@Override
public void registerPackets() {
final BlockRewriter<ClientboundPackets1_20_3> blockRewriter = BlockRewriter.for1_20_2(protocol);
blockRewriter.registerBlockAction(ClientboundPackets1_20_3.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_20_3.BLOCK_CHANGE);
blockRewriter.registerVarLongMultiBlockChange1_20(ClientboundPackets1_20_3.MULTI_BLOCK_CHANGE);
blockRewriter.registerEffect(ClientboundPackets1_20_3.EFFECT, 1010, 2001);
blockRewriter.registerChunkData1_19(ClientboundPackets1_20_3.CHUNK_DATA, ChunkType1_20_2::new);
blockRewriter.registerBlockEntityData(ClientboundPackets1_20_3.BLOCK_ENTITY_DATA);

registerSetCooldown(ClientboundPackets1_20_3.COOLDOWN);
registerWindowItems1_17_1(ClientboundPackets1_20_3.WINDOW_ITEMS);
registerSetSlot1_17_1(ClientboundPackets1_20_3.SET_SLOT);
registerAdvancements1_20_3(ClientboundPackets1_20_3.ADVANCEMENTS);
registerEntityEquipmentArray(ClientboundPackets1_20_3.ENTITY_EQUIPMENT);
registerClickWindow1_17_1(ServerboundPackets1_20_3.CLICK_WINDOW);
registerTradeList1_19(ClientboundPackets1_20_3.TRADE_LIST);
registerCreativeInvAction(ServerboundPackets1_20_3.CREATIVE_INVENTORY_ACTION);
registerWindowPropertyEnchantmentHandler(ClientboundPackets1_20_3.WINDOW_PROPERTY);
registerSpawnParticle1_19(ClientboundPackets1_20_3.SPAWN_PARTICLE);

new RecipeRewriter1_20_3<>(protocol).register(ClientboundPackets1_20_3.DECLARE_RECIPES);
}
}
Loading

0 comments on commit ba725df

Please sign in to comment.