3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Refactor protocols to match template module (#3842)

Dieser Commit ist enthalten in:
EnZaXD 2024-05-11 23:06:29 +02:00 committet von Nassim Jahnke
Ursprung d47b5be7f3
Commit bd4df2813d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
49 geänderte Dateien mit 914 neuen und 1114 gelöschten Zeilen

Datei anzeigen

@ -28,14 +28,13 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.v1_10to1_11.data.PotionColorMapping;
import com.viaversion.viaversion.protocols.v1_10to1_11.metadata.MetadataRewriter1_11;
import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.BlockEntityRewriter;
import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.EntityIdRewriter;
import com.viaversion.viaversion.protocols.v1_10to1_11.data.PotionColors1_11;
import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.EntityPacketRewriter1_11;
import com.viaversion.viaversion.protocols.v1_10to1_11.data.BlockEntityNames1_11;
import com.viaversion.viaversion.protocols.v1_10to1_11.data.EntityNames1_11;
import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.ItemPacketRewriter1_11;
import com.viaversion.viaversion.protocols.v1_10to1_11.storage.EntityTracker1_11;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
@ -51,7 +50,7 @@ public class Protocol1_10To1_11 extends AbstractProtocol<ClientboundPackets1_9_3
}
};
private final MetadataRewriter1_11 entityRewriter = new MetadataRewriter1_11(this);
private final EntityPacketRewriter1_11 entityRewriter = new EntityPacketRewriter1_11(this);
private final ItemPacketRewriter1_11 itemRewriter = new ItemPacketRewriter1_11(this);
public Protocol1_10To1_11() {
@ -62,95 +61,8 @@ public class Protocol1_10To1_11 extends AbstractProtocol<ClientboundPackets1_9_3
protected void registerPackets() {
super.registerPackets();
registerClientbound(ClientboundPackets1_9_3.ADD_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity id
map(Types.UUID); // 1 - UUID
map(Types.BYTE); // 2 - Type
// Track Entity
handler(entityRewriter.objectTrackerHandler());
}
});
registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity ID
map(Types.UUID); // 1 - Entity UUID
map(Types.UNSIGNED_BYTE, Types.VAR_INT); // 2 - Entity Type
map(Types.DOUBLE); // 3 - X
map(Types.DOUBLE); // 4 - Y
map(Types.DOUBLE); // 5 - Z
map(Types.BYTE); // 6 - Yaw
map(Types.BYTE); // 7 - Pitch
map(Types.BYTE); // 8 - Head Pitch
map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z
map(Types1_9.METADATA_LIST); // 12 - Metadata
handler(wrapper -> {
int entityId = wrapper.get(Types.VAR_INT, 0);
// Change Type :)
int type = wrapper.get(Types.VAR_INT, 1);
EntityTypes1_11.EntityType entType = MetadataRewriter1_11.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0));
if (entType != null) {
wrapper.set(Types.VAR_INT, 1, entType.getId());
// Register Type ID
wrapper.user().getEntityTracker(Protocol1_10To1_11.class).addEntity(entityId, entType);
entityRewriter.handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
}
});
}
});
new SoundRewriter<>(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND);
registerClientbound(ClientboundPackets1_9_3.TAKE_ITEM_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Collected entity id
map(Types.VAR_INT); // 1 - Collector entity id
handler(wrapper -> {
wrapper.write(Types.VAR_INT, 1); // 2 - Pickup Count
});
}
});
entityRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.SET_ENTITY_DATA, Types1_9.METADATA_LIST);
registerClientbound(ClientboundPackets1_9_3.TELEPORT_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity id
map(Types.DOUBLE); // 1 - x
map(Types.DOUBLE); // 2 - y
map(Types.DOUBLE); // 3 - z
map(Types.BYTE); // 4 - yaw
map(Types.BYTE); // 5 - pitch
map(Types.BOOLEAN); // 6 - onGround
handler(wrapper -> {
int entityID = wrapper.get(Types.VAR_INT, 0);
if (Via.getConfig().isHologramPatch()) {
EntityTracker1_11 tracker = wrapper.user().getEntityTracker(Protocol1_10To1_11.class);
if (tracker.isHologram(entityID)) {
Double newValue = wrapper.get(Types.DOUBLE, 1);
newValue -= (Via.getConfig().getHologramYOffset());
wrapper.set(Types.DOUBLE, 1, newValue);
}
}
});
}
});
entityRewriter.registerRemoveEntities(ClientboundPackets1_9_3.REMOVE_ENTITIES);
registerClientbound(ClientboundPackets1_9_3.SET_TITLES, new PacketHandlers() {
@Override
public void register() {
@ -187,28 +99,6 @@ public class Protocol1_10To1_11 extends AbstractProtocol<ClientboundPackets1_9_3
}
});
registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketHandlers() {
@Override
public void register() {
map(Types.BLOCK_POSITION1_8); // 0 - Position
map(Types.UNSIGNED_BYTE); // 1 - Action
map(Types.NAMED_COMPOUND_TAG); // 2 - NBT data
handler(wrapper -> {
CompoundTag tag = wrapper.get(Types.NAMED_COMPOUND_TAG, 0);
if (wrapper.get(Types.UNSIGNED_BYTE, 0) == 1) {
EntityIdRewriter.toClientSpawner(tag);
}
StringTag idTag = tag.getStringTag("id");
if (idTag != null) {
// Handle new identifier
idTag.setValue(BlockEntityRewriter.toNewIdentifier(idTag.getValue()));
}
});
}
});
registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
@ -223,11 +113,11 @@ public class Protocol1_10To1_11 extends AbstractProtocol<ClientboundPackets1_9_3
String identifier = idTag.getValue();
if (identifier.equals("MobSpawner")) {
EntityIdRewriter.toClientSpawner(tag);
EntityNames1_11.toClientSpawner(tag);
}
// Handle new identifier
idTag.setValue(BlockEntityRewriter.toNewIdentifier(identifier));
idTag.setValue(BlockEntityNames1_11.toNewIdentifier(identifier));
}
});
@ -268,7 +158,7 @@ public class Protocol1_10To1_11 extends AbstractProtocol<ClientboundPackets1_9_3
if (effectID == 2002) {
int data = packetWrapper.get(Types.INT, 1);
boolean isInstant = false;
Pair<Integer, Boolean> newData = PotionColorMapping.getNewData(data);
Pair<Integer, Boolean> newData = PotionColors1_11.getNewData(data);
if (newData == null) {
Via.getPlatform().getLogger().warning("Received unknown 1.11 -> 1.10.2 potion data (" + data + ")");
data = 0;
@ -357,7 +247,7 @@ public class Protocol1_10To1_11 extends AbstractProtocol<ClientboundPackets1_9_3
}
@Override
public MetadataRewriter1_11 getEntityRewriter() {
public EntityPacketRewriter1_11 getEntityRewriter() {
return entityRewriter;
}

Datei anzeigen

@ -15,13 +15,13 @@
* 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.viaversion.protocols.v1_10to1_11.rewriter;
package com.viaversion.viaversion.protocols.v1_10to1_11.data;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.viaversion.viaversion.util.Key;
public class BlockEntityRewriter {
public class BlockEntityNames1_11 {
private static final BiMap<String, String> OLD_TO_NEW_NAMES = HashBiMap.create();
// Source: https://www.minecraftforum.net/forums/minecraft-java-edition/redstone-discussion-and/commands-command-blocks-and/2724507-1-11-nbt-changes-and-additions#AllTiles

Datei anzeigen

@ -15,7 +15,7 @@
* 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.viaversion.protocols.v1_10to1_11.rewriter;
package com.viaversion.viaversion.protocols.v1_10to1_11.data;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.StringTag;
@ -24,7 +24,7 @@ import com.google.common.collect.HashBiMap;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.util.Key;
public class EntityIdRewriter {
public class EntityNames1_11 {
private static final BiMap<String, String> oldToNewNames = HashBiMap.create();
static {

Datei anzeigen

@ -21,7 +21,7 @@ import com.viaversion.viaversion.util.Pair;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class PotionColorMapping {
public class PotionColors1_11 {
//<oldData> to <newData, isInstant> mapping
private static final Int2ObjectMap<Pair<Integer, Boolean>> POTIONS = new Int2ObjectOpenHashMap<>(37, 0.99F);

Datei anzeigen

@ -15,8 +15,10 @@
* 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.viaversion.protocols.v1_10to1_11.metadata;
package com.viaversion.viaversion.protocols.v1_10to1_11.rewriter;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11.EntityType;
@ -24,9 +26,12 @@ import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.v1_10to1_11.Protocol1_10To1_11;
import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.EntityIdRewriter;
import com.viaversion.viaversion.protocols.v1_10to1_11.data.BlockEntityNames1_11;
import com.viaversion.viaversion.protocols.v1_10to1_11.data.EntityNames1_11;
import com.viaversion.viaversion.protocols.v1_10to1_11.storage.EntityTracker1_11;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.rewriter.EntityRewriter;
@ -34,18 +39,130 @@ import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
public class MetadataRewriter1_11 extends EntityRewriter<ClientboundPackets1_9_3, Protocol1_10To1_11> {
public class EntityPacketRewriter1_11 extends EntityRewriter<ClientboundPackets1_9_3, Protocol1_10To1_11> {
public MetadataRewriter1_11(Protocol1_10To1_11 protocol) {
public EntityPacketRewriter1_11(Protocol1_10To1_11 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_9_3.ADD_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity id
map(Types.UUID); // 1 - UUID
map(Types.BYTE); // 2 - Type
// Track Entity
handler(objectTrackerHandler());
}
});
protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity ID
map(Types.UUID); // 1 - Entity UUID
map(Types.UNSIGNED_BYTE, Types.VAR_INT); // 2 - Entity Type
map(Types.DOUBLE); // 3 - X
map(Types.DOUBLE); // 4 - Y
map(Types.DOUBLE); // 5 - Z
map(Types.BYTE); // 6 - Yaw
map(Types.BYTE); // 7 - Pitch
map(Types.BYTE); // 8 - Head Pitch
map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z
map(Types1_9.METADATA_LIST); // 12 - Metadata
handler(wrapper -> {
int entityId = wrapper.get(Types.VAR_INT, 0);
// Change Type :)
int type = wrapper.get(Types.VAR_INT, 1);
EntityTypes1_11.EntityType entType = EntityPacketRewriter1_11.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0));
if (entType != null) {
wrapper.set(Types.VAR_INT, 1, entType.getId());
// Register Type ID
wrapper.user().getEntityTracker(Protocol1_10To1_11.class).addEntity(entityId, entType);
handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_9_3.TAKE_ITEM_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Collected entity id
map(Types.VAR_INT); // 1 - Collector entity id
handler(wrapper -> {
wrapper.write(Types.VAR_INT, 1); // 2 - Pickup Count
});
}
});
registerMetadataRewriter(ClientboundPackets1_9_3.SET_ENTITY_DATA, Types1_9.METADATA_LIST);
protocol.registerClientbound(ClientboundPackets1_9_3.TELEPORT_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity id
map(Types.DOUBLE); // 1 - x
map(Types.DOUBLE); // 2 - y
map(Types.DOUBLE); // 3 - z
map(Types.BYTE); // 4 - yaw
map(Types.BYTE); // 5 - pitch
map(Types.BOOLEAN); // 6 - onGround
handler(wrapper -> {
int entityID = wrapper.get(Types.VAR_INT, 0);
if (Via.getConfig().isHologramPatch()) {
EntityTracker1_11 tracker = wrapper.user().getEntityTracker(Protocol1_10To1_11.class);
if (tracker.isHologram(entityID)) {
Double newValue = wrapper.get(Types.DOUBLE, 1);
newValue -= (Via.getConfig().getHologramYOffset());
wrapper.set(Types.DOUBLE, 1, newValue);
}
}
});
}
});
registerRemoveEntities(ClientboundPackets1_9_3.REMOVE_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketHandlers() {
@Override
public void register() {
map(Types.BLOCK_POSITION1_8); // 0 - Position
map(Types.UNSIGNED_BYTE); // 1 - Action
map(Types.NAMED_COMPOUND_TAG); // 2 - NBT data
handler(wrapper -> {
CompoundTag tag = wrapper.get(Types.NAMED_COMPOUND_TAG, 0);
if (wrapper.get(Types.UNSIGNED_BYTE, 0) == 1) {
EntityNames1_11.toClientSpawner(tag);
}
StringTag idTag = tag.getStringTag("id");
if (idTag != null) {
// Handle new identifier
idTag.setValue(BlockEntityNames1_11.toNewIdentifier(idTag.getValue()));
}
});
}
});
}
@Override
protected void registerRewrites() {
filter().handler((event, meta) -> {
if (meta.getValue() instanceof DataItem) {
// Apply rewrite
EntityIdRewriter.toClientItem(meta.value());
EntityNames1_11.toClientItem(meta.value());
}
});

Datei anzeigen

@ -20,10 +20,9 @@ package com.viaversion.viaversion.protocols.v1_10to1_11.rewriter;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_10to1_11.Protocol1_10To1_11;
import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.EntityIdRewriter;
import com.viaversion.viaversion.protocols.v1_10to1_11.data.EntityNames1_11;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
import com.viaversion.viaversion.rewriter.ItemRewriter;
@ -52,12 +51,13 @@ public class ItemPacketRewriter1_11 extends ItemRewriter<ClientboundPackets1_9_3
int size = wrapper.passthrough(Types.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
EntityIdRewriter.toClientItem(wrapper.passthrough(Types.ITEM1_8)); // Input Item
EntityIdRewriter.toClientItem(wrapper.passthrough(Types.ITEM1_8)); // Output Item
handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_8)); // Input Item
handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_8)); // Output Item
boolean secondItem = wrapper.passthrough(Types.BOOLEAN); // Has second item
if (secondItem)
EntityIdRewriter.toClientItem(wrapper.passthrough(Types.ITEM1_8)); // Second Item
if (secondItem) {
handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_8)); // Second Item
}
wrapper.passthrough(Types.BOOLEAN); // Trade disabled
wrapper.passthrough(Types.INT); // Number of tools uses
@ -74,13 +74,13 @@ public class ItemPacketRewriter1_11 extends ItemRewriter<ClientboundPackets1_9_3
@Override
public Item handleItemToClient(UserConnection connection, Item item) {
EntityIdRewriter.toClientItem(item);
EntityNames1_11.toClientItem(item);
return item;
}
@Override
public Item handleItemToServer(UserConnection connection, Item item) {
EntityIdRewriter.toServerItem(item);
EntityNames1_11.toServerItem(item);
if (item == null) return null;
boolean newItem = item.identifier() >= 218 && item.identifier() <= 234;
newItem |= item.identifier() == 449 || item.identifier() == 450;

Datei anzeigen

@ -33,18 +33,16 @@ import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.api.type.types.version.Types1_12;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.metadata.MetadataRewriter1_12To1_11_1;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter.EntityPacketRewriter1_12;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ServerboundPackets1_12;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.provider.InventoryQuickMoveProvider;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter.ChatItemRewriter;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.data.ChatItemRewriter;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter.ItemPacketRewriter1_12;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter.TranslateRewriter;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.data.TranslateRewriter;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
@ -53,7 +51,7 @@ import com.viaversion.viaversion.rewriter.SoundRewriter;
public class Protocol1_11_1To1_12 extends AbstractProtocol<ClientboundPackets1_9_3, ClientboundPackets1_12, ServerboundPackets1_9_3, ServerboundPackets1_12> {
private final MetadataRewriter1_12To1_11_1 metadataRewriter = new MetadataRewriter1_12To1_11_1(this);
private final EntityPacketRewriter1_12 entityRewriter = new EntityPacketRewriter1_12(this);
private final ItemPacketRewriter1_12 itemRewriter = new ItemPacketRewriter1_12(this);
public Protocol1_11_1To1_12() {
@ -64,40 +62,6 @@ public class Protocol1_11_1To1_12 extends AbstractProtocol<ClientboundPackets1_9
protected void registerPackets() {
super.registerPackets();
registerClientbound(ClientboundPackets1_9_3.ADD_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity id
map(Types.UUID); // 1 - UUID
map(Types.BYTE); // 2 - Type
// Track Entity
handler(metadataRewriter.objectTrackerHandler());
}
});
registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity ID
map(Types.UUID); // 1 - Entity UUID
map(Types.VAR_INT); // 2 - Entity Type
map(Types.DOUBLE); // 3 - X
map(Types.DOUBLE); // 4 - Y
map(Types.DOUBLE); // 5 - Z
map(Types.BYTE); // 6 - Yaw
map(Types.BYTE); // 7 - Pitch
map(Types.BYTE); // 8 - Head Pitch
map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z
map(Types1_12.METADATA_LIST); // 12 - Metadata
// Track mob and rewrite metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_12.METADATA_LIST));
}
});
registerClientbound(ClientboundPackets1_9_3.CHAT, wrapper -> {
if (!Via.getConfig().is1_12NBTArrayFix()) return;
final JsonElement element = wrapper.passthrough(Types.COMPONENT);
@ -137,9 +101,6 @@ public class Protocol1_11_1To1_12 extends AbstractProtocol<ClientboundPackets1_9
}
});
metadataRewriter.registerRemoveEntities(ClientboundPackets1_9_3.REMOVE_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.SET_ENTITY_DATA, Types1_12.METADATA_LIST);
registerClientbound(ClientboundPackets1_9_3.LOGIN, new PacketHandlers() {
@Override
public void register() {
@ -250,8 +211,8 @@ public class Protocol1_11_1To1_12 extends AbstractProtocol<ClientboundPackets1_9
}
@Override
public MetadataRewriter1_12To1_11_1 getEntityRewriter() {
return metadataRewriter;
public EntityPacketRewriter1_12 getEntityRewriter() {
return entityRewriter;
}
@Override

Datei anzeigen

@ -21,7 +21,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import java.util.HashSet;
import java.util.Set;
public class AchievementTranslationMapping {
public class AchievementTranslations1_12 {
private static final Object2ObjectOpenHashMap<String, String> ACHIEVEMENTS = new Object2ObjectOpenHashMap<>(150, 0.99f);
private static final Set<String> SPECIAL_ACHIEVEMENTS = new HashSet<>(10);

Datei anzeigen

@ -15,7 +15,7 @@
* 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.viaversion.protocols.v1_11_1to1_12.rewriter;
package com.viaversion.viaversion.protocols.v1_11_1to1_12.data;
import com.viaversion.nbt.tag.CompoundTag;
import com.google.gson.JsonArray;

Datei anzeigen

@ -15,14 +15,13 @@
* 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.viaversion.protocols.v1_11_1to1_12.rewriter;
package com.viaversion.viaversion.protocols.v1_11_1to1_12.data;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.data.AchievementTranslationMapping;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.util.SerializerVersion;
@ -33,7 +32,7 @@ public class TranslateRewriter {
private static final ComponentRewriter<ClientboundPackets1_9_3> ACHIEVEMENT_TEXT_REWRITER = new ComponentRewriter<>(null, ComponentRewriter.ReadType.JSON) {
@Override
protected void handleTranslate(JsonObject object, String translate) {
String text = AchievementTranslationMapping.get(translate);
String text = AchievementTranslations1_12.get(translate);
if (text != null) {
object.addProperty("translate", text);
}
@ -49,7 +48,7 @@ public class TranslateRewriter {
String textValue = SerializerVersion.V1_9.toComponent(hoverEvent.get("value")).asUnformattedString();
if (AchievementTranslationMapping.get(textValue) == null) {
if (AchievementTranslations1_12.get(textValue) == null) {
JsonObject invalidText = new JsonObject();
invalidText.addProperty("text", "Invalid statistic/achievement!");
invalidText.addProperty("color", "red");
@ -71,7 +70,7 @@ public class TranslateRewriter {
baseArray.add(typePart);
if (textValue.startsWith("achievement")) {
namePart.addProperty("translate", textValue);
namePart.addProperty("color", AchievementTranslationMapping.isSpecial(textValue) ? "dark_purple" : "green");
namePart.addProperty("color", AchievementTranslations1_12.isSpecial(textValue) ? "dark_purple" : "green");
typePart.addProperty("translate", "stats.tooltip.type.achievement");
JsonObject description = new JsonObject();
typePart.addProperty("italic", true);

Datei anzeigen

@ -1,53 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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.viaversion.protocols.v1_11_1to1_12.metadata;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.Protocol1_11_1To1_12;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class MetadataRewriter1_12To1_11_1 extends EntityRewriter<ClientboundPackets1_9_3, Protocol1_11_1To1_12> {
public MetadataRewriter1_12To1_11_1(Protocol1_11_1To1_12 protocol) {
super(protocol);
}
@Override
protected void registerRewrites() {
filter().handler((event, meta) -> {
if (meta.getValue() instanceof Item) {
meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()));
}
});
filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).index(12).toIndex(13); // Aggressive
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_12.getTypeFromId(type, false);
}
@Override
public EntityType objectTypeFromId(int type) {
return EntityTypes1_12.getTypeFromId(type, true);
}
}

Datei anzeigen

@ -0,0 +1,96 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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.viaversion.protocols.v1_11_1to1_12.rewriter;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_12;
import com.viaversion.viaversion.protocols.v1_11_1to1_12.Protocol1_11_1To1_12;
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class EntityPacketRewriter1_12 extends EntityRewriter<ClientboundPackets1_9_3, Protocol1_11_1To1_12> {
public EntityPacketRewriter1_12(Protocol1_11_1To1_12 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_9_3.ADD_ENTITY, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity id
map(Types.UUID); // 1 - UUID
map(Types.BYTE); // 2 - Type
// Track Entity
handler(objectTrackerHandler());
}
});
protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() {
@Override
public void register() {
map(Types.VAR_INT); // 0 - Entity ID
map(Types.UUID); // 1 - Entity UUID
map(Types.VAR_INT); // 2 - Entity Type
map(Types.DOUBLE); // 3 - X
map(Types.DOUBLE); // 4 - Y
map(Types.DOUBLE); // 5 - Z
map(Types.BYTE); // 6 - Yaw
map(Types.BYTE); // 7 - Pitch
map(Types.BYTE); // 8 - Head Pitch
map(Types.SHORT); // 9 - Velocity X
map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z
map(Types1_12.METADATA_LIST); // 12 - Metadata
// Track mob and rewrite metadata
handler(trackerAndRewriterHandler(Types1_12.METADATA_LIST));
}
});
registerRemoveEntities(ClientboundPackets1_9_3.REMOVE_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_9_3.SET_ENTITY_DATA, Types1_12.METADATA_LIST);
}
@Override
protected void registerRewrites() {
filter().handler((event, meta) -> {
if (meta.getValue() instanceof Item) {
meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()));
}
});
filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).index(12).toIndex(13); // Aggressive
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_12.getTypeFromId(type, false);
}
@Override
public EntityType objectTypeFromId(int type) {
return EntityTypes1_12.getTypeFromId(type, true);
}
}

Datei anzeigen

@ -35,7 +35,6 @@ import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
@ -56,11 +55,10 @@ import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.MappingData1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.RecipeData;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.StatisticData;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.StatisticMappings;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.metadata.MetadataRewriter1_13To1_12_2;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.EntityPacketRewriter1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.BlockEntityProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PaintingProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.EntityPacketRewriter1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.ItemPacketRewriter1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.WorldPacketRewriter1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.storage.BlockConnectionStorage;
@ -84,7 +82,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
// These are arbitrary rewrite values, it just needs an invalid color code character.
private static final Map<Character, Character> SCOREBOARD_TEAM_NAME_REWRITE = new HashMap<>();
private static final Set<Character> FORMATTING_CODES = Sets.newHashSet('k', 'l', 'm', 'n', 'o', 'r');
private final MetadataRewriter1_13To1_12_2 entityRewriter = new MetadataRewriter1_13To1_12_2(this);
private final EntityPacketRewriter1_13 entityRewriter = new EntityPacketRewriter1_13(this);
private final ItemPacketRewriter1_13 itemRewriter = new ItemPacketRewriter1_13(this);
private final ComponentRewriter1_13<ClientboundPackets1_12_1> componentRewriter = new ComponentRewriter1_13<>(this);
@ -172,7 +170,6 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
protected void registerPackets() {
super.registerPackets();
EntityPacketRewriter1_13.register(this);
WorldPacketRewriter1_13.register(this);
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_DISCONNECT.getId(), ClientboundLoginPackets.LOGIN_DISCONNECT.getId(), wrapper -> {
@ -904,7 +901,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
}
@Override
public MetadataRewriter1_13To1_12_2 getEntityRewriter() {
public EntityPacketRewriter1_13 getEntityRewriter() {
return entityRewriter;
}

Datei anzeigen

@ -1,110 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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.viaversion.protocols.v1_12_2to1_13.metadata;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.EntityTypeRewriter;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.ParticleRewriter;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.WorldPacketRewriter1_13;
import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
public class MetadataRewriter1_13To1_12_2 extends EntityRewriter<ClientboundPackets1_12_1, Protocol1_12_2To1_13> {
public MetadataRewriter1_13To1_12_2(Protocol1_12_2To1_13 protocol) {
super(protocol);
}
@Override
protected void registerRewrites() {
filter().mapMetaType(typeId -> Types1_13.META_TYPES.byId(typeId > 4 ? typeId + 1 : typeId));
filter().metaType(Types1_13.META_TYPES.itemType).handler(((event, meta) -> protocol.getItemRewriter().handleItemToClient(event.user(), meta.value())));
filter().metaType(Types1_13.META_TYPES.optionalBlockStateType).handler(((event, meta) -> {
final int oldId = meta.value();
if (oldId != 0) {
final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
final int newId = WorldPacketRewriter1_13.toNewId(combined);
meta.setValue(newId);
}
}));
// Previously unused, now swimming
filter().index(0).handler((event, meta) -> meta.setValue((byte) ((byte) meta.getValue() & ~0x10)));
filter().index(2).handler(((event, meta) -> {
if (meta.getValue() != null && !((String) meta.getValue()).isEmpty()) {
meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, ComponentUtil.legacyToJson((String) meta.getValue()));
} else {
meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, null);
}
}));
filter().type(EntityTypes1_13.EntityType.WOLF).index(17).handler((event, meta) -> {
// Handle new colors
meta.setValue(15 - (int) meta.getValue());
});
filter().type(EntityTypes1_13.EntityType.ZOMBIE).addIndex(15); // Shaking
filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> {
final int oldId = meta.value();
final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
final int newId = WorldPacketRewriter1_13.toNewId(combined);
meta.setValue(newId);
});
filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).handler((event, meta) -> {
if (meta.id() == 9) {
int particleId = meta.value();
Metadata parameter1Meta = event.metaAtIndex(10);
Metadata parameter2Meta = event.metaAtIndex(11);
int parameter1 = parameter1Meta != null ? parameter1Meta.value() : 0;
int parameter2 = parameter2Meta != null ? parameter2Meta.value() : 0;
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
if (particle != null && particle.id() != -1) {
event.createExtraMeta(new Metadata(9, Types1_13.META_TYPES.particleType, particle));
}
}
if (meta.id() >= 9) {
event.cancel();
}
});
}
@Override
public int newEntityId(final int id) {
return EntityTypeRewriter.getNewId(id);
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_13.getTypeFromId(type, false);
}
@Override
public EntityType objectTypeFromId(int type) {
return EntityTypes1_13.getTypeFromId(type, true);
}
}

Datei anzeigen

@ -19,21 +19,29 @@ package com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_12;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.metadata.MetadataRewriter1_13To1_12_2;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.EntityTypeRewriter;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.ParticleRewriter;
import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
public class EntityPacketRewriter1_13 {
public class EntityPacketRewriter1_13 extends EntityRewriter<ClientboundPackets1_12_1, Protocol1_12_2To1_13> {
public static void register(Protocol1_12_2To1_13 protocol) {
MetadataRewriter1_13To1_12_2 metadataRewriter = protocol.get(MetadataRewriter1_13To1_12_2.class);
public EntityPacketRewriter1_13(Protocol1_12_2To1_13 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_12_1.ADD_ENTITY, new PacketHandlers() {
@Override
public void register() {
@ -96,7 +104,7 @@ public class EntityPacketRewriter1_13 {
map(Types.SHORT); // 11 - Velocity Z
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST));
handler(trackerAndRewriterHandler(Types1_13.METADATA_LIST));
}
});
@ -112,7 +120,7 @@ public class EntityPacketRewriter1_13 {
map(Types.BYTE); // 6 - Pitch
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 7 - Metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST, EntityTypes1_13.EntityType.PLAYER));
handler(trackerAndRewriterHandler(Types1_13.METADATA_LIST, EntityTypes1_13.EntityType.PLAYER));
}
});
@ -128,7 +136,7 @@ public class EntityPacketRewriter1_13 {
int dimensionId = wrapper.get(Types.INT, 1);
clientChunks.setEnvironment(dimensionId);
});
handler(metadataRewriter.playerTrackerHandler());
handler(playerTrackerHandler());
handler(Protocol1_12_2To1_13.SEND_DECLARE_COMMANDS_AND_TAGS);
}
});
@ -152,7 +160,79 @@ public class EntityPacketRewriter1_13 {
}
});
metadataRewriter.registerRemoveEntities(ClientboundPackets1_12_1.REMOVE_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_12_1.SET_ENTITY_DATA, Types1_12.METADATA_LIST, Types1_13.METADATA_LIST);
registerRemoveEntities(ClientboundPackets1_12_1.REMOVE_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_12_1.SET_ENTITY_DATA, Types1_12.METADATA_LIST, Types1_13.METADATA_LIST);
}
}
@Override
protected void registerRewrites() {
filter().mapMetaType(typeId -> Types1_13.META_TYPES.byId(typeId > 4 ? typeId + 1 : typeId));
filter().metaType(Types1_13.META_TYPES.itemType).handler(((event, meta) -> protocol.getItemRewriter().handleItemToClient(event.user(), meta.value())));
filter().metaType(Types1_13.META_TYPES.optionalBlockStateType).handler(((event, meta) -> {
final int oldId = meta.value();
if (oldId != 0) {
final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
final int newId = WorldPacketRewriter1_13.toNewId(combined);
meta.setValue(newId);
}
}));
// Previously unused, now swimming
filter().index(0).handler((event, meta) -> meta.setValue((byte) ((byte) meta.getValue() & ~0x10)));
filter().index(2).handler(((event, meta) -> {
if (meta.getValue() != null && !((String) meta.getValue()).isEmpty()) {
meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, ComponentUtil.legacyToJson((String) meta.getValue()));
} else {
meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, null);
}
}));
filter().type(EntityTypes1_13.EntityType.WOLF).index(17).handler((event, meta) -> {
// Handle new colors
meta.setValue(15 - (int) meta.getValue());
});
filter().type(EntityTypes1_13.EntityType.ZOMBIE).addIndex(15); // Shaking
filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> {
final int oldId = meta.value();
final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15));
final int newId = WorldPacketRewriter1_13.toNewId(combined);
meta.setValue(newId);
});
filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).handler((event, meta) -> {
if (meta.id() == 9) {
int particleId = meta.value();
Metadata parameter1Meta = event.metaAtIndex(10);
Metadata parameter2Meta = event.metaAtIndex(11);
int parameter1 = parameter1Meta != null ? parameter1Meta.value() : 0;
int parameter2 = parameter2Meta != null ? parameter2Meta.value() : 0;
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
if (particle != null && particle.id() != -1) {
event.createExtraMeta(new Metadata(9, Types1_13.META_TYPES.particleType, particle));
}
}
if (meta.id() >= 9) {
event.cancel();
}
});
}
@Override
public int newEntityId(final int id) {
return EntityTypeRewriter.getNewId(id);
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_13.getTypeFromId(type, false);
}
@Override
public EntityType objectTypeFromId(int type) {
return EntityTypes1_13.getTypeFromId(type, true);
}
}

Datei anzeigen

@ -21,7 +21,6 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_13_2;
@ -30,12 +29,11 @@ import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPacke
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.data.ComponentRewriter1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.data.MappingData1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.metadata.MetadataRewriter1_14To1_13_2;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.EntityPacketRewriter1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.EntityPacketRewriter1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.ItemPacketRewriter1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.PlayerPackets1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.PlayerPacketRewriter1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.WorldPacketRewriter1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.storage.EntityTracker1_14;
import com.viaversion.viaversion.rewriter.CommandRewriter;
@ -47,7 +45,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_13, ClientboundPackets1_14, ServerboundPackets1_13, ServerboundPackets1_14> {
public static final MappingData1_14 MAPPINGS = new MappingData1_14();
private final MetadataRewriter1_14To1_13_2 metadataRewriter = new MetadataRewriter1_14To1_13_2(this);
private final EntityPacketRewriter1_14 entityRewriter = new EntityPacketRewriter1_14(this);
private final ItemPacketRewriter1_14 itemRewriter = new ItemPacketRewriter1_14(this);
public Protocol1_13_2To1_14() {
@ -58,9 +56,8 @@ public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_1
protected void registerPackets() {
super.registerPackets();
EntityPacketRewriter1_14.register(this);
WorldPacketRewriter1_14.register(this);
PlayerPackets1_14.register(this);
PlayerPacketRewriter1_14.register(this);
new SoundRewriter<>(this).registerSound(ClientboundPackets1_13.SOUND);
new StatisticsRewriter<>(this).register(ClientboundPackets1_13.AWARD_STATS);
@ -177,8 +174,8 @@ public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_1
}
@Override
public MetadataRewriter1_14To1_13_2 getEntityRewriter() {
return metadataRewriter;
public EntityPacketRewriter1_14 getEntityRewriter() {
return entityRewriter;
}
@Override

Datei anzeigen

@ -1,231 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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.viaversion.protocols.v1_13_2to1_14.metadata;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.VillagerData;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.Protocol1_13_2To1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.storage.EntityTracker1_14;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<ClientboundPackets1_13, Protocol1_13_2To1_14> {
public MetadataRewriter1_14To1_13_2(Protocol1_13_2To1_14 protocol) {
super(protocol);
}
@Override
protected void registerRewrites() {
filter().mapMetaType(Types1_14.META_TYPES::byId);
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.optionalBlockStateType, Types1_14.META_TYPES.particleType);
filter().type(EntityTypes1_14.ENTITY).addIndex(6);
filter().type(EntityTypes1_14.LIVING_ENTITY).addIndex(12);
filter().type(EntityTypes1_14.LIVING_ENTITY).index(8).handler((event, meta) -> {
float value = ((Number) meta.getValue()).floatValue();
if (Float.isNaN(value) && Via.getConfig().is1_14HealthNaNFix()) {
meta.setValue(1F);
}
});
filter().type(EntityTypes1_14.MOB).index(13).handler((event, meta) -> {
EntityTracker1_14 tracker = tracker(event.user());
int entityId = event.entityId();
tracker.setInsentientData(entityId, (byte) ((((Number) meta.getValue()).byteValue() & ~0x4)
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
meta.setValue(tracker.getInsentientData(entityId));
});
filter().type(EntityTypes1_14.PLAYER).handler((event, meta) -> {
EntityTracker1_14 tracker = tracker(event.user());
int entityId = event.entityId();
if (entityId != tracker.clientEntityId()) {
if (meta.id() == 0) {
byte flags = ((Number) meta.getValue()).byteValue();
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
tracker.setEntityFlags(entityId, flags);
} else if (meta.id() == 7) {
tracker.setRiptide(entityId, (((Number) meta.getValue()).byteValue() & 0x4) != 0);
}
if (meta.id() == 0 || meta.id() == 7) {
event.createExtraMeta(new Metadata(6, Types1_14.META_TYPES.poseType, recalculatePlayerPose(entityId, tracker)));
}
}
});
filter().type(EntityTypes1_14.ZOMBIE).handler((event, meta) -> {
if (meta.id() == 16) {
EntityTracker1_14 tracker = tracker(event.user());
int entityId = event.entityId();
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking
event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
event.cancel(); // "Are hands held up"
} else if (meta.id() > 16) {
meta.setId(meta.id() - 1);
}
});
filter().type(EntityTypes1_14.ABSTRACT_MINECART).index(10).handler((event, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_14.HORSE).index(18).handler((event, meta) -> {
event.cancel();
int armorType = meta.value();
Item armorItem = null;
if (armorType == 1) { //iron armor
armorItem = new DataItem(protocol.getMappingData().getNewItemId(727), (byte) 1, (short) 0, null);
} else if (armorType == 2) { //gold armor
armorItem = new DataItem(protocol.getMappingData().getNewItemId(728), (byte) 1, (short) 0, null);
} else if (armorType == 3) { //diamond armor
armorItem = new DataItem(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null);
}
PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_14.SET_EQUIPPED_ITEM, null, event.user());
equipmentPacket.write(Types.VAR_INT, event.entityId());
equipmentPacket.write(Types.VAR_INT, 4);
equipmentPacket.write(Types.ITEM1_13_2, armorItem);
try {
equipmentPacket.scheduleSend(Protocol1_13_2To1_14.class);
} catch (final Exception e) {
throw new RuntimeException(e);
}
});
filter().type(EntityTypes1_14.VILLAGER).index(15).handler((event, meta) -> {
meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0));
});
filter().type(EntityTypes1_14.ZOMBIE_VILLAGER).index(18).handler((event, meta) -> {
meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0));
});
filter().type(EntityTypes1_14.ABSTRACT_ARROW).addIndex(9); // Piercing level added
filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, meta) -> {
meta.setMetaType(Types1_14.META_TYPES.optionalVarIntType);
if (meta.getValue().equals(0)) {
meta.setValue(null); // https://bugs.mojang.com/browse/MC-111480
}
});
filter().type(EntityTypes1_14.ABSTRACT_SKELETON).index(14).handler((event, meta) -> {
EntityTracker1_14 tracker = tracker(event.user());
int entityId = event.entityId();
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking
event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
event.cancel(); // "Is swinging arms"
});
filter().type(EntityTypes1_14.ABSTRACT_ILLAGER).handler((event, meta) -> {
if (event.index() == 14) {
EntityTracker1_14 tracker = tracker(event.user());
int entityId = event.entityId();
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| (((Number) meta.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking
event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
event.cancel(); // "Has target (aggressive state)"
} else if (event.index() > 14) {
meta.setId(meta.id() - 1);
}
});
filter().type(EntityTypes1_14.OCELOT).removeIndex(17); // variant
// Ocelot is not tamable anymore
filter().type(EntityTypes1_14.OCELOT).removeIndex(16); // owner uuid
filter().type(EntityTypes1_14.OCELOT).removeIndex(15); // data
filter().type(EntityTypes1_14.ABSTRACT_RAIDER).addIndex(14); // celebrating
}
@Override
public void onMappingDataLoaded() {
mapTypes();
if (Via.getConfig().translateOcelotToCat()) {
// A better solution for this would be to despawn the ocelot and spawn a cat in its place, but that would
// require a lot of data tracking and is not worth the effort.
mapEntityType(EntityTypes1_13.EntityType.OCELOT, EntityTypes1_14.CAT);
}
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_14.getTypeFromId(type);
}
private static boolean isSneaking(byte flags) {
return (flags & 0x2) != 0;
}
private static boolean isSwimming(byte flags) {
return (flags & 0x10) != 0;
}
private static int getNewProfessionId(int old) {
// profession -> career
return switch (old) {
case 0 -> 5; // farmer
case 1 -> 9; // librarian
case 2 -> 4; // priest ->cleric
case 3 -> 1; // blacksmith -> armorer
case 4 -> 2; // butcher
case 5 -> 11; // nitwit
default -> 0; // none
};
}
private static boolean isFallFlying(int entityFlags) {
return (entityFlags & 0x80) != 0;
}
public static int recalculatePlayerPose(int entityId, EntityTracker1_14 tracker) {
byte flags = tracker.getEntityFlags(entityId);
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
int pose = 0; // standing
if (isFallFlying(flags)) {
pose = 1;
} else if (tracker.isSleeping(entityId)) {
pose = 2;
} else if (isSwimming(flags)) {
pose = 3;
} else if (tracker.isRiptide(entityId)) {
pose = 4;
} else if (isSneaking(flags)) {
pose = 5;
}
return pose;
}
}

Datei anzeigen

@ -17,40 +17,46 @@
*/
package com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.VillagerData;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_13_2;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.Protocol1_13_2To1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.metadata.MetadataRewriter1_14To1_13_2;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.storage.EntityTracker1_14;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import java.util.LinkedList;
import java.util.List;
public class EntityPacketRewriter1_14 {
public class EntityPacketRewriter1_14 extends EntityRewriter<ClientboundPackets1_13, Protocol1_13_2To1_14> {
public static void register(Protocol1_13_2To1_14 protocol) {
MetadataRewriter1_14To1_13_2 metadataRewriter = protocol.get(MetadataRewriter1_14To1_13_2.class);
public EntityPacketRewriter1_14(Protocol1_13_2To1_14 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_13.ADD_EXPERIENCE_ORB, wrapper -> {
int entityId = wrapper.passthrough(Types.VAR_INT);
metadataRewriter.tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.EXPERIENCE_ORB);
tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.EXPERIENCE_ORB);
});
protocol.registerClientbound(ClientboundPackets1_13.ADD_GLOBAL_ENTITY, wrapper -> {
int entityId = wrapper.passthrough(Types.VAR_INT);
if (wrapper.passthrough(Types.BYTE) == 1) {
metadataRewriter.tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.LIGHTNING_BOLT);
tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.LIGHTNING_BOLT);
}
});
@ -76,7 +82,7 @@ public class EntityPacketRewriter1_14 {
int typeId = wrapper.get(Types.VAR_INT, 1);
EntityTypes1_13.EntityType type1_13 = EntityTypes1_13.getTypeFromId(typeId, true);
typeId = metadataRewriter.newEntityId(type1_13.getId());
typeId = newEntityId(type1_13.getId());
EntityType type1_14 = EntityTypes1_14.getTypeFromId(typeId);
if (type1_14 != null) {
@ -94,7 +100,7 @@ public class EntityPacketRewriter1_14 {
default -> typeId; // default 0 = rideable minecart
};
} else if ((type1_14.is(EntityTypes1_14.ITEM) && data > 0)
|| type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) {
|| type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) {
if (type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) {
wrapper.set(Types.INT, 0, data - 1);
}
@ -133,7 +139,7 @@ public class EntityPacketRewriter1_14 {
map(Types.SHORT); // 11 - Velocity Z
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 12 - Metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST));
handler(trackerAndRewriterHandler(Types1_14.METADATA_LIST));
}
});
@ -145,7 +151,7 @@ public class EntityPacketRewriter1_14 {
map(Types.VAR_INT);
map(Types.BLOCK_POSITION1_8, Types.BLOCK_POSITION1_14);
map(Types.BYTE);
handler(wrapper -> metadataRewriter.tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), EntityTypes1_14.PAINTING));
handler(wrapper -> tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), EntityTypes1_14.PAINTING));
}
});
@ -161,7 +167,7 @@ public class EntityPacketRewriter1_14 {
map(Types.BYTE); // 6 - Pitch
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 7 - Metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST, EntityTypes1_14.PLAYER));
handler(trackerAndRewriterHandler(Types1_14.METADATA_LIST, EntityTypes1_14.PLAYER));
}
});
@ -180,7 +186,7 @@ public class EntityPacketRewriter1_14 {
metadataPacket.write(Types.VAR_INT, entityId);
List<Metadata> metadataList = new LinkedList<>();
if (tracker.clientEntityId() != entityId) {
metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker)));
metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, EntityPacketRewriter1_14.recalculatePlayerPose(entityId, tracker)));
}
metadataList.add(new Metadata(12, Types1_14.META_TYPES.optionalBlockPositionType, null));
metadataPacket.write(Types1_14.METADATA_LIST, metadataList);
@ -202,7 +208,7 @@ public class EntityPacketRewriter1_14 {
int dimensionId = wrapper.get(Types.INT, 1);
clientChunks.setEnvironment(dimensionId);
});
handler(metadataRewriter.playerTrackerHandler());
handler(playerTrackerHandler());
handler(wrapper -> {
short difficulty = wrapper.read(Types.UNSIGNED_BYTE); // 19w11a removed difficulty from join game
PacketWrapper difficultyPacket = wrapper.create(ClientboundPackets1_14.CHANGE_DIFFICULTY);
@ -239,14 +245,202 @@ public class EntityPacketRewriter1_14 {
List<Metadata> metadataList = new LinkedList<>();
metadataList.add(new Metadata(12, Types1_14.META_TYPES.optionalBlockPositionType, position));
if (tracker.clientEntityId() != entityId) {
metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker)));
metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, EntityPacketRewriter1_14.recalculatePlayerPose(entityId, tracker)));
}
wrapper.write(Types1_14.METADATA_LIST, metadataList);
});
}
});
metadataRewriter.registerRemoveEntities(ClientboundPackets1_13.REMOVE_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.SET_ENTITY_DATA, Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST);
registerRemoveEntities(ClientboundPackets1_13.REMOVE_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_13.SET_ENTITY_DATA, Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST);
}
@Override
protected void registerRewrites() {
filter().mapMetaType(Types1_14.META_TYPES::byId);
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.optionalBlockStateType, Types1_14.META_TYPES.particleType);
filter().type(EntityTypes1_14.ENTITY).addIndex(6);
filter().type(EntityTypes1_14.LIVING_ENTITY).addIndex(12);
filter().type(EntityTypes1_14.LIVING_ENTITY).index(8).handler((event, meta) -> {
float value = ((Number) meta.getValue()).floatValue();
if (Float.isNaN(value) && Via.getConfig().is1_14HealthNaNFix()) {
meta.setValue(1F);
}
});
filter().type(EntityTypes1_14.MOB).index(13).handler((event, meta) -> {
EntityTracker1_14 tracker = tracker(event.user());
int entityId = event.entityId();
tracker.setInsentientData(entityId, (byte) ((((Number) meta.getValue()).byteValue() & ~0x4)
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
meta.setValue(tracker.getInsentientData(entityId));
});
filter().type(EntityTypes1_14.PLAYER).handler((event, meta) -> {
EntityTracker1_14 tracker = tracker(event.user());
int entityId = event.entityId();
if (entityId != tracker.clientEntityId()) {
if (meta.id() == 0) {
byte flags = ((Number) meta.getValue()).byteValue();
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
tracker.setEntityFlags(entityId, flags);
} else if (meta.id() == 7) {
tracker.setRiptide(entityId, (((Number) meta.getValue()).byteValue() & 0x4) != 0);
}
if (meta.id() == 0 || meta.id() == 7) {
event.createExtraMeta(new Metadata(6, Types1_14.META_TYPES.poseType, recalculatePlayerPose(entityId, tracker)));
}
}
});
filter().type(EntityTypes1_14.ZOMBIE).handler((event, meta) -> {
if (meta.id() == 16) {
EntityTracker1_14 tracker = tracker(event.user());
int entityId = event.entityId();
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking
event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
event.cancel(); // "Are hands held up"
} else if (meta.id() > 16) {
meta.setId(meta.id() - 1);
}
});
filter().type(EntityTypes1_14.ABSTRACT_MINECART).index(10).handler((event, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_14.HORSE).index(18).handler((event, meta) -> {
event.cancel();
int armorType = meta.value();
Item armorItem = null;
if (armorType == 1) { //iron armor
armorItem = new DataItem(protocol.getMappingData().getNewItemId(727), (byte) 1, (short) 0, null);
} else if (armorType == 2) { //gold armor
armorItem = new DataItem(protocol.getMappingData().getNewItemId(728), (byte) 1, (short) 0, null);
} else if (armorType == 3) { //diamond armor
armorItem = new DataItem(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null);
}
PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_14.SET_EQUIPPED_ITEM, null, event.user());
equipmentPacket.write(Types.VAR_INT, event.entityId());
equipmentPacket.write(Types.VAR_INT, 4);
equipmentPacket.write(Types.ITEM1_13_2, armorItem);
try {
equipmentPacket.scheduleSend(Protocol1_13_2To1_14.class);
} catch (final Exception e) {
throw new RuntimeException(e);
}
});
filter().type(EntityTypes1_14.VILLAGER).index(15).handler((event, meta) -> {
meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0));
});
filter().type(EntityTypes1_14.ZOMBIE_VILLAGER).index(18).handler((event, meta) -> {
meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0));
});
filter().type(EntityTypes1_14.ABSTRACT_ARROW).addIndex(9); // Piercing level added
filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, meta) -> {
meta.setMetaType(Types1_14.META_TYPES.optionalVarIntType);
if (meta.getValue().equals(0)) {
meta.setValue(null); // https://bugs.mojang.com/browse/MC-111480
}
});
filter().type(EntityTypes1_14.ABSTRACT_SKELETON).index(14).handler((event, meta) -> {
EntityTracker1_14 tracker = tracker(event.user());
int entityId = event.entityId();
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking
event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
event.cancel(); // "Is swinging arms"
});
filter().type(EntityTypes1_14.ABSTRACT_ILLAGER).handler((event, meta) -> {
if (event.index() == 14) {
EntityTracker1_14 tracker = tracker(event.user());
int entityId = event.entityId();
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| (((Number) meta.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking
event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId)));
event.cancel(); // "Has target (aggressive state)"
} else if (event.index() > 14) {
meta.setId(meta.id() - 1);
}
});
filter().type(EntityTypes1_14.OCELOT).removeIndex(17); // variant
// Ocelot is not tamable anymore
filter().type(EntityTypes1_14.OCELOT).removeIndex(16); // owner uuid
filter().type(EntityTypes1_14.OCELOT).removeIndex(15); // data
filter().type(EntityTypes1_14.ABSTRACT_RAIDER).addIndex(14); // celebrating
}
@Override
public void onMappingDataLoaded() {
mapTypes();
if (Via.getConfig().translateOcelotToCat()) {
// A better solution for this would be to despawn the ocelot and spawn a cat in its place, but that would
// require a lot of data tracking and is not worth the effort.
mapEntityType(EntityTypes1_13.EntityType.OCELOT, EntityTypes1_14.CAT);
}
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_14.getTypeFromId(type);
}
private static boolean isSneaking(byte flags) {
return (flags & 0x2) != 0;
}
private static boolean isSwimming(byte flags) {
return (flags & 0x10) != 0;
}
private static int getNewProfessionId(int old) {
// profession -> career
return switch (old) {
case 0 -> 5; // farmer
case 1 -> 9; // librarian
case 2 -> 4; // priest ->cleric
case 3 -> 1; // blacksmith -> armorer
case 4 -> 2; // butcher
case 5 -> 11; // nitwit
default -> 0; // none
};
}
private static boolean isFallFlying(int entityFlags) {
return (entityFlags & 0x80) != 0;
}
public static int recalculatePlayerPose(int entityId, EntityTracker1_14 tracker) {
byte flags = tracker.getEntityFlags(entityId);
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
int pose = 0; // standing
if (isFallFlying(flags)) {
pose = 1;
} else if (tracker.isSleeping(entityId)) {
pose = 2;
} else if (isSwimming(flags)) {
pose = 3;
} else if (tracker.isRiptide(entityId)) {
pose = 4;
} else if (isSneaking(flags)) {
pose = 5;
}
return pose;
}
}

Datei anzeigen

@ -24,14 +24,12 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.Protocol1_13_2To1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14;
import java.util.Collections;
public class PlayerPackets1_14 {
public class PlayerPacketRewriter1_14 {
public static void register(Protocol1_13_2To1_14 protocol) {
protocol.registerClientbound(ClientboundPackets1_13.OPEN_SIGN_EDITOR, new PacketHandlers() {

Datei anzeigen

@ -28,12 +28,10 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_13to1_13_1.metadata.MetadataRewriter1_13_1To1_13;
import com.viaversion.viaversion.protocols.v1_13to1_13_1.rewriter.EntityPacketRewriter1_13_1;
import com.viaversion.viaversion.protocols.v1_13to1_13_1.rewriter.ItemPacketRewriter1_13_1;
import com.viaversion.viaversion.protocols.v1_13to1_13_1.rewriter.WorldPacketRewriter1_13_1;
@ -43,7 +41,7 @@ import com.viaversion.viaversion.rewriter.TagRewriter;
public class Protocol1_13To1_13_1 extends AbstractProtocol<ClientboundPackets1_13, ClientboundPackets1_13, ServerboundPackets1_13, ServerboundPackets1_13> {
public static final MappingData MAPPINGS = new MappingDataBase("1.13", "1.13.2");
private final MetadataRewriter1_13_1To1_13 entityRewriter = new MetadataRewriter1_13_1To1_13(this);
private final EntityPacketRewriter1_13_1 entityRewriter = new EntityPacketRewriter1_13_1(this);
private final ItemPacketRewriter1_13_1 itemRewriter = new ItemPacketRewriter1_13_1(this);
private final TagRewriter<ClientboundPackets1_13> tagRewriter = new TagRewriter<>(this);
@ -55,7 +53,6 @@ public class Protocol1_13To1_13_1 extends AbstractProtocol<ClientboundPackets1_1
protected void registerPackets() {
super.registerPackets();
EntityPacketRewriter1_13_1.register(this);
WorldPacketRewriter1_13_1.register(this);
registerServerbound(ServerboundPackets1_13.COMMAND_SUGGESTION, new PacketHandlers() {
@ -148,7 +145,7 @@ public class Protocol1_13To1_13_1 extends AbstractProtocol<ClientboundPackets1_1
}
@Override
public MetadataRewriter1_13_1To1_13 getEntityRewriter() {
public EntityPacketRewriter1_13_1 getEntityRewriter() {
return entityRewriter;
}

Datei anzeigen

@ -1,52 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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.viaversion.protocols.v1_13to1_13_1.metadata;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_13to1_13_1.Protocol1_13To1_13_1;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class MetadataRewriter1_13_1To1_13 extends EntityRewriter<ClientboundPackets1_13, Protocol1_13To1_13_1> {
public MetadataRewriter1_13_1To1_13(Protocol1_13To1_13_1 protocol) {
super(protocol);
}
@Override
protected void registerRewrites() {
registerMetaTypeHandler(Types1_13.META_TYPES.itemType, Types1_13.META_TYPES.optionalBlockStateType, Types1_13.META_TYPES.particleType);
filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_13.EntityType.ABSTRACT_ARROW).addIndex(7); // Shooter UUID
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_13.getTypeFromId(type, false);
}
@Override
public EntityType objectTypeFromId(int type) {
return EntityTypes1_13.getTypeFromId(type, true);
}
}

Datei anzeigen

@ -17,20 +17,23 @@
*/
package com.viaversion.viaversion.protocols.v1_13to1_13_1.rewriter;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.v1_13to1_13_1.Protocol1_13To1_13_1;
import com.viaversion.viaversion.protocols.v1_13to1_13_1.metadata.MetadataRewriter1_13_1To1_13;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class EntityPacketRewriter1_13_1 {
public class EntityPacketRewriter1_13_1 extends EntityRewriter<ClientboundPackets1_13, Protocol1_13To1_13_1> {
public static void register(Protocol1_13To1_13_1 protocol) {
MetadataRewriter1_13_1To1_13 metadataRewriter = protocol.get(MetadataRewriter1_13_1To1_13.class);
public EntityPacketRewriter1_13_1(Protocol1_13To1_13_1 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_13.ADD_ENTITY, new PacketHandlers() {
@Override
public void register() {
@ -79,7 +82,7 @@ public class EntityPacketRewriter1_13_1 {
map(Types.SHORT); // 11 - Velocity Z
map(Types1_13.METADATA_LIST); // 12 - Metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST));
handler(trackerAndRewriterHandler(Types1_13.METADATA_LIST));
}
});
@ -95,11 +98,31 @@ public class EntityPacketRewriter1_13_1 {
map(Types.BYTE); // 6 - Pitch
map(Types1_13.METADATA_LIST); // 7 - Metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST, EntityTypes1_13.EntityType.PLAYER));
handler(trackerAndRewriterHandler(Types1_13.METADATA_LIST, EntityTypes1_13.EntityType.PLAYER));
}
});
metadataRewriter.registerRemoveEntities(ClientboundPackets1_13.REMOVE_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.SET_ENTITY_DATA, Types1_13.METADATA_LIST);
registerRemoveEntities(ClientboundPackets1_13.REMOVE_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_13.SET_ENTITY_DATA, Types1_13.METADATA_LIST);
}
@Override
protected void registerRewrites() {
registerMetaTypeHandler(Types1_13.META_TYPES.itemType, Types1_13.META_TYPES.optionalBlockStateType, Types1_13.META_TYPES.particleType);
filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_13.EntityType.ABSTRACT_ARROW).addIndex(7); // Shooter UUID
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_13.getTypeFromId(type, false);
}
@Override
public EntityType objectTypeFromId(int type) {
return EntityTypes1_13.getTypeFromId(type, true);
}
}

Datei anzeigen

@ -23,14 +23,12 @@ import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_14_3to1_14_4.packet.ClientboundPackets1_14_4;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.metadata.MetadataRewriter1_15To1_14_4;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter.EntityPacketRewriter1_15;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter.ItemPacketRewriter1_15;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter.WorldPacketRewriter1_15;
import com.viaversion.viaversion.rewriter.SoundRewriter;
@ -40,7 +38,7 @@ import com.viaversion.viaversion.rewriter.TagRewriter;
public class Protocol1_14_4To1_15 extends AbstractProtocol<ClientboundPackets1_14_4, ClientboundPackets1_15, ServerboundPackets1_14, ServerboundPackets1_14> {
public static final MappingData MAPPINGS = new MappingDataBase("1.14", "1.15");
private final MetadataRewriter1_15To1_14_4 metadataRewriter = new MetadataRewriter1_15To1_14_4(this);
private final EntityPacketRewriter1_15 entityRewriter = new EntityPacketRewriter1_15(this);
private final ItemPacketRewriter1_15 itemRewriter = new ItemPacketRewriter1_15(this);
private final TagRewriter<ClientboundPackets1_14_4> tagRewriter = new TagRewriter<>(this);
@ -52,7 +50,6 @@ public class Protocol1_14_4To1_15 extends AbstractProtocol<ClientboundPackets1_1
protected void registerPackets() {
super.registerPackets();
EntityPacketRewriter1_15.register(this);
WorldPacketRewriter1_15.register(this);
SoundRewriter<ClientboundPackets1_14_4> soundRewriter = new SoundRewriter<>(this);
@ -91,8 +88,8 @@ public class Protocol1_14_4To1_15 extends AbstractProtocol<ClientboundPackets1_1
}
@Override
public MetadataRewriter1_15To1_14_4 getEntityRewriter() {
return metadataRewriter;
public EntityPacketRewriter1_15 getEntityRewriter() {
return entityRewriter;
}
@Override

Datei anzeigen

@ -1,55 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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.viaversion.protocols.v1_14_4to1_15.metadata;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.protocols.v1_14_3to1_14_4.packet.ClientboundPackets1_14_4;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.Protocol1_14_4To1_15;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter.EntityPacketRewriter1_15;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class MetadataRewriter1_15To1_14_4 extends EntityRewriter<ClientboundPackets1_14_4, Protocol1_14_4To1_15> {
public MetadataRewriter1_15To1_14_4(Protocol1_14_4To1_15 protocol) {
super(protocol);
}
@Override
protected void registerRewrites() {
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.optionalBlockStateType, Types1_14.META_TYPES.particleType);
filter().type(EntityTypes1_15.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_15.LIVING_ENTITY).addIndex(12);
filter().type(EntityTypes1_15.WOLF).removeIndex(18);
}
@Override
public int newEntityId(final int id) {
return EntityPacketRewriter1_15.getNewEntityId(id);
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_15.getTypeFromId(type);
}
}

Datei anzeigen

@ -18,26 +18,28 @@
package com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.protocols.v1_14_3to1_14_4.packet.ClientboundPackets1_14_4;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.Protocol1_14_4To1_15;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.metadata.MetadataRewriter1_15To1_14_4;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import java.util.List;
public final class EntityPacketRewriter1_15 {
public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1_14_4, Protocol1_14_4To1_15> {
public static void register(Protocol1_14_4To1_15 protocol) {
MetadataRewriter1_15To1_14_4 metadataRewriter = protocol.get(MetadataRewriter1_15To1_14_4.class);
public EntityPacketRewriter1_15(Protocol1_14_4To1_15 protocol) {
super(protocol);
}
metadataRewriter.registerTrackerWithData(ClientboundPackets1_14_4.ADD_ENTITY, EntityTypes1_15.FALLING_BLOCK);
@Override
protected void registerPackets() {
registerTrackerWithData(ClientboundPackets1_14_4.ADD_ENTITY, EntityTypes1_15.FALLING_BLOCK);
protocol.registerClientbound(ClientboundPackets1_14_4.ADD_MOB, new PacketHandlers() {
@Override
@ -55,8 +57,8 @@ public final class EntityPacketRewriter1_15 {
map(Types.SHORT); // 10 - Velocity Y
map(Types.SHORT); // 11 - Velocity Z
handler(metadataRewriter.trackerHandler());
handler(wrapper -> sendMetadataPacket(wrapper, wrapper.get(Types.VAR_INT, 0), metadataRewriter));
handler(trackerHandler());
handler(wrapper -> sendMetadataPacket(wrapper, wrapper.get(Types.VAR_INT, 0)));
}
});
@ -75,7 +77,7 @@ public final class EntityPacketRewriter1_15 {
int entityId = wrapper.get(Types.VAR_INT, 0);
wrapper.user().getEntityTracker(Protocol1_14_4To1_15.class).addEntity(entityId, EntityTypes1_15.PLAYER);
sendMetadataPacket(wrapper, entityId, metadataRewriter);
sendMetadataPacket(wrapper, entityId);
});
}
});
@ -94,7 +96,7 @@ public final class EntityPacketRewriter1_15 {
map(Types.INT); // 0 - Entity ID
map(Types.UNSIGNED_BYTE); // 1 - Gamemode
map(Types.INT); // 2 - Dimension
handler(metadataRewriter.playerTrackerHandler());
handler(playerTrackerHandler());
handler(wrapper -> wrapper.write(Types.LONG, 0L)); // Level Seed
map(Types.UNSIGNED_BYTE); // 3 - Max Players
@ -106,11 +108,24 @@ public final class EntityPacketRewriter1_15 {
}
});
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14_4.SET_ENTITY_DATA, Types1_14.METADATA_LIST);
metadataRewriter.registerRemoveEntities(ClientboundPackets1_14_4.REMOVE_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_14_4.SET_ENTITY_DATA, Types1_14.METADATA_LIST);
registerRemoveEntities(ClientboundPackets1_14_4.REMOVE_ENTITIES);
}
private static void sendMetadataPacket(PacketWrapper wrapper, int entityId, EntityRewriter<?, ?> rewriter) {
@Override
protected void registerRewrites() {
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.optionalBlockStateType, Types1_14.META_TYPES.particleType);
filter().type(EntityTypes1_15.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_15.LIVING_ENTITY).addIndex(12);
filter().type(EntityTypes1_15.WOLF).removeIndex(18);
}
private void sendMetadataPacket(PacketWrapper wrapper, int entityId) {
// Meta is no longer included in the spawn packets, but sent separately
List<Metadata> metadata = wrapper.read(Types1_14.METADATA_LIST);
if (metadata.isEmpty()) {
@ -122,7 +137,7 @@ public final class EntityPacketRewriter1_15 {
wrapper.cancel();
// Handle meta
rewriter.handleMetadata(entityId, metadata, wrapper.user());
handleMetadata(entityId, metadata, wrapper.user());
PacketWrapper metadataPacket = PacketWrapper.create(ClientboundPackets1_15.SET_ENTITY_DATA, wrapper.user());
metadataPacket.write(Types.VAR_INT, entityId);
@ -130,7 +145,13 @@ public final class EntityPacketRewriter1_15 {
metadataPacket.send(Protocol1_14_4To1_15.class);
}
public static int getNewEntityId(int oldId) {
return oldId >= 4 ? oldId + 1 : oldId; // 4 = bee
@Override
public int newEntityId(final int id) {
return id >= 4 ? id + 1 : id; // 4 = bee
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_15.getTypeFromId(type);
}
}

Datei anzeigen

@ -23,12 +23,11 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_14to1_14_1.metadata.MetadataRewriter1_14_1To1_14;
import com.viaversion.viaversion.protocols.v1_14to1_14_1.rewriter.EntityPacketRewriter1_14_1;
public class Protocol1_14To1_14_1 extends AbstractProtocol<ClientboundPackets1_14, ClientboundPackets1_14, ServerboundPackets1_14, ServerboundPackets1_14> {
private final MetadataRewriter1_14_1To1_14 metadataRewriter = new MetadataRewriter1_14_1To1_14(this);
private final EntityPacketRewriter1_14_1 entityRewriter = new EntityPacketRewriter1_14_1(this);
public Protocol1_14To1_14_1() {
super(ClientboundPackets1_14.class, ClientboundPackets1_14.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class);
@ -36,9 +35,7 @@ public class Protocol1_14To1_14_1 extends AbstractProtocol<ClientboundPackets1_1
@Override
protected void registerPackets() {
super.registerPackets();
EntityPacketRewriter1_14_1.register(this);
entityRewriter.register();
}
@Override
@ -47,7 +44,7 @@ public class Protocol1_14To1_14_1 extends AbstractProtocol<ClientboundPackets1_1
}
@Override
public MetadataRewriter1_14_1To1_14 getEntityRewriter() {
return metadataRewriter;
public EntityPacketRewriter1_14_1 getEntityRewriter() {
return entityRewriter;
}
}

Datei anzeigen

@ -1,42 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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.viaversion.protocols.v1_14to1_14_1.metadata;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_14to1_14_1.Protocol1_14To1_14_1;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class MetadataRewriter1_14_1To1_14 extends EntityRewriter<ClientboundPackets1_14, Protocol1_14To1_14_1> {
public MetadataRewriter1_14_1To1_14(Protocol1_14To1_14_1 protocol) {
super(protocol);
}
@Override
protected void registerRewrites() {
filter().type(EntityTypes1_14.VILLAGER).addIndex(15);
filter().type(EntityTypes1_14.WANDERING_TRADER).addIndex(15);
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_14.getTypeFromId(type);
}
}

Datei anzeigen

@ -17,20 +17,23 @@
*/
package com.viaversion.viaversion.protocols.v1_14to1_14_1.rewriter;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_14to1_14_1.Protocol1_14To1_14_1;
import com.viaversion.viaversion.protocols.v1_14to1_14_1.metadata.MetadataRewriter1_14_1To1_14;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class EntityPacketRewriter1_14_1 {
public class EntityPacketRewriter1_14_1 extends EntityRewriter<ClientboundPackets1_14, Protocol1_14To1_14_1> {
public static void register(Protocol1_14To1_14_1 protocol) {
MetadataRewriter1_14_1To1_14 metadataRewriter = protocol.get(MetadataRewriter1_14_1To1_14.class);
public EntityPacketRewriter1_14_1(Protocol1_14To1_14_1 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_14.ADD_MOB, new PacketHandlers() {
@Override
public void register() {
@ -48,11 +51,11 @@ public class EntityPacketRewriter1_14_1 {
map(Types.SHORT); // 11 - Velocity Z
map(Types1_14.METADATA_LIST); // 12 - Metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST));
handler(trackerAndRewriterHandler(Types1_14.METADATA_LIST));
}
});
metadataRewriter.registerRemoveEntities(ClientboundPackets1_14.REMOVE_ENTITIES);
registerRemoveEntities(ClientboundPackets1_14.REMOVE_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_14.ADD_PLAYER, new PacketHandlers() {
@Override
@ -66,10 +69,21 @@ public class EntityPacketRewriter1_14_1 {
map(Types.BYTE); // 6 - Pitch
map(Types1_14.METADATA_LIST); // 7 - Metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST, EntityTypes1_14.PLAYER));
handler(trackerAndRewriterHandler(Types1_14.METADATA_LIST, EntityTypes1_14.PLAYER));
}
});
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14.SET_ENTITY_DATA, Types1_14.METADATA_LIST);
registerMetadataRewriter(ClientboundPackets1_14.SET_ENTITY_DATA, Types1_14.METADATA_LIST);
}
@Override
protected void registerRewrites() {
filter().type(EntityTypes1_14.VILLAGER).addIndex(15);
filter().type(EntityTypes1_14.WANDERING_TRADER).addIndex(15);
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_14.getTypeFromId(type);
}
}

Datei anzeigen

@ -31,7 +31,6 @@ import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_16;
@ -40,12 +39,11 @@ import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ClientboundStatusPackets;
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.TranslationMappings;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.metadata.MetadataRewriter1_16To1_15_2;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.ComponentRewriter1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.EntityPacketRewriter1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.EntityPacketRewriter1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.ItemPacketRewriter1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.WorldPacketRewriter1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.storage.InventoryTracker1_16;
@ -63,9 +61,9 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol<ClientboundPackets1_1
private static final UUID ZERO_UUID = new UUID(0, 0);
public static final MappingData MAPPINGS = new MappingDataBase("1.15", "1.16");
private final MetadataRewriter1_16To1_15_2 metadataRewriter = new MetadataRewriter1_16To1_15_2(this);
private final EntityPacketRewriter1_16 entityRewriter = new EntityPacketRewriter1_16(this);
private final ItemPacketRewriter1_16 itemRewriter = new ItemPacketRewriter1_16(this);
private final TranslationMappings componentRewriter = new TranslationMappings(this);
private final ComponentRewriter1_16 componentRewriter = new ComponentRewriter1_16(this);
private final TagRewriter<ClientboundPackets1_15> tagRewriter = new TagRewriter<>(this);
public Protocol1_15_2To1_16() {
@ -76,7 +74,6 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol<ClientboundPackets1_1
protected void registerPackets() {
super.registerPackets();
EntityPacketRewriter1_16.register(this);
WorldPacketRewriter1_16.register(this);
tagRewriter.register(ClientboundPackets1_15.UPDATE_TAGS, RegistryType.ENTITY);
@ -287,8 +284,8 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol<ClientboundPackets1_1
}
@Override
public MetadataRewriter1_16To1_15_2 getEntityRewriter() {
return metadataRewriter;
public EntityPacketRewriter1_16 getEntityRewriter() {
return entityRewriter;
}
@Override
@ -296,7 +293,7 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol<ClientboundPackets1_1
return itemRewriter;
}
public TranslationMappings getComponentRewriter() {
public ComponentRewriter1_16 getComponentRewriter() {
return componentRewriter;
}

Datei anzeigen

@ -20,7 +20,7 @@ package com.viaversion.viaversion.protocols.v1_15_2to1_16.data;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
public final class AttributeMappings {
public final class Attributes1_16 {
private static final BiMap<String, String> ATTRIBUTE_MAPPINGS = HashBiMap.create();
static {

Datei anzeigen

@ -0,0 +1,119 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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.viaversion.protocols.v1_15_2to1_16.data;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.FloatTag;
import com.viaversion.nbt.tag.IntTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.LongTag;
import com.viaversion.nbt.tag.StringTag;
import java.util.Arrays;
public class DimensionRegistries1_16 {
private static final CompoundTag DIMENSIONS_TAG = new CompoundTag();
private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"};
static {
ListTag<CompoundTag> list = new ListTag<>(CompoundTag.class);
list.add(createOverworldEntry());
list.add(createOverworldCavesEntry());
list.add(createNetherEntry());
list.add(createEndEntry());
DIMENSIONS_TAG.put("dimension", list);
}
public static CompoundTag getDimensionsTag() {
return DIMENSIONS_TAG.copy();
}
public static String[] getWorldNames() {
return Arrays.copyOf(WORLD_NAMES, WORLD_NAMES.length);
}
private static CompoundTag createOverworldEntry() {
CompoundTag tag = new CompoundTag();
tag.put("name", new StringTag("minecraft:overworld"));
tag.put("has_ceiling", new ByteTag((byte) 0));
addSharedOverwaldEntries(tag);
return tag;
}
private static CompoundTag createOverworldCavesEntry() {
CompoundTag tag = new CompoundTag();
tag.put("name", new StringTag("minecraft:overworld_caves"));
tag.put("has_ceiling", new ByteTag((byte) 1));
addSharedOverwaldEntries(tag);
return tag;
}
private static void addSharedOverwaldEntries(CompoundTag tag) {
tag.put("piglin_safe", new ByteTag((byte) 0));
tag.put("natural", new ByteTag((byte) 1));
tag.put("ambient_light", new FloatTag(0));
tag.put("infiniburn", new StringTag("minecraft:infiniburn_overworld"));
tag.put("respawn_anchor_works", new ByteTag((byte) 0));
tag.put("has_skylight", new ByteTag((byte) 1));
tag.put("bed_works", new ByteTag((byte) 1));
tag.put("has_raids", new ByteTag((byte) 1));
tag.put("logical_height", new IntTag(256));
tag.put("shrunk", new ByteTag((byte) 0));
tag.put("ultrawarm", new ByteTag((byte) 0));
}
private static CompoundTag createNetherEntry() {
CompoundTag tag = new CompoundTag();
tag.put("piglin_safe", new ByteTag((byte) 1));
tag.put("natural", new ByteTag((byte) 0));
tag.put("ambient_light", new FloatTag(0.1F));
tag.put("infiniburn", new StringTag("minecraft:infiniburn_nether"));
tag.put("respawn_anchor_works", new ByteTag((byte) 1));
tag.put("has_skylight", new ByteTag((byte) 0));
tag.put("bed_works", new ByteTag((byte) 0));
tag.put("fixed_time", new LongTag(18000));
tag.put("has_raids", new ByteTag((byte) 0));
tag.put("name", new StringTag("minecraft:the_nether"));
tag.put("logical_height", new IntTag(128));
tag.put("shrunk", new ByteTag((byte) 1));
tag.put("ultrawarm", new ByteTag((byte) 1));
tag.put("has_ceiling", new ByteTag((byte) 1));
return tag;
}
private static CompoundTag createEndEntry() {
CompoundTag tag = new CompoundTag();
tag.put("piglin_safe", new ByteTag((byte) 0));
tag.put("natural", new ByteTag((byte) 0));
tag.put("ambient_light", new FloatTag(0));
tag.put("infiniburn", new StringTag("minecraft:infiniburn_end"));
tag.put("respawn_anchor_works", new ByteTag((byte) 0));
tag.put("has_skylight", new ByteTag((byte) 0));
tag.put("bed_works", new ByteTag((byte) 0));
tag.put("fixed_time", new LongTag(6000));
tag.put("has_raids", new ByteTag((byte) 1));
tag.put("name", new StringTag("minecraft:the_end"));
tag.put("logical_height", new IntTag(256));
tag.put("shrunk", new ByteTag((byte) 0));
tag.put("ultrawarm", new ByteTag((byte) 0));
tag.put("has_ceiling", new ByteTag((byte) 0));
return tag;
}
}

Datei anzeigen

@ -1,59 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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.viaversion.protocols.v1_15_2to1_16.metadata;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.types.version.Types1_16;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.Protocol1_15_2To1_16;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class MetadataRewriter1_16To1_15_2 extends EntityRewriter<ClientboundPackets1_15, Protocol1_15_2To1_16> {
public MetadataRewriter1_16To1_15_2(Protocol1_15_2To1_16 protocol) {
super(protocol);
}
@Override
protected void registerRewrites() {
filter().mapMetaType(Types1_16.META_TYPES::byId);
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.optionalBlockStateType, Types1_16.META_TYPES.particleType);
filter().type(EntityTypes1_16.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8);
filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> {
byte mask = meta.value();
int angerTime = (mask & 0x02) != 0 ? Integer.MAX_VALUE : 0;
event.createExtraMeta(new Metadata(20, Types1_16.META_TYPES.varIntType, angerTime));
});
}
@Override
public void onMappingDataLoaded() {
mapTypes();
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_16.getTypeFromId(type);
}
}

Datei anzeigen

@ -15,7 +15,7 @@
* 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.viaversion.protocols.v1_15_2to1_16.data;
package com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@ -27,10 +27,10 @@ import com.viaversion.viaversion.rewriter.ComponentRewriter;
import java.util.HashMap;
import java.util.Map;
public class TranslationMappings extends ComponentRewriter<ClientboundPackets1_15> {
public class ComponentRewriter1_16 extends ComponentRewriter<ClientboundPackets1_15> {
private final Map<String, String> mappings = new HashMap<>();
public TranslationMappings(Protocol1_15_2To1_16 protocol) {
public ComponentRewriter1_16(Protocol1_15_2To1_16 protocol) {
super(protocol, ReadType.JSON);
mappings.put("attribute.name.generic.armorToughness", "attribute.name.generic.armor_toughness");
mappings.put("attribute.name.generic.attackDamage", "attribute.name.generic.attack_damage");

Datei anzeigen

@ -17,34 +17,28 @@
*/
package com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.FloatTag;
import com.viaversion.nbt.tag.IntTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.LongTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.api.type.types.version.Types1_16;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.Protocol1_15_2To1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.AttributeMappings;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.metadata.MetadataRewriter1_16To1_15_2;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.Attributes1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.DimensionRegistries1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.storage.InventoryTracker1_16;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.util.Key;
import java.util.Arrays;
import java.util.UUID;
public class EntityPacketRewriter1_16 {
public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1_15, Protocol1_15_2To1_16> {
private static final PacketHandler DIMENSION_HANDLER = wrapper -> {
WorldIdentifiers map = Via.getConfig().get1_16WorldNamesMap();
@ -77,89 +71,13 @@ public class EntityPacketRewriter1_16 {
wrapper.write(Types.STRING, dimensionName); // dimension
wrapper.write(Types.STRING, outputName); // world
};
public static final CompoundTag DIMENSIONS_TAG = new CompoundTag();
private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"};
static {
ListTag<CompoundTag> list = new ListTag<>(CompoundTag.class);
list.add(createOverworldEntry());
list.add(createOverworldCavesEntry());
list.add(createNetherEntry());
list.add(createEndEntry());
DIMENSIONS_TAG.put("dimension", list);
public EntityPacketRewriter1_16(Protocol1_15_2To1_16 protocol) {
super(protocol);
}
private static CompoundTag createOverworldEntry() {
CompoundTag tag = new CompoundTag();
tag.put("name", new StringTag("minecraft:overworld"));
tag.put("has_ceiling", new ByteTag((byte) 0));
addSharedOverwaldEntries(tag);
return tag;
}
private static CompoundTag createOverworldCavesEntry() {
CompoundTag tag = new CompoundTag();
tag.put("name", new StringTag("minecraft:overworld_caves"));
tag.put("has_ceiling", new ByteTag((byte) 1));
addSharedOverwaldEntries(tag);
return tag;
}
private static void addSharedOverwaldEntries(CompoundTag tag) {
tag.put("piglin_safe", new ByteTag((byte) 0));
tag.put("natural", new ByteTag((byte) 1));
tag.put("ambient_light", new FloatTag(0));
tag.put("infiniburn", new StringTag("minecraft:infiniburn_overworld"));
tag.put("respawn_anchor_works", new ByteTag((byte) 0));
tag.put("has_skylight", new ByteTag((byte) 1));
tag.put("bed_works", new ByteTag((byte) 1));
tag.put("has_raids", new ByteTag((byte) 1));
tag.put("logical_height", new IntTag(256));
tag.put("shrunk", new ByteTag((byte) 0));
tag.put("ultrawarm", new ByteTag((byte) 0));
}
private static CompoundTag createNetherEntry() {
CompoundTag tag = new CompoundTag();
tag.put("piglin_safe", new ByteTag((byte) 1));
tag.put("natural", new ByteTag((byte) 0));
tag.put("ambient_light", new FloatTag(0.1F));
tag.put("infiniburn", new StringTag("minecraft:infiniburn_nether"));
tag.put("respawn_anchor_works", new ByteTag((byte) 1));
tag.put("has_skylight", new ByteTag((byte) 0));
tag.put("bed_works", new ByteTag((byte) 0));
tag.put("fixed_time", new LongTag(18000));
tag.put("has_raids", new ByteTag((byte) 0));
tag.put("name", new StringTag("minecraft:the_nether"));
tag.put("logical_height", new IntTag(128));
tag.put("shrunk", new ByteTag((byte) 1));
tag.put("ultrawarm", new ByteTag((byte) 1));
tag.put("has_ceiling", new ByteTag((byte) 1));
return tag;
}
private static CompoundTag createEndEntry() {
CompoundTag tag = new CompoundTag();
tag.put("piglin_safe", new ByteTag((byte) 0));
tag.put("natural", new ByteTag((byte) 0));
tag.put("ambient_light", new FloatTag(0));
tag.put("infiniburn", new StringTag("minecraft:infiniburn_end"));
tag.put("respawn_anchor_works", new ByteTag((byte) 0));
tag.put("has_skylight", new ByteTag((byte) 0));
tag.put("bed_works", new ByteTag((byte) 0));
tag.put("fixed_time", new LongTag(6000));
tag.put("has_raids", new ByteTag((byte) 1));
tag.put("name", new StringTag("minecraft:the_end"));
tag.put("logical_height", new IntTag(256));
tag.put("shrunk", new ByteTag((byte) 0));
tag.put("ultrawarm", new ByteTag((byte) 0));
tag.put("has_ceiling", new ByteTag((byte) 0));
return tag;
}
public static void register(Protocol1_15_2To1_16 protocol) {
MetadataRewriter1_16To1_15_2 metadataRewriter = protocol.get(MetadataRewriter1_16To1_15_2.class);
@Override
protected void registerPackets() {
// Spawn lightning -> Spawn entity
protocol.registerClientbound(ClientboundPackets1_15.ADD_GLOBAL_ENTITY, ClientboundPackets1_16.ADD_ENTITY, wrapper -> {
int entityId = wrapper.passthrough(Types.VAR_INT);
@ -186,11 +104,11 @@ public class EntityPacketRewriter1_16 {
wrapper.write(Types.SHORT, (short) 0); // velocity
});
metadataRewriter.registerTrackerWithData(ClientboundPackets1_15.ADD_ENTITY, EntityTypes1_16.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets1_15.ADD_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_15.ADD_PLAYER, EntityTypes1_16.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_15.SET_ENTITY_DATA, Types1_14.METADATA_LIST, Types1_16.METADATA_LIST);
metadataRewriter.registerRemoveEntities(ClientboundPackets1_15.REMOVE_ENTITIES);
registerTrackerWithData(ClientboundPackets1_15.ADD_ENTITY, EntityTypes1_16.FALLING_BLOCK);
registerTracker(ClientboundPackets1_15.ADD_MOB);
registerTracker(ClientboundPackets1_15.ADD_PLAYER, EntityTypes1_16.PLAYER);
registerMetadataRewriter(ClientboundPackets1_15.SET_ENTITY_DATA, Types1_14.METADATA_LIST, Types1_16.METADATA_LIST);
registerRemoveEntities(ClientboundPackets1_15.REMOVE_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_15.RESPAWN, new PacketHandlers() {
@Override
@ -216,8 +134,8 @@ public class EntityPacketRewriter1_16 {
map(Types.UNSIGNED_BYTE); // Gamemode
handler(wrapper -> {
wrapper.write(Types.BYTE, (byte) -1); // Previous gamemode, set to none
wrapper.write(Types.STRING_ARRAY, Arrays.copyOf(WORLD_NAMES, WORLD_NAMES.length)); // World list - only used for command completion
wrapper.write(Types.NAMED_COMPOUND_TAG, DIMENSIONS_TAG.copy()); // Dimension registry
wrapper.write(Types.STRING_ARRAY, DimensionRegistries1_16.getWorldNames()); // World list - only used for command completion
wrapper.write(Types.NAMED_COMPOUND_TAG, DimensionRegistries1_16.getDimensionsTag()); // Dimension registry
});
handler(DIMENSION_HANDLER); // Dimension
map(Types.LONG); // Seed
@ -243,7 +161,7 @@ public class EntityPacketRewriter1_16 {
for (int i = 0; i < size; i++) {
// Attributes have been renamed and are now namespaced identifiers
String key = wrapper.read(Types.STRING);
String attributeIdentifier = AttributeMappings.attributeIdentifierMappings().get(key);
String attributeIdentifier = Attributes1_16.attributeIdentifierMappings().get(key);
if (attributeIdentifier == null) {
attributeIdentifier = Key.namespaced(key);
if (!Key.isValid(attributeIdentifier)) {
@ -285,4 +203,30 @@ public class EntityPacketRewriter1_16 {
}
});
}
@Override
protected void registerRewrites() {
filter().mapMetaType(Types1_16.META_TYPES::byId);
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.optionalBlockStateType, Types1_16.META_TYPES.particleType);
filter().type(EntityTypes1_16.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8);
filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> {
byte mask = meta.value();
int angerTime = (mask & 0x02) != 0 ? Integer.MAX_VALUE : 0;
event.createExtraMeta(new Metadata(20, Types1_16.META_TYPES.varIntType, angerTime));
});
}
@Override
public void onMappingDataLoaded() {
mapTypes();
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_16.getTypeFromId(type);
}
}

Datei anzeigen

@ -27,11 +27,10 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.Protocol1_15_2To1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.AttributeMappings;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.Attributes1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.storage.InventoryTracker1_16;
@ -240,8 +239,8 @@ public class ItemPacketRewriter1_16 extends ItemRewriter<ClientboundPackets1_15,
attributeName = Key.namespaced(attributeName);
}
String mappedAttribute = (inverse ? AttributeMappings.attributeIdentifierMappings().inverse()
: AttributeMappings.attributeIdentifierMappings()).get(attributeName);
String mappedAttribute = (inverse ? Attributes1_16.attributeIdentifierMappings().inverse()
: Attributes1_16.attributeIdentifierMappings()).get(attributeName);
if (mappedAttribute == null) return;
attributeNameTag.setValue(mappedAttribute);

Datei anzeigen

@ -21,16 +21,14 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.data.MappingData1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.metadata.MetadataRewriter1_16_2To1_16_1;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.EntityPacketRewriter1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ClientboundPackets1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ServerboundPackets1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.EntityPacketRewriter1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.ItemPacketRewriter1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.WorldPacketRewriter1_16_2;
import com.viaversion.viaversion.rewriter.SoundRewriter;
@ -40,7 +38,7 @@ import com.viaversion.viaversion.rewriter.TagRewriter;
public class Protocol1_16_1To1_16_2 extends AbstractProtocol<ClientboundPackets1_16, ClientboundPackets1_16_2, ServerboundPackets1_16, ServerboundPackets1_16_2> {
public static final MappingData1_16_2 MAPPINGS = new MappingData1_16_2();
private final MetadataRewriter1_16_2To1_16_1 metadataRewriter = new MetadataRewriter1_16_2To1_16_1(this);
private final EntityPacketRewriter1_16_2 entityRewriter = new EntityPacketRewriter1_16_2(this);
private final ItemPacketRewriter1_16_2 itemRewriter = new ItemPacketRewriter1_16_2(this);
private final TagRewriter<ClientboundPackets1_16> tagRewriter = new TagRewriter<>(this);
@ -52,7 +50,6 @@ public class Protocol1_16_1To1_16_2 extends AbstractProtocol<ClientboundPackets1
protected void registerPackets() {
super.registerPackets();
EntityPacketRewriter1_16_2.register(this);
WorldPacketRewriter1_16_2.register(this);
tagRewriter.register(ClientboundPackets1_16.UPDATE_TAGS, RegistryType.ENTITY);
@ -117,8 +114,8 @@ public class Protocol1_16_1To1_16_2 extends AbstractProtocol<ClientboundPackets1
}
@Override
public MetadataRewriter1_16_2To1_16_1 getEntityRewriter() {
return metadataRewriter;
public EntityPacketRewriter1_16_2 getEntityRewriter() {
return entityRewriter;
}
@Override

Datei anzeigen

@ -1,58 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* 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.viaversion.protocols.v1_16_1to1_16_2.metadata;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2;
import com.viaversion.viaversion.api.type.types.version.Types1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.Protocol1_16_1To1_16_2;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class MetadataRewriter1_16_2To1_16_1 extends EntityRewriter<ClientboundPackets1_16, Protocol1_16_1To1_16_2> {
public MetadataRewriter1_16_2To1_16_1(Protocol1_16_1To1_16_2 protocol) {
super(protocol);
}
@Override
protected void registerRewrites() {
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.optionalBlockStateType, Types1_16.META_TYPES.particleType);
filter().type(EntityTypes1_16_2.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).handler((metadatas, meta) -> {
if (meta.id() == 15) {
meta.setId(16);
} else if (meta.id() == 16) {
meta.setId(15);
}
});
}
@Override
public void onMappingDataLoaded() {
mapTypes();
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_16_2.getTypeFromId(type);
}
}

Datei anzeigen

@ -19,24 +19,28 @@ package com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.Protocol1_16_1To1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.metadata.MetadataRewriter1_16_2To1_16_1;
import com.viaversion.viaversion.rewriter.EntityRewriter;
public class EntityPacketRewriter1_16_2 {
public class EntityPacketRewriter1_16_2 extends EntityRewriter<ClientboundPackets1_16, Protocol1_16_1To1_16_2> {
public static void register(Protocol1_16_1To1_16_2 protocol) {
MetadataRewriter1_16_2To1_16_1 metadataRewriter = protocol.get(MetadataRewriter1_16_2To1_16_1.class);
metadataRewriter.registerTrackerWithData(ClientboundPackets1_16.ADD_ENTITY, EntityTypes1_16_2.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets1_16.ADD_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_16.ADD_PLAYER, EntityTypes1_16_2.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_16.SET_ENTITY_DATA, Types1_16.METADATA_LIST);
metadataRewriter.registerRemoveEntities(ClientboundPackets1_16.REMOVE_ENTITIES);
public EntityPacketRewriter1_16_2(Protocol1_16_1To1_16_2 protocol) {
super(protocol);
}
@Override
protected void registerPackets() {
registerTrackerWithData(ClientboundPackets1_16.ADD_ENTITY, EntityTypes1_16_2.FALLING_BLOCK);
registerTracker(ClientboundPackets1_16.ADD_MOB);
registerTracker(ClientboundPackets1_16.ADD_PLAYER, EntityTypes1_16_2.PLAYER);
registerMetadataRewriter(ClientboundPackets1_16.SET_ENTITY_DATA, Types1_16.METADATA_LIST);
registerRemoveEntities(ClientboundPackets1_16.REMOVE_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_16.LOGIN, new PacketHandlers() {
@Override
@ -62,7 +66,7 @@ public class EntityPacketRewriter1_16_2 {
map(Types.LONG); // Seed
map(Types.UNSIGNED_BYTE, Types.VAR_INT); // Max players
// ...
handler(metadataRewriter.playerTrackerHandler());
handler(playerTrackerHandler());
}
});
@ -72,7 +76,34 @@ public class EntityPacketRewriter1_16_2 {
});
}
public static CompoundTag getDimensionData(String dimensionType) {
@Override
protected void registerRewrites() {
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.optionalBlockStateType, Types1_16.META_TYPES.particleType);
filter().type(EntityTypes1_16_2.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).handler((metadatas, meta) -> {
if (meta.id() == 15) {
meta.setId(16);
} else if (meta.id() == 16) {
meta.setId(15);
}
});
}
@Override
public void onMappingDataLoaded() {
mapTypes();
}
@Override
public EntityType typeFromId(int type) {
return EntityTypes1_16_2.getTypeFromId(type);
}
private CompoundTag getDimensionData(String dimensionType) {
CompoundTag tag = Protocol1_16_1To1_16_2.MAPPINGS.getDimensionDataMap().get(dimensionType);
if (tag == null) {
Via.getPlatform().getLogger().severe("Could not get dimension data of " + dimensionType);

Datei anzeigen

@ -20,7 +20,7 @@ package com.viaversion.viaversion.protocols.v1_17_1to1_18.data;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
public final class BlockEntities {
public final class BlockEntities1_18 {
private static final Object2IntMap<String> BLOCK_ENTITY_IDS = new Object2IntOpenHashMap<>();
static {

Datei anzeigen

@ -20,7 +20,7 @@ package com.viaversion.viaversion.protocols.v1_17_1to1_18.data;
import com.viaversion.viaversion.api.Via;
import java.util.Arrays;
public final class BlockEntityIds {
public final class BlockEntityIds1_18 {
private static final int[] IDS = new int[14];

Datei anzeigen

@ -31,13 +31,12 @@ import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl;
import com.viaversion.viaversion.api.minecraft.chunks.DataPaletteImpl;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_17;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.protocols.v1_17_1to1_18.Protocol1_17_1To1_18;
import com.viaversion.viaversion.protocols.v1_17_1to1_18.data.BlockEntityIds;
import com.viaversion.viaversion.protocols.v1_17_1to1_18.data.BlockEntities;
import com.viaversion.viaversion.protocols.v1_17_1to1_18.data.BlockEntityIds1_18;
import com.viaversion.viaversion.protocols.v1_17_1to1_18.data.BlockEntities1_18;
import com.viaversion.viaversion.protocols.v1_17_1to1_18.packet.ClientboundPackets1_18;
import com.viaversion.viaversion.protocols.v1_17_1to1_18.storage.ChunkLightStorage;
import com.viaversion.viaversion.protocols.v1_17to1_17_1.packet.ClientboundPackets1_17_1;
@ -56,7 +55,7 @@ public final class WorldPacketRewriter1_18 {
map(Types.BLOCK_POSITION1_14);
handler(wrapper -> {
final short id = wrapper.read(Types.UNSIGNED_BYTE);
final int newId = BlockEntityIds.newId(id);
final int newId = BlockEntityIds1_18.newId(id);
wrapper.write(Types.VAR_INT, newId);
handleSpawners(newId, wrapper.passthrough(Types.NAMED_COMPOUND_TAG));
@ -118,7 +117,7 @@ public final class WorldPacketRewriter1_18 {
}
final String id = idTag.getValue();
final int typeId = BlockEntities.blockEntityIds().getInt(Key.stripMinecraftNamespace(id));
final int typeId = BlockEntities1_18.blockEntityIds().getInt(Key.stripMinecraftNamespace(id));
if (typeId == -1) {
Via.getPlatform().getLogger().warning("Unknown block entity: " + id);
}

Datei anzeigen

@ -26,7 +26,6 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_19;
@ -43,7 +42,7 @@ import com.viaversion.viaversion.protocols.v1_18_2to1_19.rewriter.EntityPacketRe
import com.viaversion.viaversion.protocols.v1_18_2to1_19.rewriter.ItemPacketRewriter1_19;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.rewriter.WorldPacketRewriter1_19;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.storage.DimensionRegistryStorage;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.storage.NonceStorage;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.storage.NonceStorage1_19;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.storage.SequenceStorage;
import com.viaversion.viaversion.rewriter.CommandRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter;
@ -249,7 +248,7 @@ public final class Protocol1_18_2To1_19 extends AbstractProtocol<ClientboundPack
handler(wrapper -> {
final byte[] publicKey = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE);
final byte[] nonce = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE);
wrapper.user().put(new NonceStorage(CipherUtil.encryptNonce(publicKey, nonce)));
wrapper.user().put(new NonceStorage1_19(CipherUtil.encryptNonce(publicKey, nonce)));
});
}
});
@ -272,7 +271,7 @@ public final class Protocol1_18_2To1_19 extends AbstractProtocol<ClientboundPack
wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE);
} else {
// 🧂
final NonceStorage nonceStorage = wrapper.user().remove(NonceStorage.class);
final NonceStorage1_19 nonceStorage = wrapper.user().remove(NonceStorage1_19.class);
if (nonceStorage == null) {
throw new IllegalArgumentException("Server sent nonce is missing");
}

Datei anzeigen

@ -27,7 +27,7 @@ public final class DimensionRegistryStorage implements StorableObject {
private Map<CompoundTag, String> dimensions;
public @Nullable String dimensionKey(final CompoundTag dimensionData) {
return dimensions.get(dimensionData); // HMMMMMMMMMMM
return dimensions.get(dimensionData);
}
public void setDimensions(final Map<CompoundTag, String> dimensions) {

Datei anzeigen

@ -19,5 +19,5 @@ package com.viaversion.viaversion.protocols.v1_18_2to1_19.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
public record NonceStorage(byte[] nonce) implements StorableObject {
public record NonceStorage1_19(byte[] nonce) implements StorableObject {
}

Datei anzeigen

@ -37,9 +37,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_19_3;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
@ -51,7 +49,7 @@ import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ClientboundPacke
import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ServerboundPackets1_19_1;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.rewriter.EntityPacketRewriter1_19_3;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.rewriter.ItemPacketRewriter1_19_3;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage.NonceStorage;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage.NonceStorage1_19_3;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage.ReceivedMessagesStorage;
import com.viaversion.viaversion.rewriter.CommandRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
@ -294,7 +292,7 @@ public final class Protocol1_19_1To1_19_3 extends AbstractProtocol<ClientboundPa
map(Types.BYTE_ARRAY_PRIMITIVE); // Public key
handler(wrapper -> {
if (wrapper.user().has(ChatSession1_19_1.class)) {
wrapper.user().put(new NonceStorage(wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE))); // Nonce
wrapper.user().put(new NonceStorage1_19_3(wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE))); // Nonce
}
});
}
@ -324,7 +322,7 @@ public final class Protocol1_19_1To1_19_3 extends AbstractProtocol<ClientboundPa
final byte[] signature;
try {
signature = chatSession.sign(signer -> {
signer.accept(wrapper.user().remove(NonceStorage.class).nonce());
signer.accept(wrapper.user().remove(NonceStorage1_19_3.class).nonce());
signer.accept(Longs.toByteArray(salt));
});
} catch (final SignatureException e) {

Datei anzeigen

@ -20,5 +20,5 @@ package com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
import org.checkerframework.checker.nullness.qual.Nullable;
public record NonceStorage(byte @Nullable[] nonce) implements StorableObject {
public record NonceStorage1_19_3(byte @Nullable[] nonce) implements StorableObject {
}

Datei anzeigen

@ -34,18 +34,17 @@ import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ClientboundPackets1_19;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ServerboundPackets1_19;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.data.ChatDecorationResult;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.data.ChatRegistry;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.data.ChatRegistry1_19_1;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ClientboundPackets1_19_1;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ServerboundPackets1_19_1;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.storage.ChatTypeStorage;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.storage.NonceStorage;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.storage.NonceStorage1_19_1;
import com.viaversion.viaversion.util.CipherUtil;
import com.viaversion.viaversion.util.Pair;
import com.viaversion.viaversion.util.TagUtil;
@ -211,7 +210,7 @@ public final class Protocol1_19To1_19_1 extends AbstractProtocol<ClientboundPack
}
// Replace chat types - they won't actually be used
registry.put("minecraft:chat_type", ChatRegistry.chatRegistry());
registry.put("minecraft:chat_type", ChatRegistry1_19_1.chatRegistry());
});
}
});
@ -238,7 +237,7 @@ public final class Protocol1_19To1_19_1 extends AbstractProtocol<ClientboundPack
if (profileKey == null || chatSession != null) {
// Modified client that doesn't include the profile key, or already done in 1.18->1.19 protocol; no need to map it
wrapper.user().put(new NonceStorage(null));
wrapper.user().put(new NonceStorage1_19_1(null));
}
});
read(Types.OPTIONAL_UUID); // Profile uuid
@ -249,13 +248,13 @@ public final class Protocol1_19To1_19_1 extends AbstractProtocol<ClientboundPack
public void register() {
map(Types.STRING); // Server id
handler(wrapper -> {
if (wrapper.user().has(NonceStorage.class)) {
if (wrapper.user().has(NonceStorage1_19_1.class)) {
return;
}
final byte[] publicKey = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE);
final byte[] nonce = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE);
wrapper.user().put(new NonceStorage(CipherUtil.encryptNonce(publicKey, nonce)));
wrapper.user().put(new NonceStorage1_19_1(CipherUtil.encryptNonce(publicKey, nonce)));
});
}
});
@ -264,7 +263,7 @@ public final class Protocol1_19To1_19_1 extends AbstractProtocol<ClientboundPack
public void register() {
map(Types.BYTE_ARRAY_PRIMITIVE); // Keys
handler(wrapper -> {
final NonceStorage nonceStorage = wrapper.user().remove(NonceStorage.class);
final NonceStorage1_19_1 nonceStorage = wrapper.user().remove(NonceStorage1_19_1.class);
if (nonceStorage.nonce() == null) {
return;
}

Datei anzeigen

@ -20,7 +20,7 @@ package com.viaversion.viaversion.protocols.v1_19to1_19_1.data;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.data.MappingDataLoader;
public class ChatRegistry {
public class ChatRegistry1_19_1 {
private static final CompoundTag chatRegistry;

Datei anzeigen

@ -20,6 +20,6 @@ package com.viaversion.viaversion.protocols.v1_19to1_19_1.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
import org.checkerframework.checker.nullness.qual.Nullable;
public record NonceStorage(byte @Nullable [] nonce) implements StorableObject {
public record NonceStorage1_19_1(byte @Nullable [] nonce) implements StorableObject {
}