Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22daa60eb6 | ||
|
|
6eca07966c | ||
|
|
56cc711c01 | ||
|
|
c2ee558235 | ||
|
|
c8a010c390 | ||
|
|
53c54485eb | ||
|
|
f42a308f2c | ||
|
|
44250cbb99 | ||
|
|
55ffe72198 | ||
|
|
a47dd2ecdb | ||
|
|
8a5233b6a1 | ||
|
|
c8a1279e75 | ||
|
|
57ef90e851 | ||
|
|
2262681351 | ||
|
|
56e1d0a69d | ||
|
|
63ffb51df5 | ||
|
|
b33bd2ac2b | ||
|
|
1afff77a0f | ||
|
|
26af09f2a4 | ||
|
|
a8e475dbf0 | ||
|
|
6388021c6d | ||
|
|
f4aa96a5f8 | ||
|
|
6baae5e4f7 | ||
|
|
189b244a3a | ||
|
|
12d538fe0d | ||
|
|
34f0dbf642 | ||
|
|
548f80bb7c | ||
|
|
9113a77331 | ||
|
|
e3e85db02a | ||
|
|
c4d9209c81 | ||
|
|
24d887a53d | ||
|
|
702ced200e | ||
|
|
40f5cb6e71 | ||
|
|
7ab0c41be6 | ||
|
|
66b21431f2 | ||
|
|
c6cd655f7e | ||
|
|
e9bccda259 | ||
|
|
9a34ff2a51 | ||
|
|
f01d9408de | ||
|
|
15ff7b4c9d | ||
|
|
d47765ce45 | ||
|
|
b82b067745 | ||
|
|
b7005f2400 | ||
|
|
312fe3a851 | ||
|
|
69d50fa992 | ||
|
|
1308dcb8dd | ||
|
|
b4ecba8382 | ||
|
|
3529d6a229 | ||
|
|
4213c4cce5 | ||
|
|
3d3e09977c | ||
|
|
90feac8c83 | ||
|
|
80a807e366 | ||
|
|
3eba8ba922 | ||
|
|
71a68bf36e | ||
|
|
e67501cde3 | ||
|
|
9aa7f5e879 | ||
|
|
854ecf0b47 | ||
|
|
f538f25d63 | ||
|
|
48a7fdc1d1 | ||
|
|
1d5ae0e3e0 | ||
|
|
f0462085d3 | ||
|
|
7dc7b62cc9 | ||
|
|
b9f80754e0 | ||
|
|
5b9f775743 | ||
|
|
0e66228a96 | ||
|
|
8df48bc378 | ||
|
|
d36d5d6def | ||
|
|
8b51430555 | ||
|
|
f71288e299 | ||
|
|
c0fc8195ce | ||
|
|
dd189411e6 | ||
|
|
4693b95bea | ||
|
|
596a42e312 | ||
|
|
71944be482 | ||
|
|
d1699fbb8d | ||
|
|
bd880b608f | ||
|
|
3386431749 | ||
|
|
c3fc8b5f18 | ||
|
|
ec740476da | ||
|
|
a536ad1d10 | ||
|
|
a1ae7818a2 | ||
|
|
365b3a8a38 | ||
|
|
823eb1f392 | ||
|
|
a12dfa405f | ||
|
|
9798ec296a | ||
|
|
c1b993c01b | ||
|
|
f55696a605 |
No files matched your search
@@ -1,5 +1,6 @@
|
||||
name: Feature Request
|
||||
description: Suggest a feature to be added
|
||||
labels: [Feature Request]
|
||||
|
||||
body:
|
||||
- type: textarea
|
||||
@@ -34,4 +35,4 @@ body:
|
||||
description: |
|
||||
Does the feature apply to any specific version or environment?
|
||||
validations:
|
||||
required: false
|
||||
required: false
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
Supported Versions:
|
||||
|
||||

|
||||

|
||||
|
||||
On Paper you may also use ProtocolSupport, but ensure you have the right build for your server version.
|
||||
|
||||
|
||||
@@ -83,6 +83,8 @@ public class ProtocolVersion {
|
||||
public static final ProtocolVersion v1_17_1 = register(756, "1.17.1");
|
||||
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new VersionRange("1.18", 0, 1));
|
||||
public static final ProtocolVersion v1_18_2 = register(758, "1.18.2");
|
||||
public static final ProtocolVersion v1_19 = register(759, "1.19");
|
||||
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1");
|
||||
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
|
||||
|
||||
public static ProtocolVersion register(int version, String name) {
|
||||
|
||||
@@ -64,7 +64,7 @@ public interface ViaAPI<T> {
|
||||
* @return API version incremented with meaningful API changes
|
||||
*/
|
||||
default int apiVersion() {
|
||||
return 10;
|
||||
return 13;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,4 +29,13 @@ package com.viaversion.viaversion.api.connection;
|
||||
* @see UserConnection#put(StorableObject)
|
||||
*/
|
||||
public interface StorableObject {
|
||||
|
||||
/**
|
||||
* Returns whether the object should be uncached on a server switch.
|
||||
*
|
||||
* @return whether the object should be uncached on a server switch
|
||||
*/
|
||||
default boolean clearOnServerSwitch() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,15 @@ public interface UserConnection {
|
||||
*/
|
||||
boolean has(Class<? extends StorableObject> objectClass);
|
||||
|
||||
/**
|
||||
* Removes and returns an object from the storage.
|
||||
*
|
||||
* @param objectClass class of the object to get
|
||||
* @param <T> type of the class you want to get
|
||||
* @return removed storable object if present
|
||||
*/
|
||||
@Nullable <T extends StorableObject> T remove(Class<T> objectClass);
|
||||
|
||||
/**
|
||||
* Put an object into the stored objects based on class.
|
||||
*
|
||||
@@ -83,6 +92,7 @@ public interface UserConnection {
|
||||
|
||||
/**
|
||||
* Adds an entity tracker to the user connection.
|
||||
* Does not override existing entity trackers.
|
||||
*
|
||||
* @param protocolClass protocol class
|
||||
* @param tracker entity tracker
|
||||
@@ -91,9 +101,18 @@ public interface UserConnection {
|
||||
|
||||
/**
|
||||
* Clear stored objects and entity trackers.
|
||||
* Used for Bungee when switching servers.
|
||||
*/
|
||||
void clearStoredObjects();
|
||||
default void clearStoredObjects() {
|
||||
clearStoredObjects(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear stored objects and entity trackers.
|
||||
* If cleared for a proxy server switch, some stored objects and tracker data will be retained.
|
||||
*
|
||||
* @param isServerSwitch whether the clear is due to a server switch
|
||||
*/
|
||||
void clearStoredObjects(boolean isServerSwitch);
|
||||
|
||||
/**
|
||||
* Sends a raw packet to the connection on the current thread.
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.data;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Mappings containing the full string identifier mappings.
|
||||
*/
|
||||
public interface FullMappings {
|
||||
|
||||
Mappings mappings();
|
||||
|
||||
/**
|
||||
* Returns the unmapped integer id for the given identifier, or -1 if not found.
|
||||
*
|
||||
* @param identifier unmapped string identifier
|
||||
* @return unmapped int id, or -1 if not found
|
||||
*/
|
||||
int id(String identifier);
|
||||
|
||||
/**
|
||||
* Returns the mapped integer id for the given mapped identifier, or -1 if not found.
|
||||
*
|
||||
* @param mappedIdentifier mapped string identifier
|
||||
* @return mapped int id, or -1 if not found
|
||||
*/
|
||||
int mappedId(String mappedIdentifier);
|
||||
|
||||
/**
|
||||
* Returns the unmapped string identifier for the given mapped id.
|
||||
*
|
||||
* @param id unmapped id
|
||||
* @return unmapped string identifier
|
||||
*/
|
||||
String identifier(int id);
|
||||
|
||||
/**
|
||||
* Returns the mapped string identifier for the given mapped id.
|
||||
*
|
||||
* @param mappedId mapped id
|
||||
* @return mapped string identifier
|
||||
*/
|
||||
String mappedIdentifier(int mappedId);
|
||||
|
||||
/**
|
||||
* Returns the mapped string identifier for the given unmapped identifier.
|
||||
*
|
||||
* @param identifier unmapped identifier
|
||||
* @return mapped string identifier, or null if not found
|
||||
*/
|
||||
@Nullable String mappedIdentifier(String identifier);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.data;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class FullMappingsBase implements FullMappings {
|
||||
private final Object2IntMap<String> stringToId;
|
||||
private final Object2IntMap<String> mappedStringToId;
|
||||
private final String[] idToString;
|
||||
private final String[] mappedIdToString;
|
||||
private final Mappings mappings;
|
||||
|
||||
public FullMappingsBase(final JsonArray oldMappings, final JsonArray newMappings, final Mappings mappings) {
|
||||
this.mappings = mappings;
|
||||
stringToId = MappingDataLoader.arrayToMap(oldMappings);
|
||||
mappedStringToId = MappingDataLoader.arrayToMap(newMappings);
|
||||
stringToId.defaultReturnValue(-1);
|
||||
mappedStringToId.defaultReturnValue(-1);
|
||||
|
||||
idToString = new String[oldMappings.size()];
|
||||
for (int i = 0; i < oldMappings.size(); i++) {
|
||||
idToString[i] = oldMappings.get(i).getAsString();
|
||||
}
|
||||
|
||||
mappedIdToString = new String[newMappings.size()];
|
||||
for (int i = 0; i < newMappings.size(); i++) {
|
||||
mappedIdToString[i] = newMappings.get(i).getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mappings mappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int id(final String identifier) {
|
||||
return stringToId.getInt(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int mappedId(final String mappedIdentifier) {
|
||||
return mappedStringToId.getInt(mappedIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier(final int id) {
|
||||
return idToString[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mappedIdentifier(final int mappedId) {
|
||||
return mappedIdToString[mappedId];
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String mappedIdentifier(final String identifier) {
|
||||
final int id = id(identifier);
|
||||
if (id == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int mappedId = mappings.getNewId(id);
|
||||
return mappedId != -1 ? mappedIdentifier(mappedId) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.data;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
public class Int2IntMapMappings implements Mappings {
|
||||
private final Int2IntMap mappings;
|
||||
private final int mappedIds;
|
||||
|
||||
protected Int2IntMapMappings(final Int2IntMap mappings, final int mappedIds) {
|
||||
this.mappings = mappings;
|
||||
this.mappedIds = mappedIds;
|
||||
mappings.defaultReturnValue(-1);
|
||||
}
|
||||
|
||||
public static Int2IntMapMappings of(final Int2IntMap mappings, final int mappedIds) {
|
||||
return new Int2IntMapMappings(mappings, mappedIds);
|
||||
}
|
||||
|
||||
public static Int2IntMapMappings of() {
|
||||
|
||||
return new Int2IntMapMappings(new Int2IntOpenHashMap(), -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewId(final int id) {
|
||||
return mappings.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNewId(final int id, final int newId) {
|
||||
mappings.put(id, newId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return mappings.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int mappedSize() {
|
||||
return mappedIds;
|
||||
}
|
||||
}
|
||||
@@ -102,4 +102,12 @@ public interface MappingData {
|
||||
@Nullable Mappings getSoundMappings();
|
||||
|
||||
@Nullable Mappings getStatisticsMappings();
|
||||
|
||||
@Nullable Mappings getEnchantmentMappings();
|
||||
|
||||
@Nullable FullMappings getEntityMappings();
|
||||
|
||||
@Nullable FullMappings getArgumentTypeMappings();
|
||||
|
||||
@Nullable Mappings getPaintingMappings();
|
||||
}
|
||||
@@ -44,12 +44,16 @@ public class MappingDataBase implements MappingData {
|
||||
protected final String newVersion;
|
||||
protected final boolean hasDiffFile;
|
||||
protected Int2IntBiMap itemMappings;
|
||||
protected FullMappings argumentTypeMappings;
|
||||
protected FullMappings entityMappings;
|
||||
protected ParticleMappings particleMappings;
|
||||
protected Mappings blockMappings;
|
||||
protected Mappings blockStateMappings;
|
||||
protected Mappings blockEntityMappings;
|
||||
protected Mappings soundMappings;
|
||||
protected Mappings statisticsMappings;
|
||||
protected Mappings enchantmentMappings;
|
||||
protected Mappings paintingMappings;
|
||||
protected Map<RegistryType, List<TagData>> tags;
|
||||
protected boolean loadItems = true;
|
||||
|
||||
@@ -75,6 +79,11 @@ public class MappingDataBase implements MappingData {
|
||||
blockEntityMappings = loadFromArray(oldMappings, newMappings, diffmapping, "blockentities");
|
||||
soundMappings = loadFromArray(oldMappings, newMappings, diffmapping, "sounds");
|
||||
statisticsMappings = loadFromArray(oldMappings, newMappings, diffmapping, "statistics");
|
||||
enchantmentMappings = loadFromArray(oldMappings, newMappings, diffmapping, "enchantments");
|
||||
paintingMappings = loadFromArray(oldMappings, newMappings, diffmapping, "paintings");
|
||||
|
||||
entityMappings = loadFullMappings(oldMappings, newMappings, diffmapping, "entities");
|
||||
argumentTypeMappings = loadFullMappings(oldMappings, newMappings, diffmapping, "argumenttypes");
|
||||
|
||||
Mappings particles = loadFromArray(oldMappings, newMappings, diffmapping, "particles");
|
||||
if (particles != null) {
|
||||
@@ -102,6 +111,11 @@ public class MappingDataBase implements MappingData {
|
||||
loadExtras(oldMappings, newMappings, diffmapping);
|
||||
}
|
||||
|
||||
protected FullMappings loadFullMappings(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
|
||||
Mappings mappings = loadFromArray(oldMappings, newMappings, diffMappings, key);
|
||||
return mappings != null ? new FullMappingsBase(oldMappings.getAsJsonArray(key), newMappings.getAsJsonArray(key), mappings) : null;
|
||||
}
|
||||
|
||||
private void loadTags(RegistryType type, JsonObject object, Object2IntMap<String> typeMapping) {
|
||||
JsonObject tags = object.getAsJsonObject(type.resourceLocation());
|
||||
List<TagData> tagsList = new ArrayList<>(tags.size());
|
||||
@@ -148,7 +162,7 @@ public class MappingDataBase implements MappingData {
|
||||
|
||||
@Override
|
||||
public int getNewParticleId(int id) {
|
||||
return checkValidity(id, particleMappings.getMappings().getNewId(id), "particles");
|
||||
return checkValidity(id, particleMappings.mappings().getNewId(id), "particles");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,6 +205,26 @@ public class MappingDataBase implements MappingData {
|
||||
return statisticsMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getEnchantmentMappings() {
|
||||
return enchantmentMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FullMappings getEntityMappings() {
|
||||
return entityMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FullMappings getArgumentTypeMappings() {
|
||||
return argumentTypeMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getPaintingMappings() {
|
||||
return paintingMappings;
|
||||
}
|
||||
|
||||
protected @Nullable Mappings loadFromArray(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
|
||||
if (!oldMappings.has(key) || !newMappings.has(key)) return null;
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ public class MappingDataLoader {
|
||||
mapIdentifiers(output, oldIdentifiers, newIdentifiers, diffIdentifiers, true);
|
||||
}
|
||||
|
||||
private static int mapIdentifierEntry(Map.Entry<String, JsonElement> entry, Object2IntMap newIdentifierMap, @Nullable JsonObject diffIdentifiers, boolean warnOnMissing) {
|
||||
private static int mapIdentifierEntry(Map.Entry<String, JsonElement> entry, Object2IntMap<String> newIdentifierMap, @Nullable JsonObject diffIdentifiers, boolean warnOnMissing) {
|
||||
int value = newIdentifierMap.getInt(entry.getValue().getAsString());
|
||||
if (value == -1) {
|
||||
// Search in diff mappings
|
||||
|
||||
@@ -38,6 +38,28 @@ public interface Mappings {
|
||||
*/
|
||||
int getNewId(int id);
|
||||
|
||||
/**
|
||||
* Returns the mapped id from the given id, or the given default if unmapped/invalid.
|
||||
*
|
||||
* @param id unmapped id
|
||||
* @param def fallback return value
|
||||
* @return mapped id, or -1 if invalid/out of bounds
|
||||
*/
|
||||
default int getNewIdOrDefault(int id, int def) {
|
||||
final int mappedId = getNewId(id);
|
||||
return mappedId != -1 ? mappedId : def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the id has a mapping.
|
||||
*
|
||||
* @param id unmapped id
|
||||
* @return whether the id has a mapped id
|
||||
*/
|
||||
default boolean contains(int id) {
|
||||
return getNewId(id) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually maps a specific id.
|
||||
*
|
||||
|
||||
@@ -25,51 +25,19 @@ package com.viaversion.viaversion.api.data;
|
||||
import com.google.gson.JsonArray;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
|
||||
public class ParticleMappings {
|
||||
private final Object2IntMap<String> stringToId;
|
||||
private final Object2IntMap<String> mappedStringToId;
|
||||
private final Mappings mappings;
|
||||
public class ParticleMappings extends FullMappingsBase {
|
||||
private final IntList itemParticleIds = new IntArrayList(2);
|
||||
private final IntList blockParticleIds = new IntArrayList(4);
|
||||
|
||||
public ParticleMappings(JsonArray oldMappings, JsonArray newMappings, Mappings mappings) {
|
||||
this.mappings = mappings;
|
||||
stringToId = MappingDataLoader.arrayToMap(oldMappings);
|
||||
mappedStringToId = MappingDataLoader.arrayToMap(newMappings);
|
||||
stringToId.defaultReturnValue(-1);
|
||||
mappedStringToId.defaultReturnValue(-1);
|
||||
super(oldMappings, newMappings, mappings);
|
||||
addBlockParticle("block");
|
||||
addBlockParticle("falling_dust");
|
||||
addBlockParticle("block_marker");
|
||||
addItemParticle("item");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unmapped integer id for the given identifier, or -1 if not found.
|
||||
*
|
||||
* @param identifier unmapped string identifier
|
||||
* @return unmapped int id, or -1 if not found
|
||||
*/
|
||||
public int id(String identifier) {
|
||||
return stringToId.getInt(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mapped integer id for the given mapped identifier, or -1 if not found.
|
||||
*
|
||||
* @param mappedIdentifier mapped string identifier
|
||||
* @return mapped int id, or -1 if not found
|
||||
*/
|
||||
public int mappedId(String mappedIdentifier) {
|
||||
return mappedStringToId.getInt(mappedIdentifier);
|
||||
}
|
||||
|
||||
public Mappings getMappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
public boolean addItemParticle(final String identifier) {
|
||||
final int id = id(identifier);
|
||||
return id != -1 && itemParticleIds.add(id);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.data.entity;
|
||||
|
||||
public interface DimensionData {
|
||||
|
||||
int minY();
|
||||
|
||||
int height();
|
||||
}
|
||||
@@ -26,6 +26,8 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface EntityTracker {
|
||||
|
||||
/**
|
||||
@@ -151,4 +153,18 @@ public interface EntityTracker {
|
||||
int biomesSent();
|
||||
|
||||
void setBiomesSent(int biomesSent);
|
||||
|
||||
EntityType playerType();
|
||||
|
||||
@Nullable DimensionData dimensionData(String dimension);
|
||||
|
||||
void setDimensions(Map<String, DimensionData> dimensions);
|
||||
|
||||
/**
|
||||
* Adds the client player entity to the tracker.
|
||||
* If the client entity has not been set yet, this will return false.
|
||||
*
|
||||
* @return whether the client has been tracked
|
||||
*/
|
||||
boolean trackClientEntity();
|
||||
}
|
||||
@@ -51,6 +51,15 @@ public interface StoredEntityData {
|
||||
*/
|
||||
@Nullable <T> T get(Class<T> objectClass);
|
||||
|
||||
/**
|
||||
* Removes and returns an object from the storage if present.
|
||||
*
|
||||
* @param objectClass class of the object to remove
|
||||
* @param <T> object type
|
||||
* @return removed object if present
|
||||
*/
|
||||
@Nullable <T> T remove(Class<T> objectClass);
|
||||
|
||||
/**
|
||||
* Stores an object based on its class.
|
||||
*
|
||||
|
||||
@@ -22,8 +22,12 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.debug;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
|
||||
@Beta
|
||||
public interface DebugHandler {
|
||||
|
||||
/**
|
||||
@@ -47,6 +51,14 @@ public interface DebugHandler {
|
||||
*/
|
||||
void addPacketTypeNameToLog(String packetTypeName);
|
||||
|
||||
/**
|
||||
* Adds a packet id to the list of packet types to log.
|
||||
* Packets will be checked on each protocol transformer, so this is best used on single protocol pipes.
|
||||
*
|
||||
* @param packetType packet type
|
||||
*/
|
||||
void addPacketTypeToLog(PacketType packetType);
|
||||
|
||||
/**
|
||||
* Removes a packet type name from the list of packet types to log.
|
||||
*
|
||||
@@ -78,8 +90,16 @@ public interface DebugHandler {
|
||||
* Returns whether the given packet should be logged.
|
||||
* If no specific packet type has been added, all packet types will be logged.
|
||||
*
|
||||
* @param wrapper packet wrapper
|
||||
* @param wrapper packet wrapper
|
||||
* @param direction packet direction
|
||||
* @return whether the packet should be logged
|
||||
*/
|
||||
boolean shouldLog(PacketWrapper wrapper);
|
||||
boolean shouldLog(PacketWrapper wrapper, Direction direction);
|
||||
|
||||
default void enableAndLogIds(final PacketType... packetTypes) {
|
||||
setEnabled(true);
|
||||
for (final PacketType packetType : packetTypes) {
|
||||
addPacketTypeToLog(packetType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public final class GlobalPosition extends Position {
|
||||
private final String dimension;
|
||||
|
||||
public GlobalPosition(final String dimension, final int x, final int y, final int z) {
|
||||
super(x, y, z);
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public String dimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final GlobalPosition position = (GlobalPosition) o;
|
||||
if (x != position.x) return false;
|
||||
if (y != position.y) return false;
|
||||
if (z != position.z) return false;
|
||||
return dimension.equals(position.dimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = dimension.hashCode();
|
||||
result = 31 * result + x;
|
||||
result = 31 * result + y;
|
||||
result = 31 * result + z;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GlobalPosition{" +
|
||||
"dimension='" + dimension + '\'' +
|
||||
", x=" + x +
|
||||
", y=" + y +
|
||||
", z=" + z +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+13
-17
@@ -20,28 +20,24 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
|
||||
public class OptPositionType extends Type<Position> {
|
||||
public OptPositionType() {
|
||||
super(Position.class);
|
||||
public final class PlayerMessageSignature {
|
||||
private final UUID uuid;
|
||||
private final byte[] signatureBytes;
|
||||
|
||||
public PlayerMessageSignature(final UUID uuid, final byte[] signatureBytes) {
|
||||
this.uuid = uuid;
|
||||
this.signatureBytes = signatureBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position read(ByteBuf buffer) throws Exception {
|
||||
boolean present = buffer.readBoolean();
|
||||
if (!present) return null;
|
||||
return Type.POSITION.read(buffer);
|
||||
public UUID uuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Position object) throws Exception {
|
||||
buffer.writeBoolean(object != null);
|
||||
if (object != null)
|
||||
Type.POSITION.write(buffer, object);
|
||||
public byte[] signatureBytes() {
|
||||
return signatureBytes;
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,9 @@
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public class Position {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
protected final int x;
|
||||
protected final int y;
|
||||
protected final int z;
|
||||
|
||||
public Position(int x, int y, int z) {
|
||||
this.x = x;
|
||||
@@ -59,6 +59,10 @@ public class Position {
|
||||
return z;
|
||||
}
|
||||
|
||||
public GlobalPosition withDimension(String dimension) {
|
||||
return new GlobalPosition(dimension, x, y, z);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public int getX() {
|
||||
return x;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public class Position3d {
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
|
||||
public Position3d(final double x, final double y, final double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public double x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double z() {
|
||||
return z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public final class ProfileKey {
|
||||
private final long expiresAt;
|
||||
private final byte[] publicKey;
|
||||
private final byte[] keySignature;
|
||||
|
||||
public ProfileKey(final long expiresAt, final byte[] publicKey, final byte[] keySignature) {
|
||||
this.expiresAt = expiresAt;
|
||||
this.publicKey = publicKey;
|
||||
this.keySignature = keySignature;
|
||||
}
|
||||
|
||||
public long expiresAt() {
|
||||
return expiresAt;
|
||||
}
|
||||
|
||||
public byte[] publicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public byte[] keySignature() {
|
||||
return keySignature;
|
||||
}
|
||||
}
|
||||
+10
@@ -170,6 +170,16 @@ public class Entity1_10Types {
|
||||
public EntityType getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return id != -1;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ObjectType implements com.viaversion.viaversion.api.minecraft.entities.ObjectType {
|
||||
|
||||
+10
@@ -187,6 +187,16 @@ public class Entity1_11Types {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return id != -1;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
|
||||
+10
@@ -191,6 +191,16 @@ public class Entity1_12Types {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return id != -1;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
|
||||
+10
@@ -240,6 +240,16 @@ public class Entity1_13Types {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return id != -1;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
|
||||
+10
@@ -224,6 +224,16 @@ public enum Entity1_14Types implements EntityType {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return id != -1;
|
||||
}
|
||||
|
||||
static {
|
||||
TYPES = EntityTypeUtil.toOrderedArray(values());
|
||||
}
|
||||
|
||||
+10
@@ -226,6 +226,16 @@ public enum Entity1_15Types implements EntityType {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return id != -1;
|
||||
}
|
||||
|
||||
static {
|
||||
TYPES = EntityTypeUtil.toOrderedArray(values());
|
||||
}
|
||||
|
||||
+10
@@ -231,6 +231,16 @@ public enum Entity1_16Types implements EntityType {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return id != -1;
|
||||
}
|
||||
|
||||
static {
|
||||
TYPES = EntityTypeUtil.toOrderedArray(values());
|
||||
}
|
||||
|
||||
+10
@@ -235,6 +235,16 @@ public enum Entity1_16_2Types implements EntityType {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return id != -1;
|
||||
}
|
||||
|
||||
static {
|
||||
TYPES = EntityTypeUtil.toOrderedArray(values());
|
||||
}
|
||||
|
||||
+10
@@ -240,6 +240,16 @@ public enum Entity1_17Types implements EntityType {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return id != -1;
|
||||
}
|
||||
|
||||
static {
|
||||
TYPES = EntityTypeUtil.toOrderedArray(values());
|
||||
}
|
||||
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum Entity1_19Types implements EntityType {
|
||||
|
||||
ENTITY(null, null),
|
||||
|
||||
AREA_EFFECT_CLOUD(ENTITY),
|
||||
END_CRYSTAL(ENTITY),
|
||||
EVOKER_FANGS(ENTITY),
|
||||
EXPERIENCE_ORB(ENTITY),
|
||||
EYE_OF_ENDER(ENTITY),
|
||||
FALLING_BLOCK(ENTITY),
|
||||
FIREWORK_ROCKET(ENTITY),
|
||||
ITEM(ENTITY),
|
||||
LLAMA_SPIT(ENTITY),
|
||||
TNT(ENTITY),
|
||||
SHULKER_BULLET(ENTITY),
|
||||
FISHING_BOBBER(ENTITY),
|
||||
|
||||
LIVINGENTITY(ENTITY, null),
|
||||
ARMOR_STAND(LIVINGENTITY),
|
||||
MARKER(ENTITY),
|
||||
PLAYER(LIVINGENTITY),
|
||||
|
||||
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
|
||||
ENDER_DRAGON(ABSTRACT_INSENTIENT),
|
||||
|
||||
BEE(ABSTRACT_INSENTIENT),
|
||||
|
||||
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
|
||||
|
||||
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
|
||||
VILLAGER(ABSTRACT_AGEABLE),
|
||||
WANDERING_TRADER(ABSTRACT_AGEABLE),
|
||||
|
||||
// Animals
|
||||
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
|
||||
AXOLOTL(ABSTRACT_ANIMAL),
|
||||
DOLPHIN(ABSTRACT_INSENTIENT),
|
||||
CHICKEN(ABSTRACT_ANIMAL),
|
||||
COW(ABSTRACT_ANIMAL),
|
||||
MOOSHROOM(COW),
|
||||
PANDA(ABSTRACT_INSENTIENT),
|
||||
PIG(ABSTRACT_ANIMAL),
|
||||
POLAR_BEAR(ABSTRACT_ANIMAL),
|
||||
RABBIT(ABSTRACT_ANIMAL),
|
||||
SHEEP(ABSTRACT_ANIMAL),
|
||||
TURTLE(ABSTRACT_ANIMAL),
|
||||
FOX(ABSTRACT_ANIMAL),
|
||||
FROG(ABSTRACT_ANIMAL),
|
||||
GOAT(ABSTRACT_ANIMAL),
|
||||
|
||||
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
|
||||
CAT(ABSTRACT_TAMEABLE_ANIMAL),
|
||||
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
|
||||
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
|
||||
|
||||
ABSTRACT_PARROT(ABSTRACT_TAMEABLE_ANIMAL, null),
|
||||
PARROT(ABSTRACT_PARROT),
|
||||
|
||||
// Horses
|
||||
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
|
||||
CHESTED_HORSE(ABSTRACT_HORSE, null),
|
||||
DONKEY(CHESTED_HORSE),
|
||||
MULE(CHESTED_HORSE),
|
||||
LLAMA(CHESTED_HORSE),
|
||||
TRADER_LLAMA(CHESTED_HORSE),
|
||||
HORSE(ABSTRACT_HORSE),
|
||||
SKELETON_HORSE(ABSTRACT_HORSE),
|
||||
ZOMBIE_HORSE(ABSTRACT_HORSE),
|
||||
|
||||
// Golem
|
||||
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
|
||||
SNOW_GOLEM(ABSTRACT_GOLEM),
|
||||
IRON_GOLEM(ABSTRACT_GOLEM),
|
||||
SHULKER(ABSTRACT_GOLEM),
|
||||
|
||||
// Fish
|
||||
ABSTRACT_FISHES(ABSTRACT_CREATURE, null),
|
||||
COD(ABSTRACT_FISHES),
|
||||
PUFFERFISH(ABSTRACT_FISHES),
|
||||
SALMON(ABSTRACT_FISHES),
|
||||
TROPICAL_FISH(ABSTRACT_FISHES),
|
||||
|
||||
// Monsters
|
||||
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
|
||||
BLAZE(ABSTRACT_MONSTER),
|
||||
CREEPER(ABSTRACT_MONSTER),
|
||||
ENDERMITE(ABSTRACT_MONSTER),
|
||||
ENDERMAN(ABSTRACT_MONSTER),
|
||||
GIANT(ABSTRACT_MONSTER),
|
||||
SILVERFISH(ABSTRACT_MONSTER),
|
||||
VEX(ABSTRACT_MONSTER),
|
||||
WITCH(ABSTRACT_MONSTER),
|
||||
WITHER(ABSTRACT_MONSTER),
|
||||
RAVAGER(ABSTRACT_MONSTER),
|
||||
|
||||
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
|
||||
|
||||
PIGLIN(ABSTRACT_PIGLIN),
|
||||
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
|
||||
|
||||
HOGLIN(ABSTRACT_ANIMAL),
|
||||
STRIDER(ABSTRACT_ANIMAL),
|
||||
TADPOLE(ABSTRACT_FISHES),
|
||||
ZOGLIN(ABSTRACT_MONSTER),
|
||||
WARDEN(ABSTRACT_MONSTER),
|
||||
|
||||
// Illagers
|
||||
ABSTRACT_ILLAGER_BASE(ABSTRACT_MONSTER, null),
|
||||
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
|
||||
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
|
||||
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER),
|
||||
VINDICATOR(ABSTRACT_ILLAGER_BASE),
|
||||
PILLAGER(ABSTRACT_ILLAGER_BASE),
|
||||
|
||||
// Skeletons
|
||||
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
|
||||
SKELETON(ABSTRACT_SKELETON),
|
||||
STRAY(ABSTRACT_SKELETON),
|
||||
WITHER_SKELETON(ABSTRACT_SKELETON),
|
||||
|
||||
// Guardians
|
||||
GUARDIAN(ABSTRACT_MONSTER),
|
||||
ELDER_GUARDIAN(GUARDIAN),
|
||||
|
||||
// Spiders
|
||||
SPIDER(ABSTRACT_MONSTER),
|
||||
CAVE_SPIDER(SPIDER),
|
||||
|
||||
// Zombies
|
||||
ZOMBIE(ABSTRACT_MONSTER),
|
||||
DROWNED(ZOMBIE),
|
||||
HUSK(ZOMBIE),
|
||||
ZOMBIFIED_PIGLIN(ZOMBIE),
|
||||
ZOMBIE_VILLAGER(ZOMBIE),
|
||||
|
||||
// Flying entities
|
||||
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
|
||||
GHAST(ABSTRACT_FLYING),
|
||||
PHANTOM(ABSTRACT_FLYING),
|
||||
|
||||
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
|
||||
BAT(ABSTRACT_AMBIENT),
|
||||
ALLAY(ABSTRACT_CREATURE),
|
||||
|
||||
ABSTRACT_WATERMOB(ABSTRACT_INSENTIENT, null),
|
||||
SQUID(ABSTRACT_WATERMOB),
|
||||
GLOW_SQUID(SQUID),
|
||||
|
||||
// Slimes
|
||||
SLIME(ABSTRACT_INSENTIENT),
|
||||
MAGMA_CUBE(SLIME),
|
||||
|
||||
// Hangable objects
|
||||
ABSTRACT_HANGING(ENTITY, null),
|
||||
LEASH_KNOT(ABSTRACT_HANGING),
|
||||
ITEM_FRAME(ABSTRACT_HANGING),
|
||||
GLOW_ITEM_FRAME(ITEM_FRAME),
|
||||
PAINTING(ABSTRACT_HANGING),
|
||||
|
||||
ABSTRACT_LIGHTNING(ENTITY, null),
|
||||
LIGHTNING_BOLT(ABSTRACT_LIGHTNING),
|
||||
|
||||
// Arrows
|
||||
ABSTRACT_ARROW(ENTITY, null),
|
||||
ARROW(ABSTRACT_ARROW),
|
||||
SPECTRAL_ARROW(ABSTRACT_ARROW),
|
||||
TRIDENT(ABSTRACT_ARROW),
|
||||
|
||||
// Fireballs
|
||||
ABSTRACT_FIREBALL(ENTITY, null),
|
||||
DRAGON_FIREBALL(ABSTRACT_FIREBALL),
|
||||
FIREBALL(ABSTRACT_FIREBALL),
|
||||
SMALL_FIREBALL(ABSTRACT_FIREBALL),
|
||||
WITHER_SKULL(ABSTRACT_FIREBALL),
|
||||
|
||||
// Projectiles
|
||||
PROJECTILE_ABSTRACT(ENTITY, null),
|
||||
SNOWBALL(PROJECTILE_ABSTRACT),
|
||||
ENDER_PEARL(PROJECTILE_ABSTRACT),
|
||||
EGG(PROJECTILE_ABSTRACT),
|
||||
POTION(PROJECTILE_ABSTRACT),
|
||||
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
|
||||
|
||||
// Vehicles
|
||||
MINECART_ABSTRACT(ENTITY, null),
|
||||
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
|
||||
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
|
||||
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
|
||||
MINECART(MINECART_ABSTRACT),
|
||||
FURNACE_MINECART(MINECART_ABSTRACT),
|
||||
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
|
||||
TNT_MINECART(MINECART_ABSTRACT),
|
||||
SPAWNER_MINECART(MINECART_ABSTRACT),
|
||||
BOAT(ENTITY),
|
||||
CHEST_BOAT(BOAT);
|
||||
|
||||
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
|
||||
private final EntityType parent;
|
||||
private final String identifier;
|
||||
private int id = -1;
|
||||
|
||||
Entity1_19Types(final EntityType parent) {
|
||||
this.parent = parent;
|
||||
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
Entity1_19Types(final EntityType parent, @Nullable final String identifier) {
|
||||
this.parent = parent;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
if (id == -1) {
|
||||
throw new IllegalStateException("Ids have not been initialized yet (type " + name() + ")");
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
Preconditions.checkArgument(identifier != null, "Called identifier method on abstract type");
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable EntityType getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return identifier == null;
|
||||
}
|
||||
|
||||
public static EntityType getTypeFromId(final int typeId) {
|
||||
return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY);
|
||||
}
|
||||
|
||||
public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
|
||||
for (final Entity1_19Types type : values()) {
|
||||
if (type.isAbstractType()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int id = protocol.getMappingData().getEntityMappings().mappedId(type.identifier());
|
||||
Preconditions.checkArgument(id != -1, "Entity type %s has no id", type.identifier());
|
||||
type.id = id;
|
||||
}
|
||||
EntityTypeUtil.fill(values(), TYPES);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ public interface EntityType {
|
||||
* Returns the entity id.
|
||||
*
|
||||
* @return entity id
|
||||
* @throws IllegalStateException if ids have not been loaded yet
|
||||
*/
|
||||
int getId();
|
||||
|
||||
@@ -47,6 +48,22 @@ public interface EntityType {
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Returns the entity's Vanilla identifier.
|
||||
*
|
||||
* @return entity identifier
|
||||
* @throws IllegalArgumentException if {@link #isAbstractType()} returns true
|
||||
*/
|
||||
String identifier();
|
||||
|
||||
/**
|
||||
* Returns whether the type does not represent an actual entity, e.g. animal or monster.
|
||||
*
|
||||
* @return whether the type does not represent an actual entity
|
||||
*/
|
||||
boolean isAbstractType();
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default boolean is(EntityType... types) {
|
||||
for (EntityType type : types) {
|
||||
if (this == type) {
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
||||
|
||||
public final class MetaTypes1_19 extends AbstractMetaTypes {
|
||||
|
||||
public final MetaType byteType = add(0, Type.BYTE);
|
||||
public final MetaType varIntType = add(1, Type.VAR_INT);
|
||||
public final MetaType floatType = add(2, Type.FLOAT);
|
||||
public final MetaType stringType = add(3, Type.STRING);
|
||||
public final MetaType componentType = add(4, Type.COMPONENT);
|
||||
public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT);
|
||||
public final MetaType itemType = add(6, Type.FLAT_VAR_INT_ITEM);
|
||||
public final MetaType booleanType = add(7, Type.BOOLEAN);
|
||||
public final MetaType rotationType = add(8, Type.ROTATION);
|
||||
public final MetaType positionType = add(9, Type.POSITION1_14);
|
||||
public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION_1_14);
|
||||
public final MetaType directionType = add(11, Type.VAR_INT);
|
||||
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID);
|
||||
public final MetaType blockStateType = add(13, Type.VAR_INT);
|
||||
public final MetaType nbtType = add(14, Type.NBT);
|
||||
public final MetaType particleType;
|
||||
public final MetaType villagerDatatType = add(16, Type.VILLAGER_DATA);
|
||||
public final MetaType optionalVarIntType = add(17, Type.OPTIONAL_VAR_INT);
|
||||
public final MetaType poseType = add(18, Type.VAR_INT);
|
||||
public final MetaType catVariantType = add(19, Type.VAR_INT);
|
||||
public final MetaType frogVariantType = add(20, Type.VAR_INT);
|
||||
public final MetaType optionalGlobalPosition = add(21, Type.OPTIONAL_GLOBAL_POSITION);
|
||||
public final MetaType paintingVariantType = add(22, Type.VAR_INT);
|
||||
|
||||
public MetaTypes1_19(final ParticleType particleType) {
|
||||
super(23);
|
||||
this.particleType = add(15, particleType);
|
||||
}
|
||||
}
|
||||
@@ -218,4 +218,12 @@ public interface ViaPlatform<T> {
|
||||
default Collection<UnsupportedSoftware> getUnsupportedSoftwareClasses() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the platform has a plugin/mod with the given name (even if disabled).
|
||||
*
|
||||
* @param name plugin or identifier
|
||||
* @return whether the platform has a plugin/mod with the given name
|
||||
*/
|
||||
boolean hasPlugin(String name);
|
||||
}
|
||||
@@ -351,7 +351,7 @@ public abstract class AbstractProtocol<C1 extends ClientboundPacketType, C2 exte
|
||||
throw e;
|
||||
}
|
||||
|
||||
private String toNiceHex(int id) {
|
||||
public static String toNiceHex(int id) {
|
||||
String hex = Integer.toHexString(id).toUpperCase();
|
||||
return (hex.length() == 1 ? "0x0" : "0x") + hex;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,8 @@ public class ProtocolVersion {
|
||||
public static final ProtocolVersion v1_17_1 = register(756, "1.17.1");
|
||||
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new VersionRange("1.18", 0, 1));
|
||||
public static final ProtocolVersion v1_18_2 = register(758, "1.18.2");
|
||||
public static final ProtocolVersion v1_19 = register(759, "1.19");
|
||||
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1");
|
||||
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
|
||||
|
||||
public static ProtocolVersion register(int version, String name) {
|
||||
|
||||
@@ -49,6 +49,9 @@ public abstract class RewriterBase<T extends Protocol> implements Rewriter<T> {
|
||||
protected void registerRewrites() {
|
||||
}
|
||||
|
||||
public void onMappingDataLoaded() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public T protocol() {
|
||||
return protocol;
|
||||
|
||||
@@ -24,13 +24,15 @@ package com.viaversion.viaversion.api.type;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ByteBufReader<T> {
|
||||
|
||||
/**
|
||||
* Read a value from a ByteBuf
|
||||
* Reads a value from a ByteBuf.
|
||||
*
|
||||
* @param buffer The buffer to read from.
|
||||
* @return The type based on the class type.
|
||||
* @throws Exception Throws exception if it failed reading.
|
||||
* @param buffer buffer to read from
|
||||
* @return type based on the class type
|
||||
* @throws Exception if it failed reading
|
||||
*/
|
||||
T read(ByteBuf buffer) throws Exception;
|
||||
}
|
||||
@@ -24,13 +24,15 @@ package com.viaversion.viaversion.api.type;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ByteBufWriter<T> {
|
||||
|
||||
/**
|
||||
* Write an object to a type to a ByteBuf
|
||||
* Writes an object to a type to a ByteBuf.
|
||||
*
|
||||
* @param buffer The buffer to write to
|
||||
* @param object The object to write
|
||||
* @throws Exception Throws if it failed to write
|
||||
* @param buffer buffer to write to
|
||||
* @param value value to write
|
||||
* @throws Exception if it failed to write
|
||||
*/
|
||||
void write(ByteBuf buffer, T object) throws Exception;
|
||||
void write(ByteBuf buffer, T value) throws Exception;
|
||||
}
|
||||
+13
-13
@@ -20,31 +20,31 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
package com.viaversion.viaversion.api.type;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class OptionalComponentType extends Type<JsonElement> {
|
||||
public abstract class OptionalType<T> extends Type<T> {
|
||||
private final Type<T> type;
|
||||
|
||||
public OptionalComponentType() {
|
||||
super(JsonElement.class);
|
||||
protected OptionalType(final Type<T> type) {
|
||||
super(type.getOutputClass());
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement read(ByteBuf buffer) throws Exception {
|
||||
boolean present = buffer.readBoolean();
|
||||
return present ? Type.COMPONENT.read(buffer) : null;
|
||||
public @Nullable T read(ByteBuf buffer) throws Exception {
|
||||
return buffer.readBoolean() ? type.read(buffer) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, JsonElement object) throws Exception {
|
||||
if (object == null) {
|
||||
public void write(final ByteBuf buffer, @Nullable final T value) throws Exception {
|
||||
if (value == null) {
|
||||
buffer.writeBoolean(false);
|
||||
} else {
|
||||
buffer.writeBoolean(true);
|
||||
Type.COMPONENT.write(buffer, object);
|
||||
type.write(buffer, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,10 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.EulerAngle;
|
||||
import com.viaversion.viaversion.api.minecraft.GlobalPosition;
|
||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector;
|
||||
import com.viaversion.viaversion.api.minecraft.VillagerData;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
@@ -59,16 +62,15 @@ import com.viaversion.viaversion.api.type.types.minecraft.FlatItemArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.FlatItemType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.FlatVarIntItemArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.FlatVarIntItemType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.GlobalPositionType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ItemArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ItemType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.NBTType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.OptPosition1_14Type;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.OptPositionType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.OptUUIDType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.OptionalComponentType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.OptionalVarIntType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.PlayerMessageSignatureType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.Position1_14Type;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.PositionType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ProfileKeyType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.VarLongBlockChangeRecordType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.VectorType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.VillagerDataType;
|
||||
@@ -102,15 +104,17 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
|
||||
/* Other Types */
|
||||
public static final Type<JsonElement> COMPONENT = new ComponentType();
|
||||
public static final Type<JsonElement> OPTIONAL_COMPONENT = new OptionalComponentType();
|
||||
public static final Type<JsonElement> OPTIONAL_COMPONENT = new ComponentType.OptionalComponentType();
|
||||
|
||||
public static final Type<String> STRING = new StringType();
|
||||
public static final Type<String> OPTIONAL_STRING = new StringType.OptionalStringType();
|
||||
public static final Type<String[]> STRING_ARRAY = new ArrayType<>(Type.STRING);
|
||||
|
||||
public static final Type<UUID> UUID = new UUIDType();
|
||||
public static final Type<UUID> OPTIONAL_UUID = new OptUUIDType();
|
||||
public static final Type<UUID> UUID_INT_ARRAY = new UUIDIntArrayType();
|
||||
public static final Type<UUID> OPTIONAL_UUID = new UUIDType.OptionalUUIDType();
|
||||
public static final Type<UUID[]> UUID_ARRAY = new ArrayType<>(Type.UUID);
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public static final Type<UUID> UUID_INT_ARRAY = new UUIDIntArrayType();
|
||||
|
||||
public static final VarIntType VAR_INT = new VarIntType();
|
||||
public static final OptionalVarIntType OPTIONAL_VAR_INT = new OptionalVarIntType();
|
||||
@@ -146,14 +150,16 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
|
||||
/* MC Types */
|
||||
public static final Type<Position> POSITION = new PositionType();
|
||||
public static final Type<Position> OPTIONAL_POSITION = new PositionType.OptionalPositionType();
|
||||
public static final Type<Position> POSITION1_14 = new Position1_14Type();
|
||||
public static final Type<Position> OPTIONAL_POSITION_1_14 = new Position1_14Type.OptionalPosition1_14Type();
|
||||
public static final Type<EulerAngle> ROTATION = new EulerAngleType();
|
||||
public static final Type<Vector> VECTOR = new VectorType();
|
||||
public static final Type<CompoundTag> NBT = new NBTType();
|
||||
public static final Type<CompoundTag[]> NBT_ARRAY = new ArrayType<>(Type.NBT);
|
||||
|
||||
public static final Type<Position> OPTIONAL_POSITION = new OptPositionType();
|
||||
public static final Type<Position> OPTIONAL_POSITION_1_14 = new OptPosition1_14Type();
|
||||
public static final Type<GlobalPosition> GLOBAL_POSITION = new GlobalPositionType();
|
||||
public static final Type<GlobalPosition> OPTIONAL_GLOBAL_POSITION = new GlobalPositionType.OptionalGlobalPositionType();
|
||||
|
||||
public static final Type<BlockChangeRecord> BLOCK_CHANGE_RECORD = new BlockChangeRecordType();
|
||||
public static final Type<BlockChangeRecord[]> BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.BLOCK_CHANGE_RECORD);
|
||||
@@ -166,6 +172,13 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
public static final Type<Item> ITEM = new ItemType();
|
||||
public static final Type<Item[]> ITEM_ARRAY = new ItemArrayType();
|
||||
|
||||
public static final Type<ProfileKey> PROFILE_KEY = new ProfileKeyType();
|
||||
public static final Type<ProfileKey> OPTIONAL_PROFILE_KEY = new ProfileKeyType.OptionalProfileKeyType();
|
||||
|
||||
public static final Type<PlayerMessageSignature> PLAYER_MESSAGE_SIGNATURE = new PlayerMessageSignatureType();
|
||||
public static final Type<PlayerMessageSignature> OPTIONAL_PLAYER_MESSAGE_SIGNATURE = new PlayerMessageSignatureType.OptionalPlayerMessageSignatureType();
|
||||
public static final Type<PlayerMessageSignature[]> PLAYER_MESSAGE_SIGNATURE_ARRAY = new ArrayType<>(PLAYER_MESSAGE_SIGNATURE);
|
||||
|
||||
/* 1.13 Flat Item (no data) */
|
||||
public static final Type<Item> FLAT_ITEM = new FlatItemType();
|
||||
public static final Type<Item> FLAT_VAR_INT_ITEM = new FlatVarIntItemType();
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@@ -51,4 +52,11 @@ public class ComponentType extends Type<JsonElement> {
|
||||
public void write(ByteBuf buffer, JsonElement object) throws Exception {
|
||||
STRING_TAG.write(buffer, object.toString());
|
||||
}
|
||||
|
||||
public static final class OptionalComponentType extends OptionalType<JsonElement> {
|
||||
|
||||
public OptionalComponentType() {
|
||||
super(Type.COMPONENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class LongArrayType extends Type<long[]> {
|
||||
int length = Type.VAR_INT.readPrimitive(buffer);
|
||||
long[] array = new long[length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = Type.LONG.readPrimitive(buffer);
|
||||
array[i] = buffer.readLong();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class LongArrayType extends Type<long[]> {
|
||||
public void write(ByteBuf buffer, long[] object) throws Exception {
|
||||
Type.VAR_INT.writePrimitive(buffer, object.length);
|
||||
for (long l : object) {
|
||||
Type.LONG.writePrimitive(buffer, l);
|
||||
buffer.writeLong(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.type.types;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@@ -67,4 +68,11 @@ public class StringType extends Type<String> {
|
||||
Type.VAR_INT.writePrimitive(buffer, b.length);
|
||||
buffer.writeBytes(b);
|
||||
}
|
||||
|
||||
public static final class OptionalStringType extends OptionalType<String> {
|
||||
|
||||
public OptionalStringType() {
|
||||
super(Type.STRING);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,14 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types;
|
||||
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDType extends Type<UUID> {
|
||||
|
||||
public UUIDType() {
|
||||
super(UUID.class);
|
||||
}
|
||||
@@ -42,4 +44,11 @@ public class UUIDType extends Type<UUID> {
|
||||
buffer.writeLong(object.getMostSignificantBits());
|
||||
buffer.writeLong(object.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
public static final class OptionalUUIDType extends OptionalType<UUID> {
|
||||
|
||||
public OptionalUUIDType() {
|
||||
super(Type.UUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,40 +28,37 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class VarIntType extends Type<Integer> implements TypeConverter<Integer> {
|
||||
|
||||
private static final int CONTINUE_BIT = 0x80;
|
||||
private static final int VALUE_BITS = 0x7F;
|
||||
private static final int MULTI_BYTE_BITS = ~VALUE_BITS;
|
||||
private static final int MAX_BYTES = 5;
|
||||
|
||||
public VarIntType() {
|
||||
super("VarInt", Integer.class);
|
||||
}
|
||||
|
||||
public int readPrimitive(ByteBuf buffer) {
|
||||
int out = 0;
|
||||
int value = 0;
|
||||
int bytes = 0;
|
||||
byte in;
|
||||
do {
|
||||
in = buffer.readByte();
|
||||
|
||||
out |= (in & 0x7F) << (bytes++ * 7);
|
||||
|
||||
if (bytes > 5) { // 5 is maxBytes
|
||||
value |= (in & VALUE_BITS) << (bytes++ * 7);
|
||||
if (bytes > MAX_BYTES) {
|
||||
throw new RuntimeException("VarInt too big");
|
||||
}
|
||||
|
||||
} while ((in & 0x80) == 0x80);
|
||||
return out;
|
||||
} while ((in & CONTINUE_BIT) == CONTINUE_BIT);
|
||||
return value;
|
||||
}
|
||||
|
||||
public void writePrimitive(ByteBuf buffer, int object) {
|
||||
int part;
|
||||
do {
|
||||
part = object & 0x7F;
|
||||
public void writePrimitive(ByteBuf buffer, int value) {
|
||||
while ((value & MULTI_BYTE_BITS) != 0) {
|
||||
buffer.writeByte((value & VALUE_BITS) | CONTINUE_BIT);
|
||||
value >>>= 7;
|
||||
}
|
||||
|
||||
object >>>= 7;
|
||||
if (object != 0) {
|
||||
part |= 0x80;
|
||||
}
|
||||
|
||||
buffer.writeByte(part);
|
||||
|
||||
} while (object != 0);
|
||||
buffer.writeByte(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-2
@@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class FlatItemType extends BaseItemType {
|
||||
public FlatItemType() {
|
||||
@@ -33,7 +34,7 @@ public class FlatItemType extends BaseItemType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item read(ByteBuf buffer) throws Exception {
|
||||
public @Nullable Item read(ByteBuf buffer) throws Exception {
|
||||
short id = buffer.readShort();
|
||||
if (id < 0) {
|
||||
return null;
|
||||
@@ -47,7 +48,7 @@ public class FlatItemType extends BaseItemType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item object) throws Exception {
|
||||
public void write(ByteBuf buffer, @Nullable Item object) throws Exception {
|
||||
if (object == null) {
|
||||
buffer.writeShort(-1);
|
||||
} else {
|
||||
|
||||
+3
-2
@@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class FlatVarIntItemType extends BaseItemType {
|
||||
public FlatVarIntItemType() {
|
||||
@@ -32,7 +33,7 @@ public class FlatVarIntItemType extends BaseItemType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item read(ByteBuf buffer) throws Exception {
|
||||
public @Nullable Item read(ByteBuf buffer) throws Exception {
|
||||
boolean present = buffer.readBoolean();
|
||||
if (!present) {
|
||||
return null;
|
||||
@@ -46,7 +47,7 @@ public class FlatVarIntItemType extends BaseItemType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item object) throws Exception {
|
||||
public void write(ByteBuf buffer, @Nullable Item object) throws Exception {
|
||||
if (object == null) {
|
||||
buffer.writeBoolean(false);
|
||||
} else {
|
||||
|
||||
+17
-15
@@ -22,31 +22,33 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.GlobalPosition;
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.UUID;
|
||||
public class GlobalPositionType extends Type<GlobalPosition> {
|
||||
|
||||
public class OptUUIDType extends Type<UUID> {
|
||||
public OptUUIDType() {
|
||||
super(UUID.class);
|
||||
public GlobalPositionType() {
|
||||
super(GlobalPosition.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID read(ByteBuf buffer) {
|
||||
boolean present = buffer.readBoolean();
|
||||
if (!present) return null;
|
||||
return new UUID(buffer.readLong(), buffer.readLong());
|
||||
public GlobalPosition read(ByteBuf buffer) throws Exception {
|
||||
final String dimension = Type.STRING.read(buffer);
|
||||
return Type.POSITION1_14.read(buffer).withDimension(dimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, UUID object) {
|
||||
if (object == null) {
|
||||
buffer.writeBoolean(false);
|
||||
} else {
|
||||
buffer.writeBoolean(true);
|
||||
buffer.writeLong(object.getMostSignificantBits());
|
||||
buffer.writeLong(object.getLeastSignificantBits());
|
||||
public void write(ByteBuf buffer, GlobalPosition object) throws Exception {
|
||||
Type.STRING.write(buffer, object.dimension());
|
||||
Type.POSITION1_14.write(buffer, object);
|
||||
}
|
||||
|
||||
public static final class OptionalGlobalPositionType extends OptionalType<GlobalPosition> {
|
||||
|
||||
public OptionalGlobalPositionType() {
|
||||
super(Type.GLOBAL_POSITION);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ItemType extends BaseItemType {
|
||||
public ItemType() {
|
||||
@@ -32,7 +33,7 @@ public class ItemType extends BaseItemType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item read(ByteBuf buffer) throws Exception {
|
||||
public @Nullable Item read(ByteBuf buffer) throws Exception {
|
||||
short id = buffer.readShort();
|
||||
if (id < 0) {
|
||||
return null;
|
||||
@@ -47,7 +48,7 @@ public class ItemType extends BaseItemType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Item object) throws Exception {
|
||||
public void write(ByteBuf buffer, @Nullable Item object) throws Exception {
|
||||
if (object == null) {
|
||||
buffer.writeShort(-1);
|
||||
} else {
|
||||
|
||||
+10
-7
@@ -26,20 +26,23 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class OptionalVarIntType extends Type<Integer> {
|
||||
|
||||
public OptionalVarIntType() {
|
||||
super(Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer read(ByteBuf buffer) throws Exception {
|
||||
int read = Type.VAR_INT.readPrimitive(buffer);
|
||||
if (read == 0) return null;
|
||||
return read - 1;
|
||||
public Integer read(final ByteBuf buffer) throws Exception {
|
||||
final int value = Type.VAR_INT.readPrimitive(buffer);
|
||||
return value == 0 ? null : value - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Integer object) throws Exception {
|
||||
if (object == null) Type.VAR_INT.writePrimitive(buffer, 0);
|
||||
else Type.VAR_INT.writePrimitive(buffer, object + 1);
|
||||
public void write(final ByteBuf buffer, final Integer object) throws Exception {
|
||||
if (object == null) {
|
||||
Type.VAR_INT.writePrimitive(buffer, 0);
|
||||
} else {
|
||||
Type.VAR_INT.writePrimitive(buffer, object + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,12 @@ public class ParticleType extends Type<Particle> {
|
||||
}
|
||||
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks
|
||||
};
|
||||
public static final ParticleReader SCULK_CHARGE = (buf, particle) -> {
|
||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Roll
|
||||
};
|
||||
public static final ParticleReader SHRIEK = (buf, particle) -> {
|
||||
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Delay
|
||||
};
|
||||
}
|
||||
|
||||
public final class ParticleTypeFiller {
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class PlayerMessageSignatureType extends Type<PlayerMessageSignature> {
|
||||
|
||||
public PlayerMessageSignatureType() {
|
||||
super(PlayerMessageSignature.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerMessageSignature read(final ByteBuf buffer) throws Exception {
|
||||
return new PlayerMessageSignature(Type.UUID.read(buffer), Type.BYTE_ARRAY_PRIMITIVE.read(buffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final PlayerMessageSignature value) throws Exception {
|
||||
Type.UUID.write(buffer, value.uuid());
|
||||
Type.BYTE_ARRAY_PRIMITIVE.write(buffer, value.signatureBytes());
|
||||
}
|
||||
|
||||
public static final class OptionalPlayerMessageSignatureType extends OptionalType<PlayerMessageSignature> {
|
||||
|
||||
public OptionalPlayerMessageSignatureType() {
|
||||
super(Type.PLAYER_MESSAGE_SIGNATURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@@ -48,4 +49,11 @@ public class Position1_14Type extends Type<Position> {
|
||||
| (object.y() & 0xfff)
|
||||
| ((((long) object.z()) & 0x3ffffff) << 12));
|
||||
}
|
||||
|
||||
public static final class OptionalPosition1_14Type extends OptionalType<Position> {
|
||||
|
||||
public OptionalPosition1_14Type() {
|
||||
super(Type.POSITION1_14);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@@ -48,4 +49,11 @@ public class PositionType extends Type<Position> {
|
||||
| ((((long) object.y()) & 0xfff) << 26)
|
||||
| (object.z() & 0x3ffffff));
|
||||
}
|
||||
|
||||
public static final class OptionalPositionType extends OptionalType<Position> {
|
||||
|
||||
public OptionalPositionType() {
|
||||
super(Type.POSITION);
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ProfileKeyType extends Type<ProfileKey> {
|
||||
|
||||
public ProfileKeyType() {
|
||||
super(ProfileKey.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileKey read(final ByteBuf buffer) throws Exception {
|
||||
return new ProfileKey(buffer.readLong(), Type.BYTE_ARRAY_PRIMITIVE.read(buffer), Type.BYTE_ARRAY_PRIMITIVE.read(buffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final ProfileKey object) throws Exception {
|
||||
buffer.writeLong(object.expiresAt());
|
||||
Type.BYTE_ARRAY_PRIMITIVE.write(buffer, object.publicKey());
|
||||
Type.BYTE_ARRAY_PRIMITIVE.write(buffer, object.keySignature());
|
||||
}
|
||||
|
||||
public static final class OptionalProfileKeyType extends OptionalType<ProfileKey> {
|
||||
|
||||
public OptionalProfileKeyType() {
|
||||
super(Type.PROFILE_KEY);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-15
@@ -41,8 +41,10 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
||||
int bitsPerBlock = buffer.readUnsignedByte();
|
||||
int originalBitsPerBlock = bitsPerBlock;
|
||||
|
||||
if (bitsPerBlock == 0 || bitsPerBlock > 8) {
|
||||
if (bitsPerBlock > 8) {
|
||||
bitsPerBlock = GLOBAL_PALETTE;
|
||||
} else if (bitsPerBlock < 4) {
|
||||
bitsPerBlock = 4;
|
||||
}
|
||||
|
||||
// Read palette
|
||||
@@ -58,18 +60,13 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
||||
}
|
||||
|
||||
// Read blocks
|
||||
long[] blockData = new long[Type.VAR_INT.readPrimitive(buffer)];
|
||||
long[] blockData = Type.LONG_ARRAY_PRIMITIVE.read(buffer);
|
||||
if (blockData.length > 0) {
|
||||
int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
|
||||
if (blockData.length != expectedLength) {
|
||||
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
|
||||
if (blockData.length == expectedLength) {
|
||||
CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData,
|
||||
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex);
|
||||
}
|
||||
|
||||
for (int i = 0; i < blockData.length; i++) {
|
||||
blockData[i] = buffer.readLong();
|
||||
}
|
||||
CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData,
|
||||
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex);
|
||||
}
|
||||
|
||||
return chunkSection;
|
||||
@@ -88,7 +85,7 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
||||
|
||||
buffer.writeByte(bitsPerBlock);
|
||||
|
||||
// Write pallet (or not)
|
||||
// Write palette
|
||||
if (bitsPerBlock != GLOBAL_PALETTE) {
|
||||
Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteSize());
|
||||
for (int i = 0; i < chunkSection.getPaletteSize(); i++) {
|
||||
@@ -98,9 +95,6 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
||||
|
||||
long[] data = CompactArrayUtil.createCompactArray(bitsPerBlock, ChunkSection.SIZE,
|
||||
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::getFlatBlock : chunkSection::getPaletteIndex);
|
||||
Type.VAR_INT.writePrimitive(buffer, data.length);
|
||||
for (long l : data) {
|
||||
buffer.writeLong(l);
|
||||
}
|
||||
Type.LONG_ARRAY_PRIMITIVE.write(buffer, data);
|
||||
}
|
||||
}
|
||||
+9
-15
@@ -41,8 +41,10 @@ public class ChunkSectionType1_16 extends Type<ChunkSection> {
|
||||
int bitsPerBlock = buffer.readUnsignedByte();
|
||||
int originalBitsPerBlock = bitsPerBlock;
|
||||
|
||||
if (bitsPerBlock == 0 || bitsPerBlock > 8) {
|
||||
if (bitsPerBlock > 8) {
|
||||
bitsPerBlock = GLOBAL_PALETTE;
|
||||
} else if (bitsPerBlock < 4) {
|
||||
bitsPerBlock = 4;
|
||||
}
|
||||
|
||||
// Read palette
|
||||
@@ -58,19 +60,14 @@ public class ChunkSectionType1_16 extends Type<ChunkSection> {
|
||||
}
|
||||
|
||||
// Read blocks
|
||||
long[] blockData = new long[Type.VAR_INT.readPrimitive(buffer)];
|
||||
long[] blockData = Type.LONG_ARRAY_PRIMITIVE.read(buffer);
|
||||
if (blockData.length > 0) {
|
||||
char valuesPerLong = (char) (64 / bitsPerBlock);
|
||||
int expectedLength = (ChunkSection.SIZE + valuesPerLong - 1) / valuesPerLong;
|
||||
if (blockData.length != expectedLength) {
|
||||
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
|
||||
if (blockData.length == expectedLength) {
|
||||
CompactArrayUtil.iterateCompactArrayWithPadding(bitsPerBlock, ChunkSection.SIZE, blockData,
|
||||
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex);
|
||||
}
|
||||
|
||||
for (int i = 0; i < blockData.length; i++) {
|
||||
blockData[i] = buffer.readLong();
|
||||
}
|
||||
CompactArrayUtil.iterateCompactArrayWithPadding(bitsPerBlock, ChunkSection.SIZE, blockData,
|
||||
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex);
|
||||
}
|
||||
|
||||
return chunkSection;
|
||||
@@ -89,7 +86,7 @@ public class ChunkSectionType1_16 extends Type<ChunkSection> {
|
||||
|
||||
buffer.writeByte(bitsPerBlock);
|
||||
|
||||
// Write pallet (or not)
|
||||
// Write palette
|
||||
if (bitsPerBlock != GLOBAL_PALETTE) {
|
||||
Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteSize());
|
||||
for (int i = 0; i < chunkSection.getPaletteSize(); i++) {
|
||||
@@ -99,9 +96,6 @@ public class ChunkSectionType1_16 extends Type<ChunkSection> {
|
||||
|
||||
long[] data = CompactArrayUtil.createCompactArrayWithPadding(bitsPerBlock, ChunkSection.SIZE,
|
||||
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::getFlatBlock : chunkSection::getPaletteIndex);
|
||||
Type.VAR_INT.writePrimitive(buffer, data.length);
|
||||
for (long l : data) {
|
||||
buffer.writeLong(l);
|
||||
}
|
||||
Type.LONG_ARRAY_PRIMITIVE.write(buffer, data);
|
||||
}
|
||||
}
|
||||
+7
-20
@@ -40,10 +40,6 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
||||
// Reaad bits per block
|
||||
int bitsPerBlock = buffer.readUnsignedByte();
|
||||
int originalBitsPerBlock = bitsPerBlock;
|
||||
|
||||
if (bitsPerBlock == 0) {
|
||||
bitsPerBlock = GLOBAL_PALETTE;
|
||||
}
|
||||
if (bitsPerBlock < 4) {
|
||||
bitsPerBlock = 4;
|
||||
}
|
||||
@@ -63,19 +59,14 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
||||
}
|
||||
|
||||
// Read blocks
|
||||
long[] blockData = new long[Type.VAR_INT.readPrimitive(buffer)];
|
||||
long[] blockData = Type.LONG_ARRAY_PRIMITIVE.read(buffer);
|
||||
if (blockData.length > 0) {
|
||||
int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
|
||||
if (blockData.length != expectedLength) {
|
||||
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
|
||||
if (blockData.length == expectedLength) {
|
||||
CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData,
|
||||
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock
|
||||
: chunkSection::setPaletteIndex);
|
||||
}
|
||||
|
||||
for (int i = 0; i < blockData.length; i++) {
|
||||
blockData[i] = buffer.readLong();
|
||||
}
|
||||
CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData,
|
||||
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock
|
||||
: chunkSection::setPaletteIndex);
|
||||
}
|
||||
|
||||
return chunkSection;
|
||||
@@ -92,10 +83,9 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
||||
bitsPerBlock = GLOBAL_PALETTE;
|
||||
}
|
||||
|
||||
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||
buffer.writeByte(bitsPerBlock);
|
||||
|
||||
// Write pallet (or not)
|
||||
// Write palette
|
||||
if (bitsPerBlock != GLOBAL_PALETTE) {
|
||||
Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteSize());
|
||||
for (int i = 0; i < chunkSection.getPaletteSize(); i++) {
|
||||
@@ -107,9 +97,6 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
||||
|
||||
long[] data = CompactArrayUtil.createCompactArray(bitsPerBlock, ChunkSection.SIZE,
|
||||
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::getFlatBlock : chunkSection::getPaletteIndex);
|
||||
Type.VAR_INT.writePrimitive(buffer, data.length);
|
||||
for (long l : data) {
|
||||
buffer.writeLong(l);
|
||||
}
|
||||
Type.LONG_ARRAY_PRIMITIVE.write(buffer, data);
|
||||
}
|
||||
}
|
||||
+24
-32
@@ -42,23 +42,25 @@ public final class PaletteType1_18 extends Type<DataPalette> {
|
||||
|
||||
@Override
|
||||
public DataPalette read(final ByteBuf buffer) throws Exception {
|
||||
int bitsPerValue = buffer.readByte();
|
||||
final int originalBitsPerValue = bitsPerValue;
|
||||
final int originalBitsPerValue = buffer.readByte();
|
||||
int bitsPerValue = originalBitsPerValue;
|
||||
|
||||
if (bitsPerValue > type.highestBitsPerValue()) {
|
||||
bitsPerValue = globalPaletteBits;
|
||||
}
|
||||
|
||||
// Read palette
|
||||
final DataPaletteImpl palette;
|
||||
if (bitsPerValue == 0) {
|
||||
//TODO Create proper singleton palette Object
|
||||
// Single value storage
|
||||
palette = new DataPaletteImpl(type.size(), 1);
|
||||
palette.addId(Type.VAR_INT.readPrimitive(buffer));
|
||||
Type.VAR_INT.readPrimitive(buffer); // 0 values length
|
||||
Type.LONG_ARRAY_PRIMITIVE.read(buffer); // Just eat it if not empty - thanks, Hypixel
|
||||
return palette;
|
||||
}
|
||||
|
||||
if (bitsPerValue < 0 || bitsPerValue > type.highestBitsPerValue()) {
|
||||
bitsPerValue = globalPaletteBits;
|
||||
} else if (type == PaletteType.BLOCKS && bitsPerValue < 4) {
|
||||
bitsPerValue = 4; // Linear block palette values are always 4 bits
|
||||
}
|
||||
|
||||
// Read palette
|
||||
if (bitsPerValue != globalPaletteBits) {
|
||||
final int paletteLength = Type.VAR_INT.readPrimitive(buffer);
|
||||
palette = new DataPaletteImpl(type.size(), paletteLength);
|
||||
@@ -70,38 +72,32 @@ public final class PaletteType1_18 extends Type<DataPalette> {
|
||||
}
|
||||
|
||||
// Read values
|
||||
final long[] values = new long[Type.VAR_INT.readPrimitive(buffer)];
|
||||
final long[] values = Type.LONG_ARRAY_PRIMITIVE.read(buffer);
|
||||
if (values.length > 0) {
|
||||
final char valuesPerLong = (char) (64 / bitsPerValue);
|
||||
final int valuesPerLong = (char) (64 / bitsPerValue);
|
||||
final int expectedLength = (type.size() + valuesPerLong - 1) / valuesPerLong;
|
||||
if (values.length != expectedLength) {
|
||||
throw new IllegalStateException("Palette data length (" + values.length + ") does not match expected length (" + expectedLength + ")! bitsPerValue=" + bitsPerValue + ", originalBitsPerValue=" + originalBitsPerValue);
|
||||
if (values.length == expectedLength) { // Thanks, Hypixel
|
||||
CompactArrayUtil.iterateCompactArrayWithPadding(bitsPerValue, type.size(), values,
|
||||
bitsPerValue == globalPaletteBits ? palette::setIdAt : palette::setPaletteIndexAt);
|
||||
}
|
||||
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = buffer.readLong();
|
||||
}
|
||||
CompactArrayUtil.iterateCompactArrayWithPadding(bitsPerValue, type.size(), values,
|
||||
bitsPerValue == globalPaletteBits ? palette::setIdAt : palette::setPaletteIndexAt);
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final DataPalette palette) throws Exception {
|
||||
if (palette.size() == 1) {
|
||||
final int size = palette.size();
|
||||
if (size == 1) {
|
||||
// Single value palette
|
||||
buffer.writeByte(0); // 0 bit storage
|
||||
Type.VAR_INT.writePrimitive(buffer, palette.idByIndex(0));
|
||||
Type.VAR_INT.writePrimitive(buffer, 0); // Empty values length
|
||||
return;
|
||||
}/* else if (palette.size() == 0) {
|
||||
Via.getPlatform().getLogger().warning("Palette size is 0!");
|
||||
}*/
|
||||
}
|
||||
|
||||
// 1, 2, and 3 bit linear block palettes can't be read by the client
|
||||
final int min = type == PaletteType.BLOCKS ? 4 : 1;
|
||||
int bitsPerValue = Math.max(min, MathUtil.ceilLog2(palette.size()));
|
||||
int bitsPerValue = Math.max(min, MathUtil.ceilLog2(size));
|
||||
if (bitsPerValue > type.highestBitsPerValue()) {
|
||||
bitsPerValue = globalPaletteBits;
|
||||
}
|
||||
@@ -109,17 +105,13 @@ public final class PaletteType1_18 extends Type<DataPalette> {
|
||||
buffer.writeByte(bitsPerValue);
|
||||
|
||||
if (bitsPerValue != globalPaletteBits) {
|
||||
// Write pallete
|
||||
Type.VAR_INT.writePrimitive(buffer, palette.size());
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
// Write palette
|
||||
Type.VAR_INT.writePrimitive(buffer, size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
Type.VAR_INT.writePrimitive(buffer, palette.idByIndex(i));
|
||||
}
|
||||
}
|
||||
|
||||
final long[] data = CompactArrayUtil.createCompactArrayWithPadding(bitsPerValue, type.size(), bitsPerValue == globalPaletteBits ? palette::idAt : palette::paletteIndexAt);
|
||||
Type.VAR_INT.writePrimitive(buffer, data.length);
|
||||
for (final long l : data) {
|
||||
buffer.writeLong(l);
|
||||
}
|
||||
Type.LONG_ARRAY_PRIMITIVE.write(buffer, CompactArrayUtil.createCompactArrayWithPadding(bitsPerValue, type.size(), bitsPerValue == globalPaletteBits ? palette::idAt : palette::paletteIndexAt));
|
||||
}
|
||||
}
|
||||
+11
-20
@@ -20,29 +20,20 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
package com.viaversion.viaversion.api.type.types.version;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes1_19;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.MetaListType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
||||
|
||||
public class OptPosition1_14Type extends Type<Position> {
|
||||
public OptPosition1_14Type() {
|
||||
super(Position.class);
|
||||
}
|
||||
import java.util.List;
|
||||
|
||||
@Override
|
||||
public Position read(ByteBuf buffer) throws Exception {
|
||||
boolean present = buffer.readBoolean();
|
||||
if (!present) return null;
|
||||
return Type.POSITION1_14.read(buffer);
|
||||
}
|
||||
public final class Types1_19 {
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Position object) throws Exception {
|
||||
buffer.writeBoolean(object != null);
|
||||
if (object != null) {
|
||||
Type.POSITION1_14.write(buffer, object);
|
||||
}
|
||||
}
|
||||
public static final ParticleType PARTICLE = new ParticleType(); // Only safe to use after protocol loading
|
||||
public static final MetaTypes1_19 META_TYPES = new MetaTypes1_19(PARTICLE);
|
||||
public static final Type<Metadata> METADATA = new MetadataType(META_TYPES);
|
||||
public static final Type<List<Metadata>> METADATA_LIST = new MetaListType(METADATA);
|
||||
}
|
||||
@@ -37,9 +37,9 @@ public class EntityTypeUtil {
|
||||
* @param values entity types
|
||||
* @return ordered array with each index representing the actual entity id
|
||||
*/
|
||||
public static EntityType[] toOrderedArray(EntityType[] values) {
|
||||
List<EntityType> types = new ArrayList<>();
|
||||
for (EntityType type : values) {
|
||||
public static EntityType[] toOrderedArray(final EntityType[] values) {
|
||||
final List<EntityType> types = new ArrayList<>();
|
||||
for (final EntityType type : values) {
|
||||
if (type.getId() != -1) {
|
||||
types.add(type);
|
||||
}
|
||||
@@ -49,6 +49,24 @@ public class EntityTypeUtil {
|
||||
return types.toArray(new EntityType[0]);
|
||||
}
|
||||
|
||||
public static EntityType[] createSizedArray(final EntityType[] values) {
|
||||
int count = 0;
|
||||
for (final EntityType type : values) {
|
||||
if (!type.isAbstractType()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return new EntityType[(int) count];
|
||||
}
|
||||
|
||||
public static void fill(final EntityType[] values, final EntityType[] toFill) {
|
||||
for (final EntityType type : values) {
|
||||
if (!type.isAbstractType()) {
|
||||
toFill[type.getId()] = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity type from id, or the given fallback if out of bounds.
|
||||
*
|
||||
@@ -57,8 +75,8 @@ public class EntityTypeUtil {
|
||||
* @param fallback fallback/base entity type
|
||||
* @return entity type from id
|
||||
*/
|
||||
public static EntityType getTypeFromId(EntityType[] values, int typeId, EntityType fallback) {
|
||||
EntityType type;
|
||||
public static EntityType getTypeFromId(final EntityType[] values, final int typeId, final EntityType fallback) {
|
||||
final EntityType type;
|
||||
if (typeId < 0 || typeId >= values.length || (type = values[typeId]) == null) {
|
||||
Via.getPlatform().getLogger().severe("Could not find " + fallback.getClass().getSimpleName() + " type id " + typeId);
|
||||
return fallback;
|
||||
|
||||
+3
-3
@@ -17,13 +17,13 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.bukkit.providers;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class BukkitBlockConnectionProvider extends BlockConnectionProvider {
|
||||
}
|
||||
|
||||
public Chunk getChunk(World world, int x, int z) {
|
||||
if (lastChunk != null && lastChunk.getX() == x && lastChunk.getZ() == z) {
|
||||
if (lastChunk != null && lastChunk.getWorld().equals(world) && lastChunk.getX() == x && lastChunk.getZ() == z) {
|
||||
return lastChunk;
|
||||
}
|
||||
return lastChunk = world.getChunkAt(x, z);
|
||||
|
||||
@@ -37,7 +37,8 @@ import com.viaversion.viaversion.bukkit.platform.BukkitViaLoader;
|
||||
import com.viaversion.viaversion.bukkit.platform.BukkitViaTask;
|
||||
import com.viaversion.viaversion.bukkit.util.NMSUtil;
|
||||
import com.viaversion.viaversion.dump.PluginInfo;
|
||||
import com.viaversion.viaversion.unsupported.UnsupportedSoftwareImpl;
|
||||
import com.viaversion.viaversion.unsupported.UnsupportedPlugin;
|
||||
import com.viaversion.viaversion.unsupported.UnsupportedServerSoftware;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -89,8 +90,8 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
||||
@Override
|
||||
public void onLoad() {
|
||||
// Via should load before PL, so we can't check for it in the constructor
|
||||
boolean hasProtocolLib = Bukkit.getPluginManager().getPlugin("ProtocolLib") != null;
|
||||
((BukkitViaInjector) Via.getManager().getInjector()).setProtocolLib(hasProtocolLib);
|
||||
Plugin protocolLib = Bukkit.getPluginManager().getPlugin("ProtocolLib");
|
||||
ProtocolLibEnableListener.checkCompat(protocolLib);
|
||||
|
||||
// Spigot detector
|
||||
try {
|
||||
@@ -286,14 +287,22 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
||||
@Override
|
||||
public final Collection<UnsupportedSoftware> getUnsupportedSoftwareClasses() {
|
||||
List<UnsupportedSoftware> list = new ArrayList<>(ViaPlatform.super.getUnsupportedSoftwareClasses());
|
||||
list.add(new UnsupportedSoftwareImpl.Builder().name("Yatopia").reason(UnsupportedSoftwareImpl.Reason.DANGEROUS_SERVER_SOFTWARE)
|
||||
list.add(new UnsupportedServerSoftware.Builder().name("Yatopia").reason(UnsupportedServerSoftware.Reason.DANGEROUS_SERVER_SOFTWARE)
|
||||
.addClassName("org.yatopiamc.yatopia.server.YatopiaConfig")
|
||||
.addClassName("net.yatopia.api.event.PlayerAttackEntityEvent")
|
||||
.addClassName("yatopiamc.org.yatopia.server.YatopiaConfig") // Only the best kind of software relocates its own classes to hide itself :tinfoilhat:
|
||||
.addMethod("org.bukkit.Server", "getLastTickTime").build());
|
||||
list.add(new UnsupportedPlugin.Builder().name("software to mess with message signing").reason(UnsupportedPlugin.Reason.SECURE_CHAT_BYPASS)
|
||||
.addPlugin("NoEncryption").addPlugin("NoReport")
|
||||
.addPlugin("NoChatReports").addPlugin("NoChatReport").build());
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlugin(final String name) {
|
||||
return getServer().getPluginManager().getPlugin(name) != null;
|
||||
}
|
||||
|
||||
public boolean isLateBind() {
|
||||
return lateBind;
|
||||
}
|
||||
|
||||
+20
-1
@@ -23,6 +23,8 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ProtocolLibEnableListener implements Listener {
|
||||
|
||||
@@ -30,7 +32,7 @@ public class ProtocolLibEnableListener implements Listener {
|
||||
public void onPluginEnable(PluginEnableEvent e) {
|
||||
// Will likely never happen, but try to account for hacky plugin loading systems anyways
|
||||
if (e.getPlugin().getName().equals("ProtocolLib")) {
|
||||
((BukkitViaInjector) Via.getManager().getInjector()).setProtocolLib(true);
|
||||
checkCompat(e.getPlugin());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,4 +42,21 @@ public class ProtocolLibEnableListener implements Listener {
|
||||
((BukkitViaInjector) Via.getManager().getInjector()).setProtocolLib(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkCompat(@Nullable Plugin protocolLib) {
|
||||
if (protocolLib != null) {
|
||||
String version = protocolLib.getDescription().getVersion();
|
||||
String majorVersion = version.split("\\.", 2)[0];
|
||||
try {
|
||||
// Only need the compat check for version < 5
|
||||
if (Integer.parseInt(majorVersion) < 5) {
|
||||
((BukkitViaInjector) Via.getManager().getInjector()).setProtocolLib(true);
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
Via.getPlatform().getLogger().warning("ProtocolLib version check failed for version " + version);
|
||||
}
|
||||
}
|
||||
((BukkitViaInjector) Via.getManager().getInjector()).setProtocolLib(false);
|
||||
}
|
||||
}
|
||||
@@ -32,12 +32,14 @@ import com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.BlockListener
|
||||
import com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.DeathListener;
|
||||
import com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.HandItemCache;
|
||||
import com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8.PaperPatch;
|
||||
import com.viaversion.viaversion.bukkit.providers.BukkitAckSequenceProvider;
|
||||
import com.viaversion.viaversion.bukkit.providers.BukkitBlockConnectionProvider;
|
||||
import com.viaversion.viaversion.bukkit.providers.BukkitInventoryQuickMoveProvider;
|
||||
import com.viaversion.viaversion.bukkit.providers.BukkitViaMovementTransmitter;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.provider.AckSequenceProvider;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -47,7 +49,6 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -174,6 +175,9 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
ConnectionData.blockConnectionProvider = blockConnectionProvider;
|
||||
}
|
||||
}
|
||||
if (serverProtocolVersion < ProtocolVersion.v1_19.getVersion()) {
|
||||
Via.getManager().getProviders().use(AckSequenceProvider.class, new BukkitAckSequenceProvider(plugin));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.bukkit.providers;
|
||||
|
||||
import com.viaversion.viaversion.ViaVersionPlugin;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.bukkit.tasks.protocol1_19to1_18_2.AckSequenceTask;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.provider.AckSequenceProvider;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.SequenceStorage;
|
||||
|
||||
public final class BukkitAckSequenceProvider extends AckSequenceProvider {
|
||||
|
||||
private final ViaVersionPlugin plugin;
|
||||
|
||||
public BukkitAckSequenceProvider(final ViaVersionPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSequence(final UserConnection connection, final int sequence) {
|
||||
final SequenceStorage sequenceStorage = connection.get(SequenceStorage.class);
|
||||
final int previousSequence = sequenceStorage.setSequenceId(sequence);
|
||||
if (previousSequence == -1) {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new AckSequenceTask(connection, sequenceStorage), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -84,14 +84,14 @@ public class BukkitViaMovementTransmitter extends MovementTransmitterProvider {
|
||||
public Object getFlyingPacket() {
|
||||
if (idlePacket == null)
|
||||
throw new NullPointerException("Could not locate flying packet");
|
||||
return idlePacket2;
|
||||
return idlePacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGroundPacket() {
|
||||
if (idlePacket == null)
|
||||
throw new NullPointerException("Could not locate flying packet");
|
||||
return idlePacket;
|
||||
return idlePacket2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.bukkit.tasks.protocol1_19to1_18_2;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.Protocol1_19To1_18_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage.SequenceStorage;
|
||||
|
||||
public final class AckSequenceTask implements Runnable {
|
||||
|
||||
private final UserConnection connection;
|
||||
private final SequenceStorage sequenceStorage;
|
||||
|
||||
public AckSequenceTask(final UserConnection connection, final SequenceStorage sequenceStorage) {
|
||||
this.connection = connection;
|
||||
this.sequenceStorage = sequenceStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final int sequence = sequenceStorage.setSequenceId(-1);
|
||||
try {
|
||||
final PacketWrapper ackPacket = PacketWrapper.create(ClientboundPackets1_19.BLOCK_CHANGED_ACK, connection);
|
||||
ackPacket.write(Type.VAR_INT, sequence);
|
||||
ackPacket.scheduleSend(Protocol1_19To1_18_2.class);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,5 +8,6 @@ loadbefore: [ProtocolLib, ProxyPipe, SpigotLib, SkinRestorer]
|
||||
softdepend: [ProtocolSupport, PacketListenerApi]
|
||||
commands:
|
||||
viaversion:
|
||||
permission: viaversion.admin # The permission is also referenced here to filter root suggestions (/via<tab>)
|
||||
description: Shows ViaVersion Version and more.
|
||||
aliases: [viaver, vvbukkit]
|
||||
@@ -56,7 +56,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>,
|
||||
@Override
|
||||
public void onLoad() {
|
||||
try {
|
||||
ProtocolConstants.class.getField("MINECRAFT_1_18");
|
||||
ProtocolConstants.class.getField("MINECRAFT_1_19");
|
||||
} catch (NoSuchFieldException e) {
|
||||
getLogger().warning(" / \\");
|
||||
getLogger().warning(" / \\");
|
||||
@@ -205,4 +205,9 @@ public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>,
|
||||
public boolean isOldClientsAllowed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlugin(final String name) {
|
||||
return getProxy().getPluginManager().getPlugin(name) != null;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class BungeeCommand extends Command implements TabExecutor {
|
||||
private final BungeeCommandHandler handler;
|
||||
|
||||
public BungeeCommand(BungeeCommandHandler handler) {
|
||||
super("viaversion", "", "viaver", "vvbungee"); // The CommandHandler will handle the permission
|
||||
super("viaversion", "viaversion.admin", "viaver", "vvbungee"); // The permission is also referenced here to filter root suggestions (/via<tab>)
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
|
||||
+7
-4
@@ -48,9 +48,12 @@ import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BungeeServerHandler implements Listener {
|
||||
private static Method getHandshake;
|
||||
@@ -184,7 +187,7 @@ public class BungeeServerHandler implements Listener {
|
||||
// Refresh the pipes
|
||||
List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), protocolId);
|
||||
ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline();
|
||||
user.clearStoredObjects();
|
||||
user.clearStoredObjects(true);
|
||||
pipeline.cleanPipes();
|
||||
if (protocolPath == null) {
|
||||
// TODO Check Bungee Supported Protocols? *shrugs*
|
||||
|
||||
@@ -235,7 +235,7 @@ public class ViaManagerImpl implements ViaManager {
|
||||
}
|
||||
}
|
||||
|
||||
private final void unsupportedSoftwareWarning() {
|
||||
private void unsupportedSoftwareWarning() {
|
||||
boolean found = false;
|
||||
for (UnsupportedSoftware software : platform.getUnsupportedSoftwareClasses()) {
|
||||
if (!software.findMatch()) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
@@ -160,10 +161,12 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
|
||||
}
|
||||
|
||||
private BlockedProtocolVersions loadBlockedProtocolVersions() {
|
||||
IntSet blockedProtocols = new IntOpenHashSet(getIntegerList("block-protocols"));
|
||||
List<Integer> blockProtocols = getListSafe("block-protocols", Integer.class, "Invalid blocked version protocol found in config: '%s'");
|
||||
List<String> blockVersions = getListSafe("block-versions", String.class, "Invalid blocked version found in config: '%s'");
|
||||
IntSet blockedProtocols = new IntOpenHashSet(blockProtocols);
|
||||
int lowerBound = -1;
|
||||
int upperBound = -1;
|
||||
for (String s : getStringList("block-versions")) {
|
||||
for (String s : blockVersions) {
|
||||
if (s.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,11 @@ public class UserConnectionImpl implements UserConnection {
|
||||
return storedObjects.containsKey(objectClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends StorableObject> @Nullable T remove(Class<T> objectClass) {
|
||||
return (T) storedObjects.remove(objectClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(StorableObject object) {
|
||||
storedObjects.put(object.getClass(), object);
|
||||
@@ -110,13 +115,23 @@ public class UserConnectionImpl implements UserConnection {
|
||||
|
||||
@Override
|
||||
public void addEntityTracker(Class<? extends Protocol> protocolClass, EntityTracker tracker) {
|
||||
entityTrackers.put(protocolClass, tracker);
|
||||
if (!entityTrackers.containsKey(protocolClass)) {
|
||||
entityTrackers.put(protocolClass, tracker);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearStoredObjects() {
|
||||
storedObjects.clear();
|
||||
entityTrackers.clear();
|
||||
public void clearStoredObjects(boolean isServerSwitch) {
|
||||
if (isServerSwitch) {
|
||||
storedObjects.values().removeIf(StorableObject::clearOnServerSwitch);
|
||||
for (EntityTracker tracker : entityTrackers.values()) {
|
||||
tracker.clearEntities();
|
||||
tracker.trackClientEntity();
|
||||
}
|
||||
} else {
|
||||
storedObjects.clear();
|
||||
entityTrackers.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.data.entity;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.api.data.entity.DimensionData;
|
||||
|
||||
public final class DimensionDataImpl implements DimensionData {
|
||||
|
||||
private final int minY;
|
||||
private final int height;
|
||||
|
||||
public DimensionDataImpl(final int minY, final int height) {
|
||||
this.minY = minY;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public DimensionDataImpl(final CompoundTag dimensionData) {
|
||||
final Tag height = dimensionData.get("height");
|
||||
if (height instanceof IntTag) {
|
||||
this.height = ((NumberTag) height).asInt();
|
||||
} else {
|
||||
throw new IllegalArgumentException("height missing in dimension data: " + dimensionData);
|
||||
}
|
||||
|
||||
final Tag minY = dimensionData.get("min_y");
|
||||
if (minY instanceof IntTag) {
|
||||
this.minY = ((NumberTag) minY).asInt();
|
||||
} else {
|
||||
throw new IllegalArgumentException("min_y missing in dimension data: " + dimensionData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minY() {
|
||||
return minY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int height() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DimensionData{" +
|
||||
"minY=" + minY +
|
||||
", height=" + height +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ package com.viaversion.viaversion.data.entity;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.entity.ClientEntityIdChangeListener;
|
||||
import com.viaversion.viaversion.api.data.entity.DimensionData;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
@@ -28,6 +29,9 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import space.vectrix.flare.fastutil.Int2ObjectSyncMap;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeListener {
|
||||
private final Int2ObjectMap<EntityType> entityTypes = Int2ObjectSyncMap.hashmap();
|
||||
private final Int2ObjectMap<StoredEntityData> entityData;
|
||||
@@ -38,6 +42,7 @@ public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeLis
|
||||
private int currentMinY;
|
||||
private String currentWorld;
|
||||
private int biomesSent = -1;
|
||||
private Map<String, DimensionData> dimensions = Collections.emptyMap();
|
||||
|
||||
public EntityTrackerBase(UserConnection connection, @Nullable EntityType playerType) {
|
||||
this(connection, playerType, false);
|
||||
@@ -118,6 +123,15 @@ public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeLis
|
||||
this.clientEntityId = clientEntityId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trackClientEntity() {
|
||||
if (clientEntityId != -1) {
|
||||
entityTypes.put(clientEntityId, playerType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int currentWorldSectionHeight() {
|
||||
return currentWorldSectionHeight;
|
||||
@@ -157,4 +171,19 @@ public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeLis
|
||||
public void setBiomesSent(int biomesSent) {
|
||||
this.biomesSent = biomesSent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType playerType() {
|
||||
return playerType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable DimensionData dimensionData(String dimension) {
|
||||
return dimensions.get(dimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDimensions(Map<String, DimensionData> dimensions) {
|
||||
this.dimensions = dimensions;
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,11 @@ public final class StoredEntityImpl implements StoredEntityData {
|
||||
return (T) storedObjects.get(objectClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T remove(Class<T> objectClass) {
|
||||
return (T) storedObjects.remove(objectClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(Class<?> objectClass) {
|
||||
return storedObjects.containsKey(objectClass);
|
||||
|
||||
@@ -18,7 +18,11 @@
|
||||
package com.viaversion.viaversion.debug;
|
||||
|
||||
import com.viaversion.viaversion.api.debug.DebugHandler;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -26,7 +30,9 @@ import java.util.Set;
|
||||
public final class DebugHandlerImpl implements DebugHandler {
|
||||
|
||||
private final Set<String> packetTypesToLog = new HashSet<>();
|
||||
private boolean logPostPacketTransform = true;
|
||||
private final IntSet clientboundPacketIdsToLog = new IntOpenHashSet();
|
||||
private final IntSet serverboundPacketIdsToLog = new IntOpenHashSet();
|
||||
private boolean logPostPacketTransform;
|
||||
private boolean enabled;
|
||||
|
||||
@Override
|
||||
@@ -44,6 +50,11 @@ public final class DebugHandlerImpl implements DebugHandler {
|
||||
packetTypesToLog.add(packetTypeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPacketTypeToLog(PacketType packetType) {
|
||||
(packetType.direction() == Direction.SERVERBOUND ? serverboundPacketIdsToLog : clientboundPacketIdsToLog).add(packetType.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePacketTypeNameToLog(final String packetTypeName) {
|
||||
return packetTypesToLog.remove(packetTypeName);
|
||||
@@ -65,7 +76,9 @@ public final class DebugHandlerImpl implements DebugHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldLog(final PacketWrapper wrapper) {
|
||||
return packetTypesToLog.isEmpty() || (wrapper.getPacketType() != null && packetTypesToLog.contains(wrapper.getPacketType().getName()));
|
||||
public boolean shouldLog(final PacketWrapper wrapper, final Direction direction) {
|
||||
return packetTypesToLog.isEmpty() && serverboundPacketIdsToLog.isEmpty() && clientboundPacketIdsToLog.isEmpty()
|
||||
|| (wrapper.getPacketType() != null && packetTypesToLog.contains(wrapper.getPacketType().getName()))
|
||||
|| (direction == Direction.SERVERBOUND ? serverboundPacketIdsToLog : clientboundPacketIdsToLog).contains(wrapper.getId());
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,8 @@ import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.Protocol1_17_1To
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
|
||||
import com.viaversion.viaversion.protocols.protocol1_18_2to1_18.Protocol1_18_2To1_18;
|
||||
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.Protocol1_19_1To1_19;
|
||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.Protocol1_19To1_18_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.Protocol1_9_3To1_9_1_2;
|
||||
@@ -171,6 +173,9 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
||||
registerProtocol(new Protocol1_17_1To1_17(), ProtocolVersion.v1_17_1, ProtocolVersion.v1_17);
|
||||
registerProtocol(new Protocol1_18To1_17_1(), ProtocolVersion.v1_18, ProtocolVersion.v1_17_1);
|
||||
registerProtocol(new Protocol1_18_2To1_18(), ProtocolVersion.v1_18_2, ProtocolVersion.v1_18);
|
||||
|
||||
registerProtocol(new Protocol1_19To1_18_2(), ProtocolVersion.v1_19, ProtocolVersion.v1_18_2);
|
||||
registerProtocol(new Protocol1_19_1To1_19(), ProtocolVersion.v1_19_1, ProtocolVersion.v1_19);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,4 +54,12 @@ public class ProtocolPathEntryImpl implements ProtocolPathEntry {
|
||||
result = 31 * result + protocol.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProtocolPathEntryImpl{" +
|
||||
"outputProtocolVersion=" + outputProtocolVersion +
|
||||
", protocol=" + protocol +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -114,12 +114,16 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
|
||||
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
|
||||
int originalID = packetWrapper.getId();
|
||||
|
||||
DebugHandler debugHandler = Via.getManager().debugHandler();
|
||||
if (debugHandler.enabled() && !debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) {
|
||||
logPacket(direction, state, packetWrapper, originalID);
|
||||
}
|
||||
|
||||
// Apply protocols
|
||||
packetWrapper.apply(direction, state, 0, protocolList, direction == Direction.CLIENTBOUND);
|
||||
super.transform(direction, state, packetWrapper);
|
||||
|
||||
DebugHandler debugHandler = Via.getManager().debugHandler();
|
||||
if (debugHandler.enabled() && debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper)) {
|
||||
if (debugHandler.enabled() && debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) {
|
||||
logPacket(direction, state, packetWrapper, originalID);
|
||||
}
|
||||
}
|
||||
@@ -127,20 +131,20 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
|
||||
private void logPacket(Direction direction, State state, PacketWrapper packetWrapper, int originalID) {
|
||||
// Debug packet
|
||||
int clientProtocol = userConnection.getProtocolInfo().getProtocolVersion();
|
||||
ViaPlatform platform = Via.getPlatform();
|
||||
ViaPlatform<?> platform = Via.getPlatform();
|
||||
|
||||
String actualUsername = packetWrapper.user().getProtocolInfo().getUsername();
|
||||
String username = actualUsername != null ? actualUsername + " " : "";
|
||||
|
||||
platform.getLogger().log(Level.INFO, "{0}{1} {2}: {3} (0x{4}) -> {5} (0x{6}) [{7}] {8}",
|
||||
platform.getLogger().log(Level.INFO, "{0}{1} {2}: {3} ({4}) -> {5} ({6}) [{7}] {8}",
|
||||
new Object[]{
|
||||
username,
|
||||
direction,
|
||||
state,
|
||||
originalID,
|
||||
Integer.toHexString(originalID),
|
||||
AbstractSimpleProtocol.toNiceHex(originalID),
|
||||
packetWrapper.getId(),
|
||||
Integer.toHexString(packetWrapper.getId()),
|
||||
AbstractSimpleProtocol.toNiceHex(packetWrapper.getId()),
|
||||
Integer.toString(clientProtocol),
|
||||
packetWrapper
|
||||
});
|
||||
|
||||
+3
-3
@@ -488,10 +488,10 @@ public class PacketWrapperImpl implements PacketWrapper {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PacketWrapper{" +
|
||||
"packetValues=" + packetValues +
|
||||
", readableObjects=" + readableObjects +
|
||||
"packetType=" + packetType +
|
||||
", id=" + id +
|
||||
", packetType=" + packetType +
|
||||
", packetValues=" + packetValues +
|
||||
", readableObjects=" + readableObjects +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,6 @@ public class BaseProtocol1_16 extends BaseProtocol1_7 {
|
||||
|
||||
@Override
|
||||
protected UUID passthroughLoginUUID(final PacketWrapper wrapper) throws Exception {
|
||||
return wrapper.passthrough(Type.UUID_INT_ARRAY);
|
||||
return wrapper.passthrough(Type.UUID);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -69,7 +69,7 @@ public class MetadataRewriter1_11To1_10 extends EntityRewriter<Protocol1_11To1_1
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(EntityType.ZOMBIE)) { // Zombie | Zombie Villager | Husk
|
||||
if (type.is(EntityType.ZOMBIE, EntityType.HUSK) && metadata.id() == 14) {
|
||||
if ((type == EntityType.ZOMBIE || type == EntityType.HUSK) && metadata.id() == 14) {
|
||||
metadatas.remove(metadata);
|
||||
} else {
|
||||
if (metadata.id() == 15) {
|
||||
@@ -104,7 +104,7 @@ public class MetadataRewriter1_11To1_10 extends EntityRewriter<Protocol1_11To1_1
|
||||
metadatas.remove(metadata);
|
||||
}
|
||||
}
|
||||
if (type.is(EntityType.DONKEY, EntityType.MULE)) {
|
||||
if (type == EntityType.DONKEY || type == EntityType.MULE) {
|
||||
// Chested Horse
|
||||
if (metadata.id() == 13) {
|
||||
if ((((byte) metadata.getValue()) & 0x08) == 0x08) {
|
||||
|
||||
+1
-25
@@ -118,7 +118,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
wrapper.write(Type.INT, position.z());
|
||||
};
|
||||
|
||||
private static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS =
|
||||
public static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS =
|
||||
w -> {
|
||||
// Send fake declare commands
|
||||
w.create(ClientboundPackets1_13.DECLARE_COMMANDS, wrapper -> {
|
||||
@@ -388,30 +388,6 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
}
|
||||
});
|
||||
|
||||
registerClientbound(ClientboundPackets1_12_1.JOIN_GAME, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Entity ID
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
// Store the player
|
||||
int entityId = wrapper.get(Type.INT, 0);
|
||||
wrapper.user().getEntityTracker(Protocol1_13To1_12_2.class).addEntity(entityId, Entity1_13Types.EntityType.PLAYER);
|
||||
|
||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientChunks.setEnvironment(dimensionId);
|
||||
}
|
||||
});
|
||||
handler(SEND_DECLARE_COMMANDS_AND_TAGS);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
registerClientbound(ClientboundPackets1_12_1.CRAFT_RECIPE_RESPONSE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@
|
||||
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -63,7 +64,7 @@ public class ComponentRewriter1_13 extends ComponentRewriter {
|
||||
}
|
||||
|
||||
CompoundTag itemTag = tag.get("tag");
|
||||
ShortTag damageTag = tag.get("Damage");
|
||||
NumberTag damageTag = tag.get("Damage");
|
||||
|
||||
// Call item converter
|
||||
short damage = damageTag != null ? damageTag.asShort() : 0;
|
||||
|
||||
+2
-7
@@ -47,7 +47,6 @@ public class MappingData extends MappingDataBase {
|
||||
private final Map<String, String> translateMapping = new HashMap<>();
|
||||
private final Map<String, String> mojangTranslation = new HashMap<>();
|
||||
private final BiMap<String, String> channelMappings = HashBiMap.create(); // 1.12->1.13
|
||||
private Mappings enchantmentMappings;
|
||||
|
||||
public MappingData() {
|
||||
super("1.12", "1.13");
|
||||
@@ -59,9 +58,9 @@ public class MappingData extends MappingDataBase {
|
||||
loadTags(itemTags, newMappings.getAsJsonObject("item_tags"));
|
||||
loadTags(fluidTags, newMappings.getAsJsonObject("fluid_tags"));
|
||||
|
||||
loadEnchantments(oldEnchantmentsIds, oldMappings.getAsJsonObject("enchantments"));
|
||||
loadEnchantments(oldEnchantmentsIds, oldMappings.getAsJsonObject("legacy_enchantments"));
|
||||
enchantmentMappings = IntArrayMappings.builder().customEntrySize(72)
|
||||
.unmapped(oldMappings.getAsJsonObject("enchantments")).mapped(newMappings.getAsJsonObject("enchantments")).build();
|
||||
.unmapped(oldMappings.getAsJsonObject("legacy_enchantments")).mapped(newMappings.getAsJsonArray("enchantments")).build();
|
||||
|
||||
// Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13
|
||||
if (Via.getConfig().isSnowCollisionFix()) {
|
||||
@@ -196,8 +195,4 @@ public class MappingData extends MappingDataBase {
|
||||
public BiMap<String, String> getChannelMappings() {
|
||||
return channelMappings;
|
||||
}
|
||||
|
||||
public Mappings getEnchantmentMappings() {
|
||||
return enchantmentMappings;
|
||||
}
|
||||
}
|
||||
+18
@@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
public class EntityPackets {
|
||||
|
||||
@@ -128,6 +129,23 @@ public class EntityPackets {
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12_1.JOIN_GAME, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Entity ID
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
handler(wrapper -> {
|
||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientChunks.setEnvironment(dimensionId);
|
||||
});
|
||||
handler(metadataRewriter.playerTrackerHandler());
|
||||
handler(Protocol1_13To1_12_2.SEND_DECLARE_COMMANDS_AND_TAGS);
|
||||
}
|
||||
});
|
||||
|
||||
metadataRewriter.registerRemoveEntities(ClientboundPackets1_12_1.DESTROY_ENTITIES);
|
||||
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_12_1.ENTITY_METADATA, Types1_12.METADATA_LIST, Types1_13.METADATA_LIST);
|
||||
}
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public class CommandRewriter1_14 extends CommandRewriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable String handleArgumentType(String argumentType) {
|
||||
public @Nullable String handleArgumentType(String argumentType) {
|
||||
if (argumentType.equals("minecraft:nbt")) {
|
||||
return "minecraft:nbt_compound_tag";
|
||||
}
|
||||
|
||||
+37
@@ -33,6 +33,7 @@ import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPacke
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -195,6 +196,42 @@ public class EntityPackets {
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.JOIN_GAME, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Entity ID
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
handler(wrapper -> {
|
||||
// Store the player
|
||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientChunks.setEnvironment(dimensionId);
|
||||
});
|
||||
handler(metadataRewriter.playerTrackerHandler());
|
||||
handler(wrapper -> {
|
||||
short difficulty = wrapper.read(Type.UNSIGNED_BYTE); // 19w11a removed difficulty from join game
|
||||
PacketWrapper difficultyPacket = wrapper.create(ClientboundPackets1_14.SERVER_DIFFICULTY);
|
||||
difficultyPacket.write(Type.UNSIGNED_BYTE, difficulty);
|
||||
difficultyPacket.write(Type.BOOLEAN, false); // Unknown value added in 19w11a
|
||||
difficultyPacket.scheduleSend(protocol.getClass());
|
||||
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Max Players
|
||||
wrapper.passthrough(Type.STRING); // Level Type
|
||||
|
||||
wrapper.write(Type.VAR_INT, WorldPackets.SERVERSIDE_VIEW_DISTANCE); // Serverside view distance, added in 19w13a
|
||||
});
|
||||
handler(wrapper -> {
|
||||
// Manually send the packet
|
||||
wrapper.send(Protocol1_14To1_13_2.class);
|
||||
wrapper.cancel();
|
||||
|
||||
// View distance has to be sent after the join packet
|
||||
WorldPackets.sendViewDistancePacket(wrapper.user());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.USE_BED, ClientboundPackets1_14.ENTITY_METADATA, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
|
||||
+1
-51
@@ -25,7 +25,6 @@ import com.viaversion.viaversion.api.minecraft.BlockFace;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.NibbleArray;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@@ -288,55 +287,6 @@ public class WorldPackets {
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.JOIN_GAME, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Entity ID
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
// Store the player
|
||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
||||
int dimensionId = wrapper.get(Type.INT, 1);
|
||||
clientChunks.setEnvironment(dimensionId);
|
||||
|
||||
int entityId = wrapper.get(Type.INT, 0);
|
||||
|
||||
Entity1_14Types entType = Entity1_14Types.PLAYER;
|
||||
// Register Type ID
|
||||
EntityTracker1_14 tracker = wrapper.user().getEntityTracker(Protocol1_14To1_13_2.class);
|
||||
tracker.addEntity(entityId, entType);
|
||||
tracker.setClientEntityId(entityId);
|
||||
}
|
||||
});
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
short difficulty = wrapper.read(Type.UNSIGNED_BYTE); // 19w11a removed difficulty from join game
|
||||
PacketWrapper difficultyPacket = wrapper.create(ClientboundPackets1_14.SERVER_DIFFICULTY);
|
||||
difficultyPacket.write(Type.UNSIGNED_BYTE, difficulty);
|
||||
difficultyPacket.write(Type.BOOLEAN, false); // Unknown value added in 19w11a
|
||||
difficultyPacket.scheduleSend(protocol.getClass());
|
||||
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Max Players
|
||||
wrapper.passthrough(Type.STRING); // Level Type
|
||||
|
||||
wrapper.write(Type.VAR_INT, SERVERSIDE_VIEW_DISTANCE); // Serverside view distance, added in 19w13a
|
||||
}
|
||||
});
|
||||
handler(wrapper -> {
|
||||
// Manually send the packet
|
||||
wrapper.send(Protocol1_14To1_13_2.class);
|
||||
wrapper.cancel();
|
||||
|
||||
// View distance has to be sent after the join packet
|
||||
sendViewDistancePacket(wrapper.user());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_13.MAP_DATA, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@@ -394,7 +344,7 @@ public class WorldPackets {
|
||||
});
|
||||
}
|
||||
|
||||
private static void sendViewDistancePacket(UserConnection connection) throws Exception {
|
||||
static void sendViewDistancePacket(UserConnection connection) throws Exception {
|
||||
PacketWrapper setViewDistance = PacketWrapper.create(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE, null, connection);
|
||||
setViewDistance.write(Type.VAR_INT, WorldPackets.SERVERSIDE_VIEW_DISTANCE);
|
||||
setViewDistance.send(Protocol1_14To1_13_2.class);
|
||||
|
||||
+1
-3
@@ -18,6 +18,7 @@
|
||||
package com.viaversion.viaversion.protocols.protocol1_15to1_14_4;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@@ -31,9 +32,7 @@ import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.data.MappingData
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPackets;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.PlayerPackets;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.WorldPackets;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
@@ -55,7 +54,6 @@ public class Protocol1_15To1_14_4 extends AbstractProtocol<ClientboundPackets1_1
|
||||
itemRewriter.register();
|
||||
|
||||
EntityPackets.register(this);
|
||||
PlayerPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
|
||||
SoundRewriter soundRewriter = new SoundRewriter(this);
|
||||
|
||||
+27
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
@@ -79,6 +80,32 @@ public class EntityPackets {
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_14.RESPAWN, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT);
|
||||
handler(wrapper -> wrapper.write(Type.LONG, 0L)); // Level Seed
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_14.JOIN_GAME, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Entity ID
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
handler(metadataRewriter.playerTrackerHandler());
|
||||
handler(wrapper -> wrapper.write(Type.LONG, 0L)); // Level Seed
|
||||
|
||||
map(Type.UNSIGNED_BYTE); // 3 - Max Players
|
||||
map(Type.STRING); // 4 - Level Type
|
||||
map(Type.VAR_INT); // 5 - View Distance
|
||||
map(Type.BOOLEAN); // 6 - Reduce Debug Info
|
||||
|
||||
handler(wrapper -> wrapper.write(Type.BOOLEAN, !Via.getConfig().is1_15InstantRespawn())); // Show Death Screen
|
||||
}
|
||||
});
|
||||
|
||||
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14.ENTITY_METADATA, Types1_14.METADATA_LIST);
|
||||
metadataRewriter.registerRemoveEntities(ClientboundPackets1_14.DESTROY_ENTITIES);
|
||||
}
|
||||
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
||||
|
||||
public class PlayerPackets {
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
protocol.registerClientbound(ClientboundPackets1_14.RESPAWN, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT);
|
||||
handler(wrapper -> wrapper.write(Type.LONG, 0L)); // Level Seed
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_14.JOIN_GAME, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Entity ID
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
handler(wrapper -> {
|
||||
// Register Type ID
|
||||
EntityTracker tracker = wrapper.user().getEntityTracker(Protocol1_15To1_14_4.class);
|
||||
int entityId = wrapper.get(Type.INT, 0);
|
||||
tracker.addEntity(entityId, Entity1_15Types.PLAYER);
|
||||
});
|
||||
handler(wrapper -> wrapper.write(Type.LONG, 0L)); // Level Seed
|
||||
|
||||
map(Type.UNSIGNED_BYTE); // 3 - Max Players
|
||||
map(Type.STRING); // 4 - Level Type
|
||||
map(Type.VAR_INT); // 5 - View Distance
|
||||
map(Type.BOOLEAN); // 6 - Reduce Debug Info
|
||||
|
||||
handler(wrapper -> wrapper.write(Type.BOOLEAN, !Via.getConfig().is1_15InstantRespawn())); // Show Death Screen
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -63,9 +63,7 @@ public class EntityPackets {
|
||||
map(Type.LONG); // Seed
|
||||
map(Type.UNSIGNED_BYTE, Type.VAR_INT); // Max players
|
||||
// ...
|
||||
handler(wrapper -> {
|
||||
wrapper.user().getEntityTracker(Protocol1_16_2To1_16_1.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16_2Types.PLAYER);
|
||||
});
|
||||
handler(metadataRewriter.playerTrackerHandler());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+2
-2
@@ -84,9 +84,9 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> {
|
||||
// Transform string to int array
|
||||
// Transform string to a uuid
|
||||
UUID uuid = UUID.fromString(wrapper.read(Type.STRING));
|
||||
wrapper.write(Type.UUID_INT_ARRAY, uuid);
|
||||
wrapper.write(Type.UUID, uuid);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Loaded 100 of 142 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user