Compare commits

..
43 Commits
Author SHA1 Message Date
Nassim Jahnke 79a2881a02 4.9.2 Release 2024-03-05 17:51:04 +01:00
Nassim Jahnke 64e68830bc Create FUNDING.yml 2024-03-04 17:32:32 +01:00
EnZaXD ab742c794f Update description included in platforms (#694) 2024-03-04 17:26:59 +01:00
EnZaXD bf3834ab21 Tidy up fabric.mod.json file of fabric platform (#695) 2024-02-29 12:25:31 +01:00
EnZaXD 2f60c79ed8 Use equals for legacy custom payload channel handlers (#693) 2024-02-29 12:09:50 +01:00
EnZaXD 5bb3e8a1fc paste.gg -> mclo.gs (#689) 2024-02-21 16:13:12 +01:00
Nassim Jahnke b60464296b Small cleanups 2024-02-12 11:02:55 +01:00
Nassim Jahnke 9241213fb5 Replace tag instanceof/unchecked casts with helper methods 2024-02-11 10:42:44 +01:00
Nassim Jahnke e9c3889c82 Add editorconfig 2024-02-11 10:39:06 +01:00
EnZaXD dca8ecf1db Fix notes color from note block being wrong in 1.13->1.12 (#680)
Closes https://github.com/ViaVersion/ViaBackwards/issues/679
2024-02-01 16:28:40 +01:00
Nassim Jahnke 170e5f224f Fix writable book handling in 1.16->1.15 2024-01-31 22:58:11 +01:00
EnZaXD 4375a259dd Fix 1.17.1 -> 1.18 mappings loading (#676)
Closes https://github.com/ViaVersion/ViaBackwards/issues/568
2024-01-29 20:30:59 +01:00
Nassim Jahnke 8fc82cd331 Update book conversion error logging 2024-01-29 17:33:08 +01:00
EnZaXD de21548a8e Clean up more item type usage in ItemRewriter (#675) 2024-01-29 17:29:17 +01:00
Nassim Jahnke 8759f059b7 Ignore errors in book conversion 2024-01-29 10:17:50 +01:00
Nassim Jahnke 1f3555df4a Put books through component conversion in 1.20.3->1.20.2 2024-01-27 21:04:32 +01:00
Kichura b40f77fed3 Update JDK to 17, setup-java to v4 (#671) 2024-01-20 21:19:36 +01:00
Kichura 9fd0df824f Update supported Velocity version to 3.3 (#666) 2024-01-14 10:02:16 +01:00
Nassim Jahnke 88df61605b Update VV usage 2024-01-09 20:59:26 +01:00
Nassim Jahnke 6c2d43d7f9 Handle 1.20->1.20.2 tags 2024-01-09 17:19:19 +01:00
Nassim Jahnke 2889daed61 Update license header 2024-01-01 12:38:33 +01:00
Nassim Jahnke 651bf052fc Update ViaNBT 2023-12-31 14:04:57 +01:00
Nassim Jahnke 83fa0c613f Update copyright profile 2023-12-27 17:51:16 +01:00
Nassim Jahnke 5334f77d49 Finish up things 2023-12-27 17:30:47 +01:00
Nassim Jahnke 96293e6e66 Start working on mcstructs usage (missing TranslatableRewriter1_16) 2023-12-27 00:24:56 +01:00
Nassim Jahnke 65faeb8574 Fix 1.20.3->1.20.2 configuration resource pack id 2023-12-26 21:49:34 +01:00
Nassim Jahnke 6ad4a29d30 Allow specifying unmapped data in legacy mappings 2023-12-20 12:10:15 +01:00
Nassim Jahnke 4fe53f5ab8 Update the bane of my existence 2023-12-13 22:45:23 +01:00
Nassim Jahnke a390990178 Read correct method type in update score
Fixes #650
2023-12-13 12:04:43 +01:00
Nassim Jahnke e020dd69ef Fix tab complete tooltip reading in old versions
Fixes #648
2023-12-11 11:27:52 +01:00
Nassim Jahnke b09950dc64 Update Via usage 2023-12-10 12:15:35 +01:00
Nassim Jahnke 7b8fd2b061 Fix 1.17->1.16 map data type reading
Fixes #646
2023-12-09 14:59:43 +01:00
Nassim Jahnke 2d57e8c212 Clone tag instead of abusing tag conversion 2023-12-08 21:06:30 +01:00
Camden Cove dcc3824a8c Fix 1.13.1->1.13 item type in some cases (#645) 2023-12-08 12:05:52 +01:00
EnZaXD 2dd19c778b Handle chunk loading game state in 1.20.3 -> 1.20.2 (#643) 2023-12-08 09:37:20 +01:00
Nassim Jahnke e24a170e77 Fix reset score reading 2023-12-07 23:17:55 +01:00
Nassim Jahnke 3a69dda548 Bump version to 4.9.2-SNAPSHOT 2023-12-07 23:17:36 +01:00
Nassim Jahnke 77ecda3977 4.9.1 Release 2023-12-07 11:19:36 +01:00
Nassim Jahnke c44bc88d2d Convert chat type in disguised chat packet 2023-12-07 10:11:18 +01:00
Nassim Jahnke deede5347e Fix 1.13 map data type
Fixes #641
2023-12-07 09:54:30 +01:00
Nassim Jahnke 255536e9d0 Handle tags packet 2023-12-06 09:47:11 +01:00
Nassim Jahnke 8a2c18863c Fix map marker reading 2023-12-05 22:23:48 +01:00
Nassim Jahnke 375bb5a1b9 Bump version to 4.9.1-SNAPSHOT 2023-12-05 22:18:32 +01:00
213 changed files with 1349 additions and 1298 deletions

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
[*]
charset = utf-8
indent_size = 4
indent_style = space
insert_final_newline = false
tab_width = 4
[*.java]
ij_java_class_count_to_use_import_on_demand = 999999
ij_java_names_count_to_use_import_on_demand = 999999
ij_java_imports_layout = *,|,$*
ij_java_generate_final_locals = true
ij_java_generate_final_parameters = true
+2
View File
@@ -0,0 +1,2 @@
github: kennytv
patreon: kennytv
+2 -2
View File
@@ -21,11 +21,11 @@ body:
attributes:
label: Console Error
description: |
If you encounter warnings/errors in your console, **paste them with https://paste.gg/ and put the paste link here**.
If you encounter warnings/errors in your console, **paste them with https://mclo.gs/ and put the paste link here**.
If the error is small/less than 10 lines, you may put it directly into this field.
value: |
```
Put the paste.gg link or text here.
Put the mclo.gs link or text here.
```
placeholder: Please do not remove the grave accents; simply replace the line of text in the middle.
validations:
+3 -3
View File
@@ -13,11 +13,11 @@ jobs:
uses: actions/checkout@v4
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 11
java-version: 17
check-latest: true
- name: Build with Gradle
run: ./gradlew build
+1 -1
View File
@@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
+1 -1
View File
@@ -1,6 +1,6 @@
<component name="CopyrightManager">
<copyright>
<option name="notice" value="This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards&#10;Copyright (C) &amp;#36;originalComment.match(&quot;Copyright \(C\) (\d+)&quot;, 1, &quot;-&quot;)&amp;#36;today.year ViaVersion and contributors&#10;&#10;This program is free software: you can redistribute it and/or modify&#10;it under the terms of the GNU General Public License as published by&#10;the Free Software Foundation, either version 3 of the License, or&#10;(at your option) any later version.&#10;&#10;This program is distributed in the hope that it will be useful,&#10;but WITHOUT ANY WARRANTY; without even the implied warranty of&#10;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the&#10;GNU General Public License for more details.&#10;&#10;You should have received a copy of the GNU General Public License&#10;along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;." />
<option name="notice" value="This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards&#10;Copyright (C) 2016-&amp;#36;today.year ViaVersion and contributors&#10;&#10;This program is free software: you can redistribute it and/or modify&#10;it under the terms of the GNU General Public License as published by&#10;the Free Software Foundation, either version 3 of the License, or&#10;(at your option) any later version.&#10;&#10;This program is distributed in the hope that it will be useful,&#10;but WITHOUT ANY WARRANTY; without even the implied warranty of&#10;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the&#10;GNU General Public License for more details.&#10;&#10;You should have received a copy of the GNU General Public License&#10;along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;." />
<option name="myName" value="viabackwards-gpl" />
</copyright>
</component>
+1 -1
View File
@@ -6,7 +6,7 @@ plugins {
allprojects {
group = "com.viaversion"
version = property("projectVersion") as String // from gradle.properties
description = "Allow older clients to join newer server versions."
description = "Allows older Minecraft client versions to connect to newer server versions."
}
val main = setOf(
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -53,6 +53,7 @@ public class LecternInteractListener extends ViaBukkitListener {
// Open a book with the text of the lectern's writable book
ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
BookMeta newBookMeta = (BookMeta) newBook.getItemMeta();
//noinspection deprecation
newBookMeta.setPages(meta.getPages());
newBookMeta.setAuthor("an upsidedown person");
newBookMeta.setTitle("buk");
@@ -1,7 +1,7 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
+1 -1
View File
@@ -1,6 +1,6 @@
name: ViaBackwards
version: ${version}
description: Allow older Minecraft versions to connect to a newer server version.
description: ${description}
main: com.viaversion.viabackwards.BukkitPlugin
api-version: 1.13
folia-supported: true
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -27,7 +27,7 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import org.checkerframework.checker.nullness.qual.Nullable;
public abstract class BackwardsProtocol<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType>
extends AbstractProtocol<CU, CM, SM, SU> {
extends AbstractProtocol<CU, CM, SM, SU> {
protected BackwardsProtocol() {
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -67,7 +67,7 @@ import java.util.logging.Logger;
public interface ViaBackwardsPlatform {
String MINIMUM_VV_VERSION = "4.9.0";
String MINIMUM_VV_VERSION = "4.9.3";
/**
* Initialize ViaBackwards.
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -17,7 +17,7 @@
*/
package com.viaversion.viabackwards.api.data;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import org.checkerframework.checker.nullness.qual.Nullable;
public class MappedItem {
@@ -32,7 +32,7 @@ public class MappedItem {
public MappedItem(final int id, final String name, @Nullable final Integer customModelData) {
this.id = id;
this.jsonName = ChatRewriter.legacyTextToJsonString("§f" + name, true);
this.jsonName = ComponentUtil.legacyToJsonString("§f" + name, true);
this.customModelData = customModelData;
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -21,9 +21,10 @@ import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viaversion.libs.gson.JsonIOException;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.gson.JsonSyntaxException;
import com.viaversion.viaversion.libs.opennbt.NBTIO;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.libs.opennbt.tag.io.NBTIO;
import com.viaversion.viaversion.libs.opennbt.tag.io.TagReader;
import com.viaversion.viaversion.util.GsonUtil;
import java.io.File;
import java.io.FileReader;
@@ -35,6 +36,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class VBMappingDataLoader {
private static final TagReader<CompoundTag> TAG_READER = NBTIO.reader(CompoundTag.class).named();
public static @Nullable CompoundTag loadNBT(final String name) {
final InputStream resource = getResource(name);
if (resource == null) {
@@ -42,7 +45,7 @@ public final class VBMappingDataLoader {
}
try (final InputStream stream = resource) {
return NBTIO.readTag(stream);
return TAG_READER.read(stream);
} catch (final IOException e) {
throw new RuntimeException(e);
}
@@ -65,7 +68,7 @@ public final class VBMappingDataLoader {
ViaBackwards.getPlatform().getLogger().info("Loading " + name + " from plugin folder");
try {
final CompoundTag fileData = NBTIO.readFile(file, false, false);
final CompoundTag fileData = TAG_READER.read(file.toPath(), false);
return mergeTags(packedData, fileData);
} catch (final IOException e) {
throw new RuntimeException(e);
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -18,11 +18,10 @@
package com.viaversion.viabackwards.api.entities.storage;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -87,7 +86,7 @@ public class EntityData {
}
if (componentType == ComponentType.JSON) {
return ChatRewriter.legacyTextToJson(name);
return ComponentUtil.legacyToJson(name);
} else if (componentType == ComponentType.TAG) {
return new StringTag(name);
}
@@ -113,11 +112,11 @@ public class EntityData {
@Override
public String toString() {
return "EntityData{" +
"id=" + id +
", mobName='" + key + '\'' +
", replacementId=" + replacementId +
", defaultMeta=" + defaultMeta +
'}';
"id=" + id +
", mobName='" + key + '\'' +
", replacementId=" + replacementId +
", defaultMeta=" + defaultMeta +
'}';
}
@FunctionalInterface
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -43,7 +43,7 @@ public class EntityPositionHandler {
public void cacheEntityPosition(PacketWrapper wrapper, boolean create, boolean relative) throws Exception {
cacheEntityPosition(wrapper,
wrapper.get(Type.DOUBLE, 0), wrapper.get(Type.DOUBLE, 1), wrapper.get(Type.DOUBLE, 2), create, relative);
wrapper.get(Type.DOUBLE, 0), wrapper.get(Type.DOUBLE, 1), wrapper.get(Type.DOUBLE, 2), create, relative);
}
public void cacheEntityPosition(PacketWrapper wrapper, double x, double y, double z, boolean create, boolean relative) throws Exception {
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,34 +0,0 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.api.exceptions;
import java.io.IOException;
public class RemovedValueException extends IOException {
/**
* May be cached since it is never actually printed, only checked.
*/
public static final RemovedValueException EX = new RemovedValueException() {
@Override
public Throwable fillInStackTrace() {
return this;
}
};
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -21,10 +21,9 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -57,10 +56,10 @@ public class EnchantmentRewriter {
CompoundTag tag = item.tag();
if (tag == null) return;
if (tag.get("Enchantments") instanceof ListTag) {
if (tag.getListTag("Enchantments") != null) {
rewriteEnchantmentsToClient(tag, false);
}
if (tag.get("StoredEnchantments") instanceof ListTag) {
if (tag.getListTag("StoredEnchantments") != null) {
rewriteEnchantmentsToClient(tag, true);
}
}
@@ -79,17 +78,16 @@ public class EnchantmentRewriter {
public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "Enchantments";
ListTag enchantments = tag.get(key);
ListTag enchantments = tag.getListTag(key);
List<Tag> loreToAdd = new ArrayList<>();
boolean changed = false;
Iterator<Tag> iterator = enchantments.iterator();
while (iterator.hasNext()) {
CompoundTag enchantmentEntry = (CompoundTag) iterator.next();
Tag idTag = enchantmentEntry.get("id");
if (!(idTag instanceof StringTag)) continue;
StringTag idTag = enchantmentEntry.getStringTag("id");
String enchantmentId = ((StringTag) idTag).getValue();
String enchantmentId = idTag.getValue();
String remappedName = enchantmentMappings.get(enchantmentId);
if (remappedName != null) {
if (!changed) {
@@ -100,10 +98,11 @@ public class EnchantmentRewriter {
iterator.remove();
int level = ((NumberTag) enchantmentEntry.get("lvl")).asInt();
NumberTag levelTag = enchantmentEntry.getNumberTag("lvl");
int level = levelTag != null ? levelTag.asInt() : 1;
String loreValue = remappedName + " " + getRomanNumber(level);
if (jsonFormat) {
loreValue = ChatRewriter.legacyTextToJsonString(loreValue);
loreValue = ComponentUtil.legacyToJsonString(loreValue);
}
loreToAdd.add(new StringTag(loreValue));
@@ -112,19 +111,19 @@ public class EnchantmentRewriter {
if (!loreToAdd.isEmpty()) {
// Add dummy enchant for the glow effect if there are no actual enchantments left
if (!storedEnchant && enchantments.size() == 0) {
if (!storedEnchant && enchantments.isEmpty()) {
CompoundTag dummyEnchantment = new CompoundTag();
dummyEnchantment.put("id", new StringTag());
dummyEnchantment.put("lvl", new ShortTag((short) 0));
dummyEnchantment.putString("id", "");
dummyEnchantment.putShort("lvl", (short) 0);
enchantments.add(dummyEnchantment);
}
CompoundTag display = tag.get("display");
CompoundTag display = tag.getCompoundTag("display");
if (display == null) {
tag.put("display", display = new CompoundTag());
}
ListTag loreTag = display.get("Lore");
ListTag loreTag = display.getListTag("Lore");
if (loreTag == null) {
display.put("Lore", loreTag = new ListTag(StringTag.class));
} else {
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -177,12 +177,12 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
}
public void registerMetaTypeHandler(
@Nullable MetaType itemType,
@Nullable MetaType blockStateType,
@Nullable MetaType optionalBlockStateType,
@Nullable MetaType particleType,
@Nullable MetaType componentType,
@Nullable MetaType optionalComponentType
@Nullable MetaType itemType,
@Nullable MetaType blockStateType,
@Nullable MetaType optionalBlockStateType,
@Nullable MetaType particleType,
@Nullable MetaType componentType,
@Nullable MetaType optionalComponentType
) {
filter().handler((event, meta) -> {
MetaType type = meta.metaType();
@@ -199,6 +199,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
} else if (type == particleType) {
rewriteParticle(meta.value());
} else if (type == optionalComponentType || type == componentType) {
JsonElement text = meta.value();
if (text != null) {
protocol.getTranslatableRewriter().processText(text);
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -29,16 +29,13 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {
public ItemRewriter(T protocol) {
super(protocol, true);
}
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType) {
super(protocol, itemType, itemArrayType, true);
@@ -50,25 +47,23 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
return null;
}
CompoundTag display = item.tag() != null ? item.tag().get("display") : null;
CompoundTag display = item.tag() != null ? item.tag().getCompoundTag("display") : null;
if (protocol.getTranslatableRewriter() != null && display != null) {
// Handle name and lore components
Tag name = display.get("Name");
if (name instanceof StringTag) {
StringTag nameStringTag = (StringTag) name;
String newValue = protocol.getTranslatableRewriter().processText(nameStringTag.getValue()).toString();
StringTag name = display.getStringTag("Name");
if (name != null) {
String newValue = protocol.getTranslatableRewriter().processText(name.getValue()).toString();
if (!newValue.equals(name.getValue())) {
saveStringTag(display, nameStringTag, "Name");
saveStringTag(display, name, "Name");
}
nameStringTag.setValue(newValue);
name.setValue(newValue);
}
Tag lore = display.get("Lore");
if (lore instanceof ListTag) {
ListTag loreListTag = (ListTag) lore;
ListTag lore = display.getListTag("Lore");
if (lore != null) {
boolean changed = false;
for (Tag loreEntryTag : loreListTag) {
for (Tag loreEntryTag : lore) {
if (!(loreEntryTag instanceof StringTag)) {
continue;
}
@@ -78,7 +73,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
if (!changed && !newValue.equals(loreEntry.getValue())) {
// Backup original lore before doing any modifications
changed = true;
saveListTag(display, loreListTag, "Lore");
saveListTag(display, lore, "Lore");
}
loreEntry.setValue(newValue);
@@ -97,12 +92,12 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
}
// Save original id, set remapped id
item.tag().put(nbtTagName + "|id", new IntTag(item.identifier()));
item.tag().putInt(nbtTagName + "|id", item.identifier());
item.setIdentifier(data.getId());
// Add custom model data
if (data.customModelData() != null && !item.tag().contains("CustomModelData")) {
item.tag().put("CustomModelData", new IntTag(data.customModelData()));
item.tag().putInt("CustomModelData", data.customModelData());
}
// Set custom name - only done if there is no original one
@@ -122,16 +117,16 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
super.handleItemToServer(item);
if (item.tag() != null) {
IntTag originalId = item.tag().remove(nbtTagName + "|id");
if (originalId != null) {
item.setIdentifier(originalId.asInt());
Tag originalId = item.tag().remove(nbtTagName + "|id");
if (originalId instanceof IntTag) {
item.setIdentifier(((NumberTag) originalId).asInt());
}
}
return item;
}
@Override
public void registerAdvancements(C packetType, Type<Item> type) {
public void registerAdvancements(C packetType) {
protocol.registerClientbound(packetType, new PacketHandlers() {
@Override
public void register() {
@@ -156,7 +151,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
translatableRewriter.processText(description);
}
handleItemToClient(wrapper.passthrough(type)); // Icon
handleItemToClient(wrapper.passthrough(getItemType())); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) {
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -30,16 +30,12 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extends ServerboundPacketType,
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriter<C, S, T> {
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriter<C, S, T> {
protected final String nbtTagName;
protected final boolean jsonNameFormat;
protected ItemRewriterBase(T protocol, boolean jsonNameFormat) {
this(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY, jsonNameFormat);
}
public ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, boolean jsonNameFormat) {
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, boolean jsonNameFormat) {
super(protocol, itemType, itemArrayType);
this.jsonNameFormat = jsonNameFormat;
nbtTagName = "VB|" + protocol.getClass().getSimpleName();
@@ -62,7 +58,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
// Multiple places might try to backup data
String backupName = nbtTagName + "|o" + name;
if (!displayTag.contains(backupName)) {
displayTag.put(backupName, new StringTag(original.getValue()));
displayTag.putString(backupName, original.getValue());
}
}
@@ -73,7 +69,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
// Clone all tag entries
ListTag listTag = new ListTag();
for (Tag tag : original.getValue()) {
listTag.add(tag.clone());
listTag.add(tag.copy());
}
displayTag.put(backupName, listTag);
@@ -83,7 +79,7 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
protected void restoreDisplayTag(Item item) {
if (item.tag() == null) return;
CompoundTag display = item.tag().get("display");
CompoundTag display = item.tag().getCompoundTag("display");
if (display != null) {
// Remove custom name / restore original name
if (display.remove(nbtTagName + "|customName") != null) {
@@ -98,16 +94,16 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
}
protected void restoreStringTag(CompoundTag tag, String tagName) {
StringTag original = tag.remove(nbtTagName + "|o" + tagName);
if (original != null) {
tag.put(tagName, new StringTag(original.getValue()));
Tag original = tag.remove(nbtTagName + "|o" + tagName);
if (original instanceof StringTag) {
tag.putString(tagName, ((StringTag) original).getValue());
}
}
protected void restoreListTag(CompoundTag tag, String tagName) {
ListTag original = tag.remove(nbtTagName + "|o" + tagName);
if (original != null) {
tag.put(tagName, new ListTag(original.getValue()));
Tag original = tag.remove(nbtTagName + "|o" + tagName);
if (original instanceof ListTag) {
tag.put(tagName, new ListTag(((ListTag) original).getValue()));
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -30,6 +30,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import com.viaversion.viaversion.libs.gson.JsonElement;
@@ -37,20 +38,18 @@ import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {
private static final Map<String, Int2ObjectMap<MappedLegacyBlockItem>> LEGACY_MAPPINGS = new HashMap<>();
protected final Int2ObjectMap<MappedLegacyBlockItem> replacementData;
protected final Int2ObjectMap<MappedLegacyBlockItem> replacementData; // Raw id -> mapped data
static {
JsonObject jsonObject = VBMappingDataLoader.loadFromDataDir("legacy-mappings.json");
@@ -58,40 +57,55 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
Int2ObjectMap<MappedLegacyBlockItem> mappings = new Int2ObjectOpenHashMap<>(8);
LEGACY_MAPPINGS.put(entry.getKey(), mappings);
for (Map.Entry<String, JsonElement> dataEntry : entry.getValue().getAsJsonObject().entrySet()) {
JsonObject object = dataEntry.getValue().getAsJsonObject();
int id = object.getAsJsonPrimitive("id").getAsInt();
JsonPrimitive jsonData = object.getAsJsonPrimitive("data");
short data = jsonData != null ? jsonData.getAsShort() : 0;
String name = object.getAsJsonPrimitive("name").getAsString();
JsonPrimitive blockField = object.getAsJsonPrimitive("block");
boolean block = blockField != null && blockField.getAsBoolean();
addMapping(dataEntry.getKey(), dataEntry.getValue().getAsJsonObject(), mappings);
}
}
}
if (dataEntry.getKey().indexOf('-') != -1) {
// Range of ids
String[] split = dataEntry.getKey().split("-", 2);
int from = Integer.parseInt(split[0]);
int to = Integer.parseInt(split[1]);
private static void addMapping(String key, JsonObject object, Int2ObjectMap<MappedLegacyBlockItem> mappings) {
int id = object.getAsJsonPrimitive("id").getAsInt();
JsonPrimitive jsonData = object.getAsJsonPrimitive("data");
short data = jsonData != null ? jsonData.getAsShort() : 0;
String name = object.getAsJsonPrimitive("name").getAsString();
JsonPrimitive blockField = object.getAsJsonPrimitive("block");
boolean block = blockField != null && blockField.getAsBoolean();
// Special block color handling
if (name.contains("%color%")) {
for (int i = from; i <= to; i++) {
mappings.put(i, new MappedLegacyBlockItem(id, data, name.replace("%color%", BlockColors.get(i - from)), block));
}
} else {
MappedLegacyBlockItem mappedBlockItem = new MappedLegacyBlockItem(id, data, name, block);
for (int i = from; i <= to; i++) {
mappings.put(i, mappedBlockItem);
}
}
} else {
mappings.put(Integer.parseInt(dataEntry.getKey()), new MappedLegacyBlockItem(id, data, name, block));
}
if (key.indexOf('-') == -1) {
int unmappedId;
int dataSeparatorIndex = key.indexOf(':');
if (dataSeparatorIndex != -1) {
// Include data
short unmappedData = Short.parseShort(key.substring(dataSeparatorIndex + 1));
unmappedId = Integer.parseInt(key.substring(0, dataSeparatorIndex));
unmappedId = (unmappedId << 4) | (unmappedData & 15);
} else {
unmappedId = Integer.parseInt(key) << 4;
}
mappings.put(unmappedId, new MappedLegacyBlockItem(id, data, name, block));
return;
}
// Range of ids
String[] split = key.split("-", 2);
int from = Integer.parseInt(split[0]);
int to = Integer.parseInt(split[1]);
// Special block color handling
if (name.contains("%color%")) {
for (int i = from; i <= to; i++) {
mappings.put(i << 4, new MappedLegacyBlockItem(id, data, name.replace("%color%", BlockColors.get(i - from)), block));
}
} else {
MappedLegacyBlockItem mappedBlockItem = new MappedLegacyBlockItem(id, data, name, block);
for (int i = from; i <= to; i++) {
mappings.put(i << 4, mappedBlockItem);
}
}
}
protected LegacyBlockItemRewriter(T protocol) {
super(protocol, false);
super(protocol, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY, false);
replacementData = LEGACY_MAPPINGS.get(protocol.getClass().getSimpleName().split("To")[1].replace("_", "."));
}
@@ -99,7 +113,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
public @Nullable Item handleItemToClient(@Nullable Item item) {
if (item == null) return null;
MappedLegacyBlockItem data = replacementData.get(item.identifier());
MappedLegacyBlockItem data = getMappedBlockItem(item.identifier(), item.data());
if (data == null) {
// Just rewrite the id
return super.handleItemToClient(item);
@@ -118,21 +132,22 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
item.setTag(new CompoundTag());
}
CompoundTag display = item.tag().get("display");
CompoundTag display = item.tag().getCompoundTag("display");
if (display == null) {
item.tag().put("display", display = new CompoundTag());
}
StringTag nameTag = display.get("Name");
StringTag nameTag = display.getStringTag("Name");
if (nameTag == null) {
display.put("Name", nameTag = new StringTag(data.getName()));
nameTag = new StringTag(data.getName());
display.put("Name", nameTag);
display.put(nbtTagName + "|customName", new ByteTag());
}
// Handle colors
String value = nameTag.getValue();
if (value.contains("%vb_color%")) {
display.put("Name", new StringTag(value.replace("%vb_color%", BlockColors.get(originalData))));
display.putString("Name", value.replace("%vb_color%", BlockColors.get(originalData)));
}
}
return item;
@@ -149,7 +164,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
}
public @Nullable Block handleBlock(int blockId, int data) {
MappedLegacyBlockItem settings = replacementData.get(blockId);
MappedLegacyBlockItem settings = getMappedBlockItem(blockId, data);
if (settings == null || !settings.isBlock()) return null;
Block block = settings.getBlock();
@@ -160,21 +175,30 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
return block;
}
private @Nullable MappedLegacyBlockItem getMappedBlockItem(int id, int data) {
MappedLegacyBlockItem mapping = replacementData.get((id << 4) | (data & 15));
return mapping != null || data == 0 ? mapping : replacementData.get(id << 4);
}
private @Nullable MappedLegacyBlockItem getMappedBlockItem(int rawId) {
MappedLegacyBlockItem mapping = replacementData.get(rawId);
return mapping != null ? mapping : replacementData.get(rawId & ~15);
}
protected void handleChunk(Chunk chunk) {
// Map Block Entities
Map<Pos, CompoundTag> tags = new HashMap<>();
for (CompoundTag tag : chunk.getBlockEntities()) {
Tag xTag;
Tag yTag;
Tag zTag;
if ((xTag = tag.get("x")) == null || (yTag = tag.get("y")) == null || (zTag = tag.get("z")) == null) {
NumberTag xTag;
NumberTag yTag;
NumberTag zTag;
if ((xTag = tag.getNumberTag("x")) == null
|| (yTag = tag.getNumberTag("y")) == null
|| (zTag = tag.getNumberTag("z")) == null) {
continue;
}
Pos pos = new Pos(
((NumberTag) xTag).asInt() & 0xF,
((NumberTag) yTag).asInt(),
((NumberTag) zTag).asInt() & 0xF);
Pos pos = new Pos(xTag.asInt() & 0xF, yTag.asInt(), zTag.asInt() & 0xF);
tags.put(pos, tag);
// Handle given Block Entities
@@ -184,9 +208,8 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
if (section == null) continue;
int block = section.palette(PaletteType.BLOCKS).idAt(pos.getX(), pos.getY() & 0xF, pos.getZ());
int btype = block >> 4;
MappedLegacyBlockItem settings = replacementData.get(btype);
MappedLegacyBlockItem settings = getMappedBlockItem(block);
if (settings != null && settings.hasBlockEntityHandler()) {
settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
}
@@ -215,7 +238,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
// We already know that is has a handler
if (hasBlockEntityHandler) continue;
MappedLegacyBlockItem settings = replacementData.get(btype);
MappedLegacyBlockItem settings = getMappedBlockItem(block);
if (settings != null && settings.hasBlockEntityHandler()) {
hasBlockEntityHandler = true;
}
@@ -228,10 +251,8 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
int block = palette.idAt(x, y, z);
int btype = block >> 4;
int meta = block & 15;
MappedLegacyBlockItem settings = replacementData.get(btype);
MappedLegacyBlockItem settings = getMappedBlockItem(block);
if (settings == null || !settings.hasBlockEntityHandler()) continue;
Pos pos = new Pos(x, (y + (i << 4)), z);
@@ -240,9 +261,9 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
if (tags.containsKey(pos)) continue;
CompoundTag tag = new CompoundTag();
tag.put("x", new IntTag(x + (chunk.getX() << 4)));
tag.put("y", new IntTag(y + (i << 4)));
tag.put("z", new IntTag(z + (chunk.getZ() << 4)));
tag.putInt("x", x + (chunk.getX() << 4));
tag.putInt("y", y + (i << 4));
tag.putInt("z", z + (chunk.getZ() << 4));
settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
chunk.getBlockEntities().add(tag);
@@ -254,9 +275,10 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
protected CompoundTag getNamedTag(String text) {
CompoundTag tag = new CompoundTag();
tag.put("display", new CompoundTag());
CompoundTag displayTag = new CompoundTag();
tag.put("display", displayTag);
text = "§r" + text;
((CompoundTag) tag.get("display")).put("Name", new StringTag(jsonNameFormat ? ChatRewriter.legacyTextToJsonString(text) : text));
displayTag.putString("Name", jsonNameFormat ? ComponentUtil.legacyToJsonString(text) : text);
return tag;
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -22,7 +22,6 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import java.util.ArrayList;
@@ -48,18 +47,24 @@ public class LegacyEnchantmentRewriter {
public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "ench";
ListTag enchantments = tag.get(key);
ListTag enchantments = tag.getListTag(key);
ListTag remappedEnchantments = new ListTag(CompoundTag.class);
List<Tag> lore = new ArrayList<>();
for (Tag enchantmentEntry : enchantments.clone()) {
Tag idTag = ((CompoundTag) enchantmentEntry).get("id");
for (Tag enchantmentEntry : enchantments.copy()) {
if (!(enchantmentEntry instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchantmentEntry;
NumberTag idTag = entryTag.getNumberTag("id");
if (idTag == null) continue;
short newId = ((NumberTag) idTag).asShort();
short newId = idTag.asShort();
String enchantmentName = enchantmentMappings.get(newId);
if (enchantmentName != null) {
enchantments.remove(enchantmentEntry);
short level = ((NumberTag) ((CompoundTag) enchantmentEntry).get("lvl")).asShort();
NumberTag levelTag = entryTag.getNumberTag("lvl");
short level = levelTag != null ? levelTag.asShort() : 1;
if (hideLevelForEnchants != null && hideLevelForEnchants.contains(newId)) {
lore.add(new StringTag(enchantmentName));
} else {
@@ -69,33 +74,32 @@ public class LegacyEnchantmentRewriter {
}
}
if (!lore.isEmpty()) {
if (!storedEnchant && enchantments.size() == 0) {
if (!storedEnchant && enchantments.isEmpty()) {
CompoundTag dummyEnchantment = new CompoundTag();
dummyEnchantment.put("id", new ShortTag((short) 0));
dummyEnchantment.put("lvl", new ShortTag((short) 0));
dummyEnchantment.putShort("id", (short) 0);
dummyEnchantment.putShort("lvl", (short) 0);
enchantments.add(dummyEnchantment);
tag.put(nbtTagName + "|dummyEnchant", new ByteTag());
IntTag hideFlags = tag.get("HideFlags");
NumberTag hideFlags = tag.getNumberTag("HideFlags");
if (hideFlags == null) {
hideFlags = new IntTag();
} else {
tag.put(nbtTagName + "|oldHideFlags", new IntTag(hideFlags.asByte()));
tag.putInt(nbtTagName + "|oldHideFlags", hideFlags.asByte());
}
int flags = hideFlags.asByte() | 1;
hideFlags.setValue(flags);
tag.put("HideFlags", hideFlags);
tag.putInt("HideFlags", flags);
}
tag.put(nbtTagName + "|" + key, remappedEnchantments);
CompoundTag display = tag.get("display");
CompoundTag display = tag.getCompoundTag("display");
if (display == null) {
tag.put("display", display = new CompoundTag());
}
ListTag loreTag = display.get("Lore");
ListTag loreTag = display.getListTag("Lore");
if (loreTag == null) {
display.put("Lore", loreTag = new ListTag(StringTag.class));
}
@@ -108,38 +112,45 @@ public class LegacyEnchantmentRewriter {
public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "ench";
ListTag remappedEnchantments = tag.remove(nbtTagName + "|" + key);
ListTag enchantments = tag.get(key);
ListTag enchantments = tag.getListTag(key);
if (enchantments == null) {
enchantments = new ListTag(CompoundTag.class);
}
if (!storedEnchant && tag.remove(nbtTagName + "|dummyEnchant") != null) {
for (Tag enchantment : enchantments.clone()) {
short id = ((NumberTag) ((CompoundTag) enchantment).get("id")).asShort();
short level = ((NumberTag) ((CompoundTag) enchantment).get("lvl")).asShort();
for (Tag enchantment : enchantments.copy()) {
if (!(enchantment instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchantment;
NumberTag idTag = entryTag.getNumberTag("id");
NumberTag levelTag = entryTag.getNumberTag("lvl");
short id = idTag != null ? idTag.asShort() : 0;
short level = levelTag != null ? levelTag.asShort() : 0;
if (id == 0 && level == 0) {
enchantments.remove(enchantment);
}
}
IntTag hideFlags = tag.remove(nbtTagName + "|oldHideFlags");
if (hideFlags != null) {
tag.put("HideFlags", new IntTag(hideFlags.asByte()));
Tag hideFlags = tag.remove(nbtTagName + "|oldHideFlags");
if (hideFlags instanceof IntTag) {
tag.putInt("HideFlags", ((IntTag) hideFlags).asByte());
} else {
tag.remove("HideFlags");
}
}
CompoundTag display = tag.get("display");
CompoundTag display = tag.getCompoundTag("display");
// A few null checks just to be safe, though they shouldn't actually be
ListTag lore = display != null ? display.get("Lore") : null;
for (Tag enchantment : remappedEnchantments.clone()) {
ListTag lore = display != null ? display.getListTag("Lore") : null;
for (Tag enchantment : remappedEnchantments.copy()) {
enchantments.add(enchantment);
if (lore != null && lore.size() != 0) {
if (lore != null && !lore.isEmpty()) {
lore.remove(lore.get(0));
}
}
if (lore != null && lore.size() == 0) {
if (lore != null && lore.isEmpty()) {
display.remove("Lore");
if (display.isEmpty()) {
tag.remove("display");
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -37,9 +37,7 @@ public final class MapColorRewriter {
wrapper.passthrough(Type.BYTE); // X
wrapper.passthrough(Type.BYTE); // Z
wrapper.passthrough(Type.BYTE); // Direction
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.COMPONENT); // Display Name
}
wrapper.passthrough(Type.OPTIONAL_COMPONENT); // Display Name
}
short columns = wrapper.passthrough(Type.UNSIGNED_BYTE);
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -33,15 +33,11 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
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.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_11to1_10.EntityIdRewriter;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
@@ -68,18 +64,15 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
handler(itemToClientHandler(Type.ITEM1_8));
// Handle Llama
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
if (isLlama(wrapper.user())) {
Optional<ChestedHorseStorage> horse = getChestedHorse(wrapper.user());
if (!horse.isPresent())
return;
ChestedHorseStorage storage = horse.get();
int currentSlot = wrapper.get(Type.SHORT, 0);
wrapper.set(Type.SHORT, 0, ((Integer) (currentSlot = getNewSlotId(storage, currentSlot))).shortValue());
wrapper.set(Type.ITEM1_8, 0, getNewItem(storage, currentSlot, wrapper.get(Type.ITEM1_8, 0)));
}
handler(wrapper -> {
if (isLlama(wrapper.user())) {
Optional<ChestedHorseStorage> horse = getChestedHorse(wrapper.user());
if (!horse.isPresent())
return;
ChestedHorseStorage storage = horse.get();
int currentSlot = wrapper.get(Type.SHORT, 0);
wrapper.set(Type.SHORT, 0, ((Integer) (currentSlot = getNewSlotId(storage, currentSlot))).shortValue());
wrapper.set(Type.ITEM1_8, 0, getNewItem(storage, currentSlot, wrapper.get(Type.ITEM1_8, 0)));
}
});
}
@@ -113,16 +106,16 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
}
});
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT);
// Plugin message Packet -> Trading
// Plugin message -> Trading
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() {
@Override
public void register() {
map(Type.STRING); // 0 - Channel
handler(wrapper -> {
if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
@@ -172,7 +165,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
}
});
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION);
protocol.registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
@@ -184,12 +177,12 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
// only patch it for signs for now
for (CompoundTag tag : chunk.getBlockEntities()) {
Tag idTag = tag.get("id");
if (!(idTag instanceof StringTag)) continue;
StringTag idTag = tag.getStringTag("id");
if (idTag == null) continue;
String id = (String) idTag.getValue();
String id = idTag.getValue();
if (id.equals("minecraft:sign")) {
((StringTag) idTag).setValue("Sign");
idTag.setValue("Sign");
}
}
});
@@ -306,7 +299,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
@Override
protected void registerRewrites() {
// Handle spawner block entity (map to itself with custom handler)
MappedLegacyBlockItem data = replacementData.computeIfAbsent(52, s -> new MappedLegacyBlockItem(52, (short) -1, null, false));
MappedLegacyBlockItem data = replacementData.computeIfAbsent(52 << 4, s -> new MappedLegacyBlockItem(52, (short) -1, null, false));
data.setBlockEntityHandler((b, tag) -> {
EntityIdRewriter.toClientSpawner(tag, true);
return tag;
@@ -330,10 +323,10 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
// Rewrite spawn eggs (id checks are done in the method itself)
EntityIdRewriter.toClientItem(item, true);
if (tag.get("ench") instanceof ListTag) {
if (tag.getListTag("ench") != null) {
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
}
if (tag.get("StoredEnchantments") instanceof ListTag) {
if (tag.getListTag("StoredEnchantments") != null) {
enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
}
return item;
@@ -350,10 +343,10 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
// Rewrite spawn eggs (id checks are done in the method itself)
EntityIdRewriter.toServerItem(item, true);
if (tag.contains(nbtTagName + "|ench")) {
if (tag.getListTag(nbtTagName + "|ench") != null) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
}
if (tag.contains(nbtTagName + "|StoredEnchantments")) {
if (tag.getListTag(nbtTagName + "|StoredEnchantments") != null) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
}
return item;
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -26,9 +26,9 @@ import com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_1
import com.viaversion.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage;
import com.viaversion.viabackwards.utils.Block;
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
@@ -230,7 +230,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
mapObjectType(EntityTypes1_11.ObjectType.EVOCATION_FANGS, EntityTypes1_11.ObjectType.FALLING_BLOCK, 198 | 1 << 12);
// Handle ElderGuardian & target metadata
filter().filterFamily(EntityTypes1_11.EntityType.GUARDIAN).index(12).handler((event, meta) -> {
filter().type(EntityTypes1_11.EntityType.GUARDIAN).index(12).handler((event, meta) -> {
boolean b = (boolean) meta.getValue();
int bitmask = b ? 0x02 : 0;
@@ -242,12 +242,12 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
});
// Handle skeleton swing
filter().filterFamily(EntityTypes1_11.EntityType.ABSTRACT_SKELETON).index(12).toIndex(13);
filter().type(EntityTypes1_11.EntityType.ABSTRACT_SKELETON).index(12).toIndex(13);
/*
ZOMBIE CHANGES
*/
filter().filterFamily(EntityTypes1_11.EntityType.ZOMBIE).handler((event, meta) -> {
filter().type(EntityTypes1_11.EntityType.ZOMBIE).handler((event, meta) -> {
switch (meta.id()) {
case 13:
event.cancel();
@@ -288,7 +288,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
*/
// Handle horse flags
filter().filterFamily(EntityTypes1_11.EntityType.ABSTRACT_HORSE).index(13).handler((event, meta) -> {
filter().type(EntityTypes1_11.EntityType.ABSTRACT_HORSE).index(13).handler((event, meta) -> {
StoredEntityData data = storedEntityData(event);
byte b = (byte) meta.getValue();
if (data.has(ChestedHorseStorage.class) && data.get(ChestedHorseStorage.class).isChested()) {
@@ -298,7 +298,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
});
// Create chested horse storage
filter().filterFamily(EntityTypes1_11.EntityType.CHESTED_HORSE).handler((event, meta) -> {
filter().type(EntityTypes1_11.EntityType.CHESTED_HORSE).handler((event, meta) -> {
StoredEntityData data = storedEntityData(event);
if (!data.has(ChestedHorseStorage.class)) {
data.put(new ChestedHorseStorage());
@@ -309,7 +309,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
filter().type(EntityTypes1_11.EntityType.HORSE).index(16).toIndex(17);
// Handle chested horse
filter().filterFamily(EntityTypes1_11.EntityType.CHESTED_HORSE).index(15).handler((event, meta) -> {
filter().type(EntityTypes1_11.EntityType.CHESTED_HORSE).index(15).handler((event, meta) -> {
StoredEntityData data = storedEntityData(event);
ChestedHorseStorage storage = data.get(ChestedHorseStorage.class);
boolean b = (boolean) meta.getValue();
@@ -341,7 +341,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<ClientboundPackets1_
});
// Handle Horse (Correct owner)
filter().filterFamily(EntityTypes1_11.EntityType.ABSTRACT_HORSE).index(14).toIndex(16);
filter().type(EntityTypes1_11.EntityType.ABSTRACT_HORSE).index(14).toIndex(16);
// Handle villager - Change non-existing profession
filter().type(EntityTypes1_11.EntityType.VILLAGER).index(13).handler((event, meta) -> {
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -25,10 +25,9 @@ import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
import com.viaversion.viaversion.util.ComponentUtil;
public class PlayerPackets1_11 {
private static final ValueTransformer<Short, Float> TO_NEW_FLOAT = new ValueTransformer<Short, Float>(Type.FLOAT) {
@@ -53,8 +52,8 @@ public class PlayerPackets1_11 {
wrapper.clearPacket();
wrapper.setPacketType(ClientboundPackets1_9_3.CHAT_MESSAGE);
// https://bugs.mojang.com/browse/MC-119145to
String legacy = LegacyComponentSerializer.legacySection().serialize(GsonComponentSerializer.gson().deserialize(message.toString()));
// https://bugs.mojang.com/browse/MC-119145
String legacy = ComponentUtil.jsonToLegacy(message);
message = new JsonObject();
message.getAsJsonObject().addProperty("text", legacy);
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -82,8 +82,8 @@ public class ShoulderTracker extends StoredObject {
for (String s : array) {
builder.append(s.substring(0, 1).toUpperCase())
.append(s.substring(1))
.append(" ");
.append(s.substring(1))
.append(" ");
}
return builder.toString();
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -80,9 +80,9 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
}
});
registerSetSlot(ClientboundPackets1_12.SET_SLOT, Type.ITEM1_8);
registerWindowItems(ClientboundPackets1_12.WINDOW_ITEMS, Type.ITEM1_8_SHORT_ARRAY);
registerEntityEquipment(ClientboundPackets1_12.ENTITY_EQUIPMENT, Type.ITEM1_8);
registerSetSlot(ClientboundPackets1_12.SET_SLOT);
registerWindowItems(ClientboundPackets1_12.WINDOW_ITEMS);
registerEntityEquipment(ClientboundPackets1_12.ENTITY_EQUIPMENT);
// Plugin message Packet -> Trading
protocol.registerClientbound(ClientboundPackets1_12.PLUGIN_MESSAGE, new PacketHandlers() {
@@ -91,7 +91,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
map(Type.STRING); // 0 - Channel
handler(wrapper -> {
if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
@@ -148,7 +148,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
}
});
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION);
protocol.registerClientbound(ClientboundPackets1_12.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
@@ -276,7 +276,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
// Restore the removed long array tags
for (Map.Entry<String, Tag> entry : backupTag) {
if (entry.getValue() instanceof CompoundTag) {
CompoundTag nestedTag = compoundTag.get(entry.getKey());
CompoundTag nestedTag = compoundTag.getCompoundTag(entry.getKey());
handleNbtToServer(nestedTag, (CompoundTag) entry.getValue());
} else {
compoundTag.put(entry.getKey(), fromIntArrayTag((IntArrayTag) entry.getValue()));
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -24,11 +24,10 @@ import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStor
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker;
import com.viaversion.viabackwards.utils.Block;
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_12;
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.Type;
@@ -214,8 +213,8 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
});
// Handle Illager
filter().filterFamily(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).cancel(12);
filter().filterFamily(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).index(13).toIndex(12);
filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).cancel(12);
filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).index(13).toIndex(12);
filter().type(EntityTypes1_12.EntityType.ILLUSION_ILLAGER).index(0).handler((event, meta) -> {
byte mask = (byte) meta.getValue();
@@ -228,7 +227,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
});
// Create Parrot storage
filter().filterFamily(EntityTypes1_12.EntityType.PARROT).handler((event, meta) -> {
filter().type(EntityTypes1_12.EntityType.PARROT).handler((event, meta) -> {
StoredEntityData data = storedEntityData(event);
if (!data.has(ParrotStorage.class)) {
data.put(new ParrotStorage());
@@ -271,8 +270,8 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
if (tag.isEmpty() && tracker.getLeftShoulder() != null) {
tracker.setLeftShoulder(null);
tracker.update();
} else if (tag.contains("id") && event.entityId() == tracker.getEntityId()) {
String id = (String) tag.get("id").getValue();
} else if (tag.getStringTag("id") != null && event.entityId() == tracker.getEntityId()) {
String id = tag.getStringTag("id").getValue();
if (tracker.getLeftShoulder() == null || !tracker.getLeftShoulder().equals(id)) {
tracker.setLeftShoulder(id);
tracker.update();
@@ -290,8 +289,8 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
if (tag.isEmpty() && tracker.getRightShoulder() != null) {
tracker.setRightShoulder(null);
tracker.update();
} else if (tag.contains("id") && event.entityId() == tracker.getEntityId()) {
String id = (String) tag.get("id").getValue();
} else if (tag.getStringTag("id") != null && event.entityId() == tracker.getEntityId()) {
String id = tag.getStringTag("id").getValue();
if (tracker.getRightShoulder() == null || !tracker.getRightShoulder().equals(id)) {
tracker.setRightShoulder(id);
tracker.update();
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -20,8 +20,8 @@ package com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets;
import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -25,7 +25,6 @@ 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.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
@@ -39,9 +38,9 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
@Override
protected void registerPackets() {
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM1_8);
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM1_8_SHORT_ARRAY);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8);
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT);
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT);
// Plugin message Packet -> Trading
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() {
@@ -50,7 +49,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
map(Type.STRING); // 0 - Channel
handler(wrapper -> {
if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) {
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
@@ -72,8 +71,8 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
}
});
registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM1_8);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8);
registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION);
// Handle item metadata
protocol.getEntityRewriter().filter().handler((event, meta) -> {
@@ -97,10 +96,10 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
CompoundTag tag = item.tag();
if (tag == null) return item;
if (tag.get("ench") instanceof ListTag) {
if (tag.getListTag("ench") != null) {
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
}
if (tag.get("StoredEnchantments") instanceof ListTag) {
if (tag.getListTag("StoredEnchantments") != null) {
enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
}
return item;
@@ -114,10 +113,10 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
CompoundTag tag = item.tag();
if (tag == null) return item;
if (tag.contains(nbtTagName + "|ench")) {
if (tag.getListTag(nbtTagName + "|ench") != null) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
}
if (tag.contains(nbtTagName + "|StoredEnchantments")) {
if (tag.getListTag(nbtTagName + "|StoredEnchantments") != null) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
}
return item;
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -29,6 +29,7 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets.PlayerP
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets.SoundPackets1_13;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.PlayerPositionStorage1_13;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage;
import com.viaversion.viaversion.api.Via;
@@ -39,15 +40,13 @@ import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.gson.JsonParser;
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import org.checkerframework.checker.nullness.qual.Nullable;
public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_13, ClientboundPackets1_12_1, ServerboundPackets1_13, ServerboundPackets1_12_1> {
@@ -126,6 +125,8 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
if (ViaBackwards.getConfig().isFix1_13FacePlayer() && !user.has(PlayerPositionStorage1_13.class)) {
user.put(new PlayerPositionStorage1_13());
}
user.put(new NoteBlockStorage());
}
@Override
@@ -167,14 +168,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
}
translatableToLegacyRewriter.processText(value);
try {
Component component = ChatRewriter.HOVER_GSON_SERIALIZER.deserializeFromTree(value);
return LegacyComponentSerializer.legacySection().serialize(component);
} catch (Exception e) {
ViaBackwards.getPlatform().getLogger().warning("Error converting json text to legacy: " + value);
e.printStackTrace();
}
return "";
return ComponentUtil.jsonToLegacy(value);
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -20,10 +20,9 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
public class BannerHandler implements BackwardsBlockEntityHandler {
@@ -34,28 +33,29 @@ public class BannerHandler implements BackwardsBlockEntityHandler {
private static final int BANNER_STOP = 7109;
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
public CompoundTag transform(int blockId, CompoundTag tag) {
// Normal banners
if (blockId >= BANNER_START && blockId <= BANNER_STOP) {
int color = (blockId - BANNER_START) >> 4;
tag.put("Base", new IntTag((15 - color)));
tag.putInt("Base", 15 - color);
}
// Wall banners
else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) {
int color = (blockId - WALL_BANNER_START) >> 2;
tag.put("Base", new IntTag((15 - color)));
tag.putInt("Base", 15 - color);
} else {
ViaBackwards.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag);
}
// Invert colors
Tag patternsTag = tag.get("Patterns");
if (patternsTag instanceof ListTag) {
for (Tag pattern : (ListTag) patternsTag) {
ListTag patternsTag = tag.getListTag("Patterns");
if (patternsTag != null) {
for (Tag pattern : patternsTag) {
if (!(pattern instanceof CompoundTag)) continue;
IntTag c = ((CompoundTag) pattern).get("Color");
c.setValue(15 - c.asInt()); // Invert color id
CompoundTag patternTag = (CompoundTag) pattern;
NumberTag colorTag = patternTag.getNumberTag("Color");
patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -19,18 +19,16 @@
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
public CompoundTag transform(int blockId, CompoundTag tag) {
int offset = blockId - 748;
int color = offset >> 4;
tag.put("color", new IntTag(color));
tag.putInt("color", color);
return tag;
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -19,12 +19,9 @@
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.util.Pair;
public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
@@ -72,11 +69,11 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB
// TODO THIS IS NEVER CALLED BECAUSE ITS NO LONGER A BLOCK ENTITY :(
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
public CompoundTag transform(int blockId, CompoundTag tag) {
Pair<String, Byte> item = getOrDefault(blockId);
tag.put("Item", new StringTag(item.key()));
tag.put("Data", new IntTag(item.value()));
tag.putString("Item", item.key());
tag.putInt("Data", item.value());
return tag;
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -20,23 +20,23 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingDataLoader;
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap;
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;
public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
private final Map<String, Integer> pistonIds = new HashMap<>();
private final Object2IntMap<String> pistonIds = new Object2IntOpenHashMap<>();
public PistonHandler() {
pistonIds.defaultReturnValue(-1);
if (Via.getConfig().isServersideBlockConnections()) {
Map<String, Integer> keyToId = ConnectionData.getKeyToId();
for (Map.Entry<String, Integer> entry : keyToId.entrySet()) {
@@ -76,30 +76,30 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc
}
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
CompoundTag blockState = tag.get("blockState");
public CompoundTag transform(int blockId, CompoundTag tag) {
CompoundTag blockState = tag.getCompoundTag("blockState");
if (blockState == null) return tag;
String dataFromTag = getDataFromTag(blockState);
if (dataFromTag == null) return tag;
Integer id = pistonIds.get(dataFromTag);
if (id == null) {
int id = pistonIds.getInt(dataFromTag);
if (id == -1) {
//TODO see why this could be null and if this is bad
return tag;
}
tag.put("blockId", new IntTag(id >> 4));
tag.put("blockData", new IntTag(id & 15));
tag.putInt("blockId", id >> 4);
tag.putInt("blockData", id & 15);
return tag;
}
// The type hasn't actually been updated in the blockstorage, so we need to construct it
private String getDataFromTag(CompoundTag tag) {
StringTag name = tag.get("Name");
StringTag name = tag.getStringTag("Name");
if (name == null) return null;
CompoundTag properties = tag.get("Properties");
CompoundTag properties = tag.getCompoundTag("Properties");
if (properties == null) return name.getValue();
StringJoiner joiner = new StringJoiner(",", name.getValue() + "[", "]");
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -19,21 +19,19 @@
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
public class SkullHandler implements BackwardsBlockEntityHandler {
private static final int SKULL_START = 5447;
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
public CompoundTag transform(int blockId, CompoundTag tag) {
int diff = blockId - SKULL_START;
int pos = diff % 20;
byte type = (byte) Math.floor(diff / 20f);
// Set type
tag.put("SkullType", new ByteTag(type));
tag.putByte("SkullType", type);
// Remove wall skulls
if (pos < 4) {
@@ -41,7 +39,7 @@ public class SkullHandler implements BackwardsBlockEntityHandler {
}
// Add rotation for normal skulls
tag.put("Rot", new ByteTag((byte) ((pos - 4) & 255)));
tag.putByte("Rot", (byte) ((pos - 4) & 255));
return tag;
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -20,22 +20,18 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.EntityNameRewrites;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
@Override
public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) {
Tag dataTag = tag.get("SpawnData");
if (dataTag instanceof CompoundTag) {
CompoundTag data = (CompoundTag) dataTag;
Tag idTag = data.get("id");
if (idTag instanceof StringTag) {
StringTag s = (StringTag) idTag;
s.setValue(EntityNameRewrites.rewrite(s.getValue()));
public CompoundTag transform(int blockId, CompoundTag tag) {
CompoundTag dataTag = tag.getCompoundTag("SpawnData");
if (dataTag != null) {
StringTag idTag = dataTag.getStringTag("id");
if (idTag != null) {
idTag.setValue(EntityNameRewrites.rewrite(idTag.getValue()));
}
}
return tag;
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -19,7 +19,6 @@
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data;
import com.viaversion.viaversion.util.Key;
import java.util.HashMap;
import java.util.Map;
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter;
import com.viaversion.viaversion.util.Key;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -55,94 +55,94 @@ public class ParticleMapping {
};
particles = new ParticleData[]{
rewrite(16), // (0->16) minecraft:ambient_entity_effect -> mobSpellAmbient
rewrite(20), // (1->20) minecraft:angry_villager -> angryVillager
rewrite(35), // (2->35) minecraft:barrier -> barrier
rewrite(37, blockHandler),
// (3->37) minecraft:block -> blockcrack
rewrite(4), // (4->4) minecraft:bubble -> bubble
rewrite(29), // (5->29) minecraft:cloud -> cloud
rewrite(9), // (6->9) minecraft:crit -> crit
rewrite(44), // (7->44) minecraft:damage_indicator -> damageIndicator‌
rewrite(42), // (8->42) minecraft:dragon_breath -> dragonbreath
rewrite(19), // (9->19) minecraft:dripping_lava -> dripLava
rewrite(18), // (10->18) minecraft:dripping_water -> dripWater
rewrite(30, new ParticleHandler() {
@Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
float r = wrapper.read(Type.FLOAT);
float g = wrapper.read(Type.FLOAT);
float b = wrapper.read(Type.FLOAT);
float scale = wrapper.read(Type.FLOAT);
rewrite(16), // (0->16) minecraft:ambient_entity_effect -> mobSpellAmbient
rewrite(20), // (1->20) minecraft:angry_villager -> angryVillager
rewrite(35), // (2->35) minecraft:barrier -> barrier
rewrite(37, blockHandler),
// (3->37) minecraft:block -> blockcrack
rewrite(4), // (4->4) minecraft:bubble -> bubble
rewrite(29), // (5->29) minecraft:cloud -> cloud
rewrite(9), // (6->9) minecraft:crit -> crit
rewrite(44), // (7->44) minecraft:damage_indicator -> damageIndicator‌
rewrite(42), // (8->42) minecraft:dragon_breath -> dragonbreath
rewrite(19), // (9->19) minecraft:dripping_lava -> dripLava
rewrite(18), // (10->18) minecraft:dripping_water -> dripWater
rewrite(30, new ParticleHandler() {
@Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
float r = wrapper.read(Type.FLOAT);
float g = wrapper.read(Type.FLOAT);
float b = wrapper.read(Type.FLOAT);
float scale = wrapper.read(Type.FLOAT);
wrapper.set(Type.FLOAT, 3, r); // 5 - Offset X index=3
wrapper.set(Type.FLOAT, 4, g); // 6 - Offset Y index=4
wrapper.set(Type.FLOAT, 5, b); // 7 - Offset Z index=5
wrapper.set(Type.FLOAT, 6, scale); // 8 - Particle Data index=6
wrapper.set(Type.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle
wrapper.set(Type.FLOAT, 3, r); // 5 - Offset X index=3
wrapper.set(Type.FLOAT, 4, g); // 6 - Offset Y index=4
wrapper.set(Type.FLOAT, 5, b); // 7 - Offset Z index=5
wrapper.set(Type.FLOAT, 6, scale); // 8 - Particle Data index=6
wrapper.set(Type.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle
return null;
}
return null;
}
@Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) {
return null;
}
}), // (11->30) minecraft:dust -> reddust
rewrite(13), // (12->13) minecraft:effect -> spell
rewrite(41), // (13->41) minecraft:elder_guardian -> mobappearance
rewrite(10), // (14->10) minecraft:enchanted_hit -> magicCrit‌
rewrite(25), // (15->25) minecraft:enchant -> enchantmenttable
rewrite(43), // (16->43) minecraft:end_rod -> endRod
rewrite(15), // (17->15) minecraft:entity_effect -> mobSpell
rewrite(2), // (18->2) minecraft:explosion_emitter -> hugeexplosion
rewrite(1), // (19->1) minecraft:explosion -> largeexplode
rewrite(46, blockHandler),
// (20->46) minecraft:falling_dust -> fallingdust
rewrite(3), // (21->3) minecraft:firework -> fireworksSpark
rewrite(6), // (22->6) minecraft:fishing -> wake
rewrite(26), // (23->26) minecraft:flame -> flame
rewrite(21), // (24->21) minecraft:happy_villager -> happyVillager
rewrite(34), // (25->34) minecraft:heart -> heart
rewrite(14), // (26->14) minecraft:instant_effect -> instantSpell
rewrite(36, new ParticleHandler() {
@Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
return rewrite(protocol, wrapper.read(Type.ITEM1_13));
}
@Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) {
return null;
}
}), // (11->30) minecraft:dust -> reddust
rewrite(13), // (12->13) minecraft:effect -> spell
rewrite(41), // (13->41) minecraft:elder_guardian -> mobappearance
rewrite(10), // (14->10) minecraft:enchanted_hit -> magicCrit‌
rewrite(25), // (15->25) minecraft:enchant -> enchantmenttable
rewrite(43), // (16->43) minecraft:end_rod -> endRod
rewrite(15), // (17->15) minecraft:entity_effect -> mobSpell
rewrite(2), // (18->2) minecraft:explosion_emitter -> hugeexplosion
rewrite(1), // (19->1) minecraft:explosion -> largeexplode
rewrite(46, blockHandler),
// (20->46) minecraft:falling_dust -> fallingdust
rewrite(3), // (21->3) minecraft:firework -> fireworksSpark
rewrite(6), // (22->6) minecraft:fishing -> wake
rewrite(26), // (23->26) minecraft:flame -> flame
rewrite(21), // (24->21) minecraft:happy_villager -> happyVillager
rewrite(34), // (25->34) minecraft:heart -> heart
rewrite(14), // (26->14) minecraft:instant_effect -> instantSpell
rewrite(36, new ParticleHandler() {
@Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
return rewrite(protocol, wrapper.read(Type.ITEM1_13));
}
@Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) {
return rewrite(protocol, (Item) data.get(0).getValue());
}
@Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, List<Particle.ParticleData<?>> data) {
return rewrite(protocol, (Item) data.get(0).getValue());
}
private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) {
Item item = protocol.getItemRewriter().handleItemToClient(newItem);
return new int[]{item.identifier(), item.data()};
}
}), // (27->36) minecraft:item -> iconcrack
rewrite(33), // (28->33) minecraft:item_slime -> slime
rewrite(31), // (29->31) minecraft:item_snowball -> snowballpoof
rewrite(12), // (30->12) minecraft:large_smoke -> largesmoke
rewrite(27), // (31->27) minecraft:lava -> lava
rewrite(22), // (32->22) minecraft:mycelium -> townaura
rewrite(23), // (33->23) minecraft:note -> note
rewrite(0), // (34->0) minecraft:poof -> explode
rewrite(24), // (35->24) minecraft:portal -> portal
rewrite(39), // (36->39) minecraft:rain -> droplet
rewrite(11), // (37->11) minecraft:smoke -> smoke
rewrite(48), // (38->48) minecraft:spit -> spit
rewrite(12), // (39->-1) minecraft:squid_ink -> squid_ink -> large_smoke
rewrite(45), // (40->45) minecraft:sweep_attack -> sweepAttack‌
rewrite(47), // (41->47) minecraft:totem_of_undying -> totem
rewrite(7), // (42->7) minecraft:underwater -> suspended‌
rewrite(5), // (43->5) minecraft:splash -> splash
rewrite(17), // (44->17) minecraft:witch -> witchMagic
rewrite(4), // (45->4) minecraft:bubble_pop -> bubble
rewrite(4), // (46->4) minecraft:current_down -> bubble
rewrite(4), // (47->4) minecraft:bubble_column_up -> bubble
rewrite(18), // (48->-1) minecraft:nautilus -> nautilus -> dripWater
rewrite(18), // (49->18) minecraft:dolphin -> dripWater
private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) {
Item item = protocol.getItemRewriter().handleItemToClient(newItem);
return new int[]{item.identifier(), item.data()};
}
}), // (27->36) minecraft:item -> iconcrack
rewrite(33), // (28->33) minecraft:item_slime -> slime
rewrite(31), // (29->31) minecraft:item_snowball -> snowballpoof
rewrite(12), // (30->12) minecraft:large_smoke -> largesmoke
rewrite(27), // (31->27) minecraft:lava -> lava
rewrite(22), // (32->22) minecraft:mycelium -> townaura
rewrite(23), // (33->23) minecraft:note -> note
rewrite(0), // (34->0) minecraft:poof -> explode
rewrite(24), // (35->24) minecraft:portal -> portal
rewrite(39), // (36->39) minecraft:rain -> droplet
rewrite(11), // (37->11) minecraft:smoke -> smoke
rewrite(48), // (38->48) minecraft:spit -> spit
rewrite(12), // (39->-1) minecraft:squid_ink -> squid_ink -> large_smoke
rewrite(45), // (40->45) minecraft:sweep_attack -> sweepAttack‌
rewrite(47), // (41->47) minecraft:totem_of_undying -> totem
rewrite(7), // (42->7) minecraft:underwater -> suspended‌
rewrite(5), // (43->5) minecraft:splash -> splash
rewrite(17), // (44->17) minecraft:witch -> witchMagic
rewrite(4), // (45->4) minecraft:bubble_pop -> bubble
rewrite(4), // (46->4) minecraft:current_down -> bubble
rewrite(4), // (47->4) minecraft:bubble_column_up -> bubble
rewrite(18), // (48->-1) minecraft:nautilus -> nautilus -> dripWater
rewrite(18), // (49->18) minecraft:dolphin -> dripWater
};
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2T
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
@@ -40,18 +41,28 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
import com.viaversion.viaversion.libs.opennbt.conversion.ConverterRegistry;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.BlockIdData;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Key;
import java.util.*;
import com.viaversion.viaversion.util.Pair;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewriters.ItemRewriter<ClientboundPackets1_13, ServerboundPackets1_12_1, Protocol1_12_2To1_13> {
@@ -59,22 +70,22 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
private final String extraNbtTag;
public BlockItemPackets1_13(Protocol1_12_2To1_13 protocol) {
super(protocol);
super(protocol, null, null);
extraNbtTag = "VB|" + protocol.getClass().getSimpleName() + "|2";
}
public static boolean isDamageable(int id) {
return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel
|| id == 261 // bow
|| id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes
|| id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe
|| id >= 290 && id <= 294 // hoes
|| id >= 298 && id <= 317 // armors
|| id == 346 // fishing rod
|| id == 359 // shears
|| id == 398 // carrot on a stick
|| id == 442 // shield
|| id == 443; // elytra
|| id == 261 // bow
|| id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes
|| id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe
|| id >= 290 && id <= 294 // hoes
|| id >= 298 && id <= 317 // armors
|| id == 346 // fishing rod
|| id == 359 // shears
|| id == 398 // carrot on a stick
|| id == 442 // shield
|| id == 443; // elytra
}
@Override
@@ -126,6 +137,17 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
else if (blockId >= 483 && blockId <= 498)
blockId = blockId - 483 + 219;
if (blockId == 25) { // Note block
final NoteBlockStorage noteBlockStorage = wrapper.user().get(NoteBlockStorage.class);
final Position position = wrapper.get(Type.POSITION1_8, 0);
final Pair<Integer, Integer> update = noteBlockStorage.getNoteBlockUpdate(position);
if (update != null) { // Use values from block state update
wrapper.set(Type.UNSIGNED_BYTE, 0, update.key().shortValue());
wrapper.set(Type.UNSIGNED_BYTE, 1, update.value().shortValue());
}
}
wrapper.set(Type.VAR_INT, 0, blockId);
});
}
@@ -147,11 +169,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
}
wrapper.set(Type.NAMED_COMPOUND_TAG, 0,
provider.transform(
wrapper.user(),
wrapper.get(Type.POSITION1_8, 0),
wrapper.get(Type.NAMED_COMPOUND_TAG, 0)
));
provider.transform(
wrapper.user(),
wrapper.get(Type.POSITION1_8, 0),
wrapper.get(Type.NAMED_COMPOUND_TAG, 0)
));
});
}
});
@@ -165,7 +187,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
blockStorage.getBlocks().entrySet().removeIf(entry -> {
Position position = entry.getKey();
return position.x() >= chunkMinX && position.z() >= chunkMinZ
&& position.x() <= chunkMaxX && position.z() <= chunkMaxZ;
&& position.x() <= chunkMaxX && position.z() <= chunkMaxZ;
});
});
@@ -179,6 +201,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
int blockState = wrapper.read(Type.VAR_INT);
Position position = wrapper.get(Type.POSITION1_8, 0);
// Note block special treatment
if (blockState >= 249 && blockState <= 748) { // Note block states id range
wrapper.user().get(NoteBlockStorage.class).storeNoteBlockUpdate(position, blockState);
}
// Store blocks
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
storage.checkAndStore(position, blockState);
@@ -206,9 +233,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
int chunkZ = wrapper.get(Type.INT, 1);
int block = record.getBlockId();
Position position = new Position(
record.getSectionX() + (chunkX * 16),
record.getY(),
record.getSectionZ() + (chunkZ * 16));
record.getSectionX() + (chunkX * 16),
record.getY(),
record.getSectionZ() + (chunkZ * 16));
// Store if needed
storage.checkAndStore(position, block);
@@ -227,7 +254,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
@Override
public void register() {
map(Type.UNSIGNED_BYTE);
map(Type.ITEM1_13_ARRAY, Type.ITEM1_8_SHORT_ARRAY);
map(Type.ITEM1_13_SHORT_ARRAY, Type.ITEM1_8_SHORT_ARRAY);
handler(itemArrayToClientHandler(Type.ITEM1_8_SHORT_ARRAY));
}
@@ -255,15 +282,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class);
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
for (CompoundTag tag : chunk.getBlockEntities()) {
Tag idTag = tag.get("id");
StringTag idTag = tag.getStringTag("id");
if (idTag == null) continue;
String id = (String) idTag.getValue();
String id = idTag.getValue();
// Ignore if we don't handle it
if (!provider.isHandled(id)) continue;
int sectionIndex = ((NumberTag) tag.get("y")).asInt() >> 4;
int sectionIndex = tag.getNumberTag("y").asInt() >> 4;
if (sectionIndex < 0 || sectionIndex > 15) {
// 1.17 chunks
continue;
@@ -271,9 +298,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
ChunkSection section = chunk.getSections()[sectionIndex];
int x = ((NumberTag) tag.get("x")).asInt();
int y = ((NumberTag) tag.get("y")).asInt();
int z = ((NumberTag) tag.get("z")).asInt();
int x = tag.getNumberTag("x").asInt();
int y = tag.getNumberTag("y").asInt();
int z = tag.getNumberTag("z").asInt();
Position position = new Position(x, (short) y, z);
int block = section.palette(PaletteType.BLOCKS).idAt(x & 0xF, y & 0xF, z & 0xF);
@@ -299,9 +326,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
// Check if the block is a flower
if (FlowerPotHandler.isFlowah(block)) {
Position pos = new Position(
(x + (chunk.getX() << 4)),
(short) (y + (i << 4)),
(z + (chunk.getZ() << 4))
(x + (chunk.getX() << 4)),
(short) (y + (i << 4)),
(z + (chunk.getZ() << 4))
);
// Store block
storage.checkAndStore(pos, block);
@@ -390,9 +417,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
byte x = wrapper.read(Type.BYTE);
byte z = wrapper.read(Type.BYTE);
byte direction = wrapper.read(Type.BYTE);
if (wrapper.read(Type.BOOLEAN)) {
wrapper.read(Type.COMPONENT);
}
wrapper.read(Type.OPTIONAL_COMPONENT);
if (type > 9) {
wrapper.set(Type.VAR_INT, 1, wrapper.get(Type.VAR_INT, 1) - 1);
continue;
@@ -481,7 +506,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
// Use tag to get original ID and data
Tag originalIdTag;
if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) != null) {
if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) instanceof NumberTag) {
rawId = ((NumberTag) originalIdTag).asInt();
gotRawIdFromTag = true;
}
@@ -518,15 +543,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
if (tag != null) {
if (isDamageable(item.identifier())) {
Tag damageTag = tag.remove("Damage");
if (!gotRawIdFromTag && damageTag instanceof IntTag) {
item.setData((short) (int) damageTag.getValue());
if (!gotRawIdFromTag && damageTag instanceof NumberTag) {
item.setData(((NumberTag) damageTag).asShort());
}
}
if (item.identifier() == 358) { // map
Tag mapTag = tag.remove("map");
if (!gotRawIdFromTag && mapTag instanceof IntTag) {
item.setData((short) (int) mapTag.getValue());
if (!gotRawIdFromTag && mapTag instanceof NumberTag) {
item.setData(((NumberTag) mapTag).asShort());
}
}
@@ -534,11 +559,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
invertShieldAndBannerId(item, tag);
// Display Name now uses JSON
CompoundTag display = tag.get("display");
CompoundTag display = tag.getCompoundTag("display");
if (display != null) {
StringTag name = display.get("Name");
StringTag name = display.getStringTag("Name");
if (name != null) {
display.put(extraNbtTag + "|Name", new StringTag(name.getValue()));
display.putString(extraNbtTag + "|Name", name.getValue());
name.setValue(protocol.jsonToLegacy(name.getValue()));
}
}
@@ -561,7 +586,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
}
if (!tag.contains("EntityTag")) {
CompoundTag entityTag = new CompoundTag();
entityTag.put("id", new StringTag(eggEntityId.get()));
entityTag.putString("id", eggEntityId.get());
tag.put("EntityTag", entityTag);
}
return 0x17f0000; // 383 << 16;
@@ -572,16 +597,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
private void rewriteCanPlaceToClient(CompoundTag tag, String tagName) {
// The tag was manually created incorrectly so ignore rewriting it
if (!(tag.get(tagName) instanceof ListTag)) return;
ListTag blockTag = tag.get(tagName);
ListTag blockTag = tag.getListTag(tagName);
if (blockTag == null) return;
ListTag newCanPlaceOn = new ListTag(StringTag.class);
tag.put(extraNbtTag + "|" + tagName, ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(blockTag)));
tag.put(extraNbtTag + "|" + tagName, blockTag.copy());
for (Tag oldTag : blockTag) {
Object value = oldTag.getValue();
String[] newValues = value instanceof String ?
BlockIdData.fallbackReverseMapping.get(Key.stripMinecraftNamespace((String) value)) : null;
BlockIdData.fallbackReverseMapping.get(Key.stripMinecraftNamespace((String) value)) : null;
if (newValues != null) {
for (String newValue : newValues) {
newCanPlaceOn.add(new StringTag(newValue));
@@ -596,22 +620,26 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
//TODO un-ugly all of this
private void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnch) {
String key = storedEnch ? "StoredEnchantments" : "Enchantments";
ListTag enchantments = tag.get(key);
ListTag enchantments = tag.getListTag(key);
if (enchantments == null) return;
ListTag noMapped = new ListTag(CompoundTag.class);
ListTag newEnchantments = new ListTag(CompoundTag.class);
List<Tag> lore = new ArrayList<>();
boolean hasValidEnchants = false;
for (Tag enchantmentEntryTag : enchantments.clone()) {
CompoundTag enchantmentEntry = (CompoundTag) enchantmentEntryTag;
Tag idTag = enchantmentEntry.get("id");
if (!(idTag instanceof StringTag)) {
for (Tag enchantmentEntryTag : enchantments.copy()) {
if (!(enchantmentEntryTag instanceof CompoundTag)) {
continue;
}
String newId = (String) idTag.getValue();
NumberTag levelTag = enchantmentEntry.get("lvl");
CompoundTag enchantmentEntry = (CompoundTag) enchantmentEntryTag;
StringTag idTag = enchantmentEntry.getStringTag("id");
if (idTag == null) {
continue;
}
String newId = idTag.getValue();
NumberTag levelTag = enchantmentEntry.getNumberTag("lvl");
if (levelTag == null) {
continue;
}
@@ -656,51 +684,50 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
}
CompoundTag newEntry = new CompoundTag();
newEntry.put("id", new ShortTag(oldId));
newEntry.put("lvl", new ShortTag(level));
newEntry.putShort("id", oldId);
newEntry.putShort("lvl", level);
newEnchantments.add(newEntry);
}
}
// Put here to hide empty enchantment from 1.14 rewrites
if (!storedEnch && !hasValidEnchants) {
IntTag hideFlags = tag.get("HideFlags");
NumberTag hideFlags = tag.getNumberTag("HideFlags");
if (hideFlags == null) {
hideFlags = new IntTag();
tag.put(extraNbtTag + "|DummyEnchant", new ByteTag());
} else {
tag.put(extraNbtTag + "|OldHideFlags", new IntTag(hideFlags.asByte()));
tag.putInt(extraNbtTag + "|OldHideFlags", hideFlags.asByte());
}
if (newEnchantments.size() == 0) {
if (newEnchantments.isEmpty()) {
CompoundTag enchEntry = new CompoundTag();
enchEntry.put("id", new ShortTag((short) 0));
enchEntry.put("lvl", new ShortTag((short) 0));
enchEntry.putShort("id", (short) 0);
enchEntry.putShort("lvl", (short) 0);
newEnchantments.add(enchEntry);
}
int value = hideFlags.asByte() | 1;
hideFlags.setValue(value);
tag.put("HideFlags", hideFlags);
tag.putInt("HideFlags", value);
}
if (noMapped.size() != 0) {
if (!noMapped.isEmpty()) {
tag.put(extraNbtTag + "|" + key, noMapped);
if (!lore.isEmpty()) {
CompoundTag display = tag.get("display");
CompoundTag display = tag.getCompoundTag("display");
if (display == null) {
tag.put("display", display = new CompoundTag());
}
ListTag loreTag = display.get("Lore");
ListTag loreTag = display.getListTag("Lore");
if (loreTag == null) {
display.put("Lore", loreTag = new ListTag(StringTag.class));
tag.put(extraNbtTag + "|DummyLore", new ByteTag());
} else if (loreTag.size() != 0) {
} else if (!loreTag.isEmpty()) {
ListTag oldLore = new ListTag(StringTag.class);
for (Tag value : loreTag) {
oldLore.add(value.clone());
oldLore.add(value.copy());
}
tag.put(extraNbtTag + "|OldLore", oldLore);
@@ -728,11 +755,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
// NBT Additions
if (isDamageable(item.identifier())) {
if (tag == null) item.setTag(tag = new CompoundTag());
tag.put("Damage", new IntTag(item.data()));
tag.putInt("Damage", item.data());
}
if (item.identifier() == 358) { // map
if (tag == null) item.setTag(tag = new CompoundTag());
tag.put("map", new IntTag(item.data()));
tag.putInt("map", item.data());
}
// NBT Changes
@@ -741,13 +768,12 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
invertShieldAndBannerId(item, tag);
// Display Name now uses JSON
Tag display = tag.get("display");
if (display instanceof CompoundTag) {
CompoundTag displayTag = (CompoundTag) display;
StringTag name = displayTag.get("Name");
CompoundTag display = tag.getCompoundTag("display");
if (display != null) {
StringTag name = display.getStringTag("Name");
if (name != null) {
StringTag via = displayTag.remove(extraNbtTag + "|Name");
name.setValue(via != null ? via.getValue() : ChatRewriter.legacyTextToJsonString(name.getValue()));
Tag via = display.remove(extraNbtTag + "|Name");
name.setValue(via instanceof StringTag ? ((StringTag) via).getValue() : ComponentUtil.legacyToJsonString(name.getValue()));
}
}
@@ -760,9 +786,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
// Handle SpawnEggs
if (item.identifier() == 383) {
CompoundTag entityTag = tag.get("EntityTag");
CompoundTag entityTag = tag.getCompoundTag("EntityTag");
StringTag identifier;
if (entityTag != null && (identifier = entityTag.get("id")) != null) {
if (entityTag != null && (identifier = entityTag.getStringTag("id")) != null) {
rawId = SpawnEggRewriter.getSpawnEggId(identifier.getValue());
if (rawId == -1) {
rawId = 25100288; // Bat fallback
@@ -796,8 +822,10 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
int newId = -1;
if (protocol.getMappingData().getItemMappings().inverse().getNewId(rawId) == -1) {
if (!isDamageable(item.identifier()) && item.identifier() != 358) { // Map
if (tag == null) item.setTag(tag = new CompoundTag());
tag.put(extraNbtTag, new IntTag(originalId)); // Data will be lost, saving original id
if (tag == null) {
item.setTag(tag = new CompoundTag());
}
tag.putInt(extraNbtTag, originalId); // Data will be lost, saving original id
}
if (item.identifier() == 229) { // purple shulker box
@@ -824,11 +852,12 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
}
private void rewriteCanPlaceToServer(CompoundTag tag, String tagName) {
if (!(tag.get(tagName) instanceof ListTag)) return;
if (tag.getListTag(tagName) == null) return;
ListTag blockTag = tag.remove(extraNbtTag + "|" + tagName);
if (blockTag != null) {
tag.put(tagName, ConverterRegistry.convertToTag(ConverterRegistry.convertToValue(blockTag)));
} else if ((blockTag = tag.get(tagName)) != null) {
tag.put(tagName, blockTag.copy());
} else if ((blockTag = tag.getListTag(tagName)) != null) {
ListTag newCanPlaceOn = new ListTag(StringTag.class);
for (Tag oldTag : blockTag) {
Object value = oldTag.getValue();
@@ -855,15 +884,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
private void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnch) {
String key = storedEnch ? "StoredEnchantments" : "Enchantments";
ListTag enchantments = tag.get(storedEnch ? key : "ench");
ListTag enchantments = tag.getListTag(storedEnch ? key : "ench");
if (enchantments == null) return;
ListTag newEnchantments = new ListTag(CompoundTag.class);
boolean dummyEnchant = false;
if (!storedEnch) {
IntTag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags");
if (hideFlags != null) {
tag.put("HideFlags", new IntTag(hideFlags.asByte()));
Tag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags");
if (hideFlags instanceof IntTag) {
tag.putInt("HideFlags", ((NumberTag) hideFlags).asByte());
dummyEnchant = true;
} else if (tag.remove(extraNbtTag + "|DummyEnchant") != null) {
tag.remove("HideFlags");
@@ -872,42 +901,50 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
}
for (Tag enchEntry : enchantments) {
CompoundTag enchantmentEntry = new CompoundTag();
short oldId = ((NumberTag) ((CompoundTag) enchEntry).get("id")).asShort();
short level = ((NumberTag) ((CompoundTag) enchEntry).get("lvl")).asShort();
if (dummyEnchant && oldId == 0 && level == 0) {
continue; //Skip dummy enchatment
if (!(enchEntry instanceof CompoundTag)) {
continue;
}
CompoundTag entryTag = (CompoundTag) enchEntry;
NumberTag idTag = entryTag.getNumberTag("id");
NumberTag levelTag = entryTag.getNumberTag("lvl");
CompoundTag enchantmentEntry = new CompoundTag();
short oldId = idTag != null ? idTag.asShort() : 0;
short level = levelTag != null ? levelTag.asShort() : 0;
if (dummyEnchant && oldId == 0 && level == 0) {
continue; // Skip dummy enchatment
}
String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId);
if (newId == null) {
newId = "viaversion:legacy/" + oldId;
}
enchantmentEntry.put("id", new StringTag(newId));
enchantmentEntry.putString("id", newId);
enchantmentEntry.put("lvl", new ShortTag(level));
enchantmentEntry.putShort("lvl", level);
newEnchantments.add(enchantmentEntry);
}
ListTag noMapped = tag.remove(extraNbtTag + "|Enchantments");
if (noMapped != null) {
for (Tag value : noMapped) {
Tag noMapped = tag.remove(extraNbtTag + "|Enchantments");
if (noMapped instanceof ListTag) {
for (Tag value : ((ListTag) noMapped)) {
newEnchantments.add(value);
}
}
CompoundTag display = tag.get("display");
CompoundTag display = tag.getCompoundTag("display");
if (display == null) {
tag.put("display", display = new CompoundTag());
}
ListTag oldLore = tag.remove(extraNbtTag + "|OldLore");
if (oldLore != null) {
ListTag lore = display.get("Lore");
Tag oldLore = tag.remove(extraNbtTag + "|OldLore");
if (oldLore instanceof ListTag) {
ListTag lore = display.getListTag("Lore");
if (lore == null) {
tag.put("Lore", lore = new ListTag());
}
lore.setValue(oldLore.getValue());
lore.setValue(((ListTag) oldLore).getValue());
} else if (tag.remove(extraNbtTag + "|DummyLore") != null) {
display.remove("Lore");
if (display.isEmpty()) {
@@ -924,24 +961,22 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
private void invertShieldAndBannerId(Item item, CompoundTag tag) {
if (item.identifier() != 442 && item.identifier() != 425) return;
Tag blockEntityTag = tag.get("BlockEntityTag");
if (!(blockEntityTag instanceof CompoundTag)) return;
CompoundTag blockEntityTag = tag.getCompoundTag("BlockEntityTag");
if (blockEntityTag == null) return;
CompoundTag blockEntityCompoundTag = (CompoundTag) blockEntityTag;
Tag base = blockEntityCompoundTag.get("Base");
if (base instanceof IntTag) {
IntTag baseTag = (IntTag) base;
baseTag.setValue(15 - baseTag.asInt()); // invert color id
NumberTag base = blockEntityTag.getNumberTag("Base");
if (base != null) {
blockEntityTag.putInt("Base", 15 - base.asInt()); // Invert color id
}
Tag patterns = blockEntityCompoundTag.get("Patterns");
if (patterns instanceof ListTag) {
ListTag patternsTag = (ListTag) patterns;
for (Tag pattern : patternsTag) {
ListTag patterns = blockEntityTag.getListTag("Patterns");
if (patterns != null) {
for (Tag pattern : patterns) {
if (!(pattern instanceof CompoundTag)) continue;
IntTag colorTag = ((CompoundTag) pattern).get("Color");
colorTag.setValue(15 - colorTag.asInt()); // Invert color id
CompoundTag patternTag = (CompoundTag) pattern;
NumberTag colorTag = patternTag.getNumberTag("Color");
patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id
}
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.EntityType
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.ParticleMapping;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage;
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.PlayerPositionStorage1_13;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
@@ -197,7 +198,10 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
map(Type.INT); // 0 - Dimension ID
handler(getDimensionHandler(0));
handler(wrapper -> wrapper.user().get(BackwardsBlockStorage.class).clear());
handler(wrapper -> {
wrapper.user().get(BackwardsBlockStorage.class).clear();
wrapper.user().get(NoteBlockStorage.class).clear();
});
}
});
@@ -227,8 +231,8 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
//TODO properly cache and calculate head position?
EntityPositionHandler.writeFacingDegrees(positionAndLook, positionStorage.getX(),
anchor == 1 ? positionStorage.getY() + 1.62 : positionStorage.getY(),
positionStorage.getZ(), x, y, z);
anchor == 1 ? positionStorage.getY() + 1.62 : positionStorage.getY(),
positionStorage.getZ(), x, y, z);
positionAndLook.write(Type.BYTE, (byte) 7); // bitfield, 0=absolute, 1=relative - x,y,z relative, yaw,pitch absolute
positionAndLook.write(Type.VAR_INT, -1);
@@ -297,7 +301,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
});
// Handle zombie metadata
filter().filterFamily(EntityTypes1_13.EntityType.ZOMBIE).removeIndex(15);
filter().type(EntityTypes1_13.EntityType.ZOMBIE).removeIndex(15);
// Handle turtle metadata (Remove them all for now)
filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(13); // Home pos
@@ -308,8 +312,8 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(18); // Traveling
// Remove additional fish meta
filter().filterFamily(EntityTypes1_13.EntityType.ABSTRACT_FISHES).cancel(12);
filter().filterFamily(EntityTypes1_13.EntityType.ABSTRACT_FISHES).cancel(13);
filter().type(EntityTypes1_13.EntityType.ABSTRACT_FISHES).cancel(12);
filter().type(EntityTypes1_13.EntityType.ABSTRACT_FISHES).cancel(13);
// Remove phantom size
filter().type(EntityTypes1_13.EntityType.PHANTOM).cancel(12);
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -61,12 +61,10 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
public void register() {
handler(packetWrapper -> {
packetWrapper.cancel();
packetWrapper.create(0x02, new PacketHandler() { // Plugin response
@Override
public void handle(PacketWrapper newWrapper) throws Exception {
newWrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id
newWrapper.write(Type.BOOLEAN, false); // Success
}
// Plugin response
packetWrapper.create(0x02, wrapper -> {
wrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id
wrapper.write(Type.BOOLEAN, false); // Success
}).sendToServer(Protocol1_12_2To1_13.class);
});
}
@@ -319,10 +317,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
for (int i = 0; i < count; i++) {
String match = wrapper.read(Type.STRING);
wrapper.write(Type.STRING, (start == 0 && !storage.isLastAssumeCommand() ? "/" : "") + match);
// Ignore tooltip
if (wrapper.read(Type.BOOLEAN)) {
wrapper.read(Type.STRING);
}
wrapper.read(Type.OPTIONAL_COMPONENT); // Remove tooltip
}
});
@@ -395,7 +390,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
if (type == 0) {
//Information from https://wiki.vg/index.php?title=Plugin_channels&oldid=14089
//The Notchain client only uses this for command block minecarts and uses MC|AutoCmd for blocks, but the Notchian server still accepts it for either.
//Maybe older versions used this and we need to implement this? The issues is that we would have to save the command block types
//Maybe older versions used this and we need to implement this? The issue is that we would have to save the command block types
wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK);
wrapper.cancel();
ViaBackwards.getPlatform().getLogger().warning("Client send MC|AdvCmd custom payload to update command block, weird!");
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -29,9 +29,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.platform.providers.Provider;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import java.util.HashMap;
import java.util.Map;
@@ -65,12 +63,12 @@ public class BackwardsBlockEntityProvider implements Provider {
* @param tag The block entity tag
*/
public CompoundTag transform(UserConnection user, Position position, CompoundTag tag) throws Exception {
final Tag idTag = tag.get("id");
if (!(idTag instanceof StringTag)) {
final StringTag idTag = tag.getStringTag("id");
if (idTag == null) {
return tag;
}
String id = (String) idTag.getValue();
String id = idTag.getValue();
BackwardsBlockEntityHandler handler = handlers.get(id);
if (handler == null) {
return tag;
@@ -82,7 +80,7 @@ public class BackwardsBlockEntityProvider implements Provider {
return tag;
}
return handler.transform(user, blockId, tag);
return handler.transform(blockId, tag);
}
/**
@@ -94,15 +92,17 @@ public class BackwardsBlockEntityProvider implements Provider {
*/
public CompoundTag transform(UserConnection user, Position position, String id) throws Exception {
CompoundTag tag = new CompoundTag();
tag.put("id", new StringTag(id));
tag.put("x", new IntTag(Math.toIntExact(position.x())));
tag.put("y", new IntTag(Math.toIntExact(position.y())));
tag.put("z", new IntTag(Math.toIntExact(position.z())));
tag.putString("id", id);
tag.putInt("x", Math.toIntExact(position.x()));
tag.putInt("y", Math.toIntExact(position.y()));
tag.putInt("z", Math.toIntExact(position.z()));
return this.transform(user, position, tag);
}
@FunctionalInterface
public interface BackwardsBlockEntityHandler {
CompoundTag transform(UserConnection user, int blockId, CompoundTag tag);
CompoundTag transform(int blockId, CompoundTag tag);
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -24,6 +24,7 @@ import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet;
import com.viaversion.viaversion.libs.fastutil.ints.IntSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.checkerframework.checker.nullness.qual.Nullable;
public class BackwardsBlockStorage implements StorableObject {
// This BlockStorage is very exclusive (;
@@ -77,11 +78,7 @@ public class BackwardsBlockStorage implements StorableObject {
blocks.put(position, block);
}
public boolean isWelcome(int block) {
return WHITELIST.contains(block);
}
public Integer get(Position position) {
public @Nullable Integer get(Position position) {
return blocks.get(position);
}
@@ -0,0 +1,50 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap;
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap;
import com.viaversion.viaversion.util.Pair;
public class NoteBlockStorage implements StorableObject {
private static final int MAX_NOTE_ID = 24;
private final Object2IntMap<Position> noteBlockUpdates = new Object2IntOpenHashMap<>();
public void storeNoteBlockUpdate(final Position position, final int blockStateId) {
noteBlockUpdates.put(position, blockStateId);
}
public Pair<Integer, Integer> getNoteBlockUpdate(final Position position) {
if (!noteBlockUpdates.containsKey(position)) {
return null;
}
int relativeBlockState = noteBlockUpdates.removeInt(position) - 249;
relativeBlockState = relativeBlockState / 2; // Get rid of powered state
return new Pair<>(relativeBlockState / MAX_NOTE_ID + 1, relativeBlockState % MAX_NOTE_ID + 1);
}
public void clear() {
noteBlockUpdates.clear();
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -20,7 +20,4 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage;
import com.viaversion.viabackwards.api.entities.storage.PlayerPositionStorage;
public class PlayerPositionStorage1_13 extends PlayerPositionStorage {
public PlayerPositionStorage1_13() {
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -39,7 +39,7 @@ public class InventoryPackets1_13_2 {
@Override
public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.ITEM1_13_2_SHORT_ARRAY, Type.ITEM1_13_ARRAY); // 1 - Window Values
map(Type.ITEM1_13_2_SHORT_ARRAY, Type.ITEM1_13_SHORT_ARRAY); // 1 - Window Values
}
});
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -25,7 +25,12 @@ import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLi
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
import com.viaversion.viaversion.api.minecraft.chunks.*;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLight;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLightImpl;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.api.minecraft.item.Item;
@@ -42,15 +47,14 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.RecipeRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Key;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -60,7 +64,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
private EnchantmentRewriter enchantmentRewriter;
public BlockItemPackets1_14(Protocol1_13_2To1_14 protocol) {
super(protocol);
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY);
}
@Override
@@ -143,7 +147,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
if (title.isJsonObject() && (object = title.getAsJsonObject()).has("translate")) {
// Don't rewrite other 9x3 translatable containers
if (type != 2 || object.getAsJsonPrimitive("translate").getAsString().equals("container.barrel")) {
title = ChatRewriter.legacyTextToJson(containerTitle);
title = ComponentUtil.legacyToJson(containerTitle);
}
}
}
@@ -166,9 +170,9 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
BlockRewriter<ClientboundPackets1_14> blockRewriter = BlockRewriter.legacy(protocol);
registerSetCooldown(ClientboundPackets1_14.COOLDOWN);
registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.ITEM1_13_2);
registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS);
registerSetSlot(ClientboundPackets1_14.SET_SLOT);
registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS);
// Trade List -> Plugin Message
protocol.registerClientbound(ClientboundPackets1_14.TRADE_LIST, ClientboundPackets1_13.PLUGIN_MESSAGE, wrapper -> {
@@ -289,8 +293,8 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
});
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION);
protocol.registerClientbound(ClientboundPackets1_14.BLOCK_BREAK_ANIMATION, new PacketHandlers() {
@Override
@@ -432,7 +436,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
}
});
registerSpawnParticle(ClientboundPackets1_14.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.FLOAT);
registerSpawnParticle(ClientboundPackets1_14.SPAWN_PARTICLE, Type.FLOAT);
protocol.registerClientbound(ClientboundPackets1_14.MAP_DATA, new PacketHandlers() {
@Override
@@ -468,8 +472,8 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
// Lore now uses JSON
CompoundTag tag = item.tag();
CompoundTag display;
if (tag != null && (display = tag.get("display")) != null) {
ListTag lore = display.get("Lore");
if (tag != null && (display = tag.getCompoundTag("display")) != null) {
ListTag lore = display.getListTag("Lore");
if (lore != null) {
saveListTag(display, lore, "Lore");
@@ -479,7 +483,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
StringTag loreEntryTag = (StringTag) loreEntry;
String value = loreEntryTag.getValue();
if (value != null && !value.isEmpty()) {
loreEntryTag.setValue(ChatRewriter.jsonToLegacyText(value));
loreEntryTag.setValue(ComponentUtil.jsonToLegacy(value));
}
}
}
@@ -496,14 +500,14 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
// Lore now uses JSON
CompoundTag tag = item.tag();
CompoundTag display;
if (tag != null && (display = tag.get("display")) != null) {
if (tag != null && (display = tag.getCompoundTag("display")) != null) {
// Transform to json if no backup tag is found (else process that in the super method)
ListTag lore = display.get("Lore");
ListTag lore = display.getListTag("Lore");
if (lore != null && !hasBackupTag(display, "Lore")) {
for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) {
StringTag loreEntryTag = (StringTag) loreEntry;
loreEntryTag.setValue(ChatRewriter.legacyTextToJsonString(loreEntryTag.getValue()));
loreEntryTag.setValue(ComponentUtil.legacyToJsonString(loreEntryTag.getValue()));
}
}
}
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -349,7 +349,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
});
registerMetaTypeHandler(Types1_13_2.META_TYPES.itemType, Types1_13_2.META_TYPES.blockStateType, null, null,
Types1_13_2.META_TYPES.componentType, Types1_13_2.META_TYPES.optionalComponentType);
Types1_13_2.META_TYPES.componentType, Types1_13_2.META_TYPES.optionalComponentType);
filter().type(EntityTypes1_14.PILLAGER).cancel(15);
@@ -394,7 +394,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
}
});
filter().filterFamily(EntityTypes1_14.ABSTRACT_ARROW).removeIndex(9);
filter().type(EntityTypes1_14.ABSTRACT_ARROW).removeIndex(9);
filter().type(EntityTypes1_14.VILLAGER).cancel(15); // Head shake timer
@@ -410,23 +410,23 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
filter().type(EntityTypes1_14.VILLAGER).index(16).handler(villagerDataHandler);
// Holding arms up - from bitfield into own boolean
filter().filterFamily(EntityTypes1_14.ABSTRACT_SKELETON).index(13).handler((event, meta) -> {
filter().type(EntityTypes1_14.ABSTRACT_SKELETON).index(13).handler((event, meta) -> {
byte value = (byte) meta.getValue();
if ((value & 4) != 0) {
event.createExtraMeta(new Metadata(14, Types1_13_2.META_TYPES.booleanType, true));
}
});
filter().filterFamily(EntityTypes1_14.ZOMBIE).index(13).handler((event, meta) -> {
filter().type(EntityTypes1_14.ZOMBIE).index(13).handler((event, meta) -> {
byte value = (byte) meta.getValue();
if ((value & 4) != 0) {
event.createExtraMeta(new Metadata(16, Types1_13_2.META_TYPES.booleanType, true));
}
});
filter().filterFamily(EntityTypes1_14.ZOMBIE).addIndex(16);
filter().type(EntityTypes1_14.ZOMBIE).addIndex(16);
// Remove bed location
filter().filterFamily(EntityTypes1_14.LIVINGENTITY).handler((event, meta) -> {
filter().type(EntityTypes1_14.LIVINGENTITY).handler((event, meta) -> {
int index = event.index();
if (index == 12) {
Position position = (Position) meta.getValue();
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
@@ -1,6 +1,6 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2023 ViaVersion and contributors
* 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
Loaded 100 of 213 files, more files were not shown because too many files have changed in this diff. Show more