3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-26 16:12:43 +01:00

Use fastutil soft wrappers

Dieser Commit ist enthalten in:
KennyTV 2020-06-08 14:37:54 +02:00
Ursprung 71d5aab1b0
Commit 16b68f7e3d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
15 geänderte Dateien mit 81 neuen und 118 gelöschten Zeilen

Datei anzeigen

@ -1,8 +1,11 @@
package nl.matsv.viabackwards.api.data; package nl.matsv.viabackwards.api.data;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
import us.myles.ViaVersion.util.fastutil.IntObjectMap;
import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.gson.JsonObject;
@ -14,9 +17,10 @@ import java.util.Map;
*/ */
public class VBItemMappings { public class VBItemMappings {
private final Map<Integer, MappedItem> itemMapping = new HashMap<>(); private final IntObjectMap<MappedItem> itemMapping;
public VBItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) { public VBItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) {
Map<Integer, MappedItem> itemMapping = new HashMap<>();
for (Map.Entry<String, JsonElement> entry : diffMapping.entrySet()) { for (Map.Entry<String, JsonElement> entry : diffMapping.entrySet()) {
JsonObject object = entry.getValue().getAsJsonObject(); JsonObject object = entry.getValue().getAsJsonObject();
String mappedIdName = object.getAsJsonPrimitive("id").getAsString(); String mappedIdName = object.getAsJsonPrimitive("id").getAsString();
@ -41,8 +45,11 @@ public class VBItemMappings {
String name = object.getAsJsonPrimitive("name").getAsString(); String name = object.getAsJsonPrimitive("name").getAsString();
itemMapping.put(id, new MappedItem(mappedId, name)); itemMapping.put(id, new MappedItem(mappedId, name));
} }
this.itemMapping = CollectionUtil.createIntObjectMap(itemMapping);
} }
@Nullable
public MappedItem getMappedItem(int id) { public MappedItem getMappedItem(int id) {
return itemMapping.get(id); return itemMapping.get(id);
} }

Datei anzeigen

@ -23,6 +23,8 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
import us.myles.ViaVersion.util.fastutil.IntMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
@ -43,7 +45,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
private final List<MetaHandlerSettings> metaHandlers = new ArrayList<>(); private final List<MetaHandlerSettings> metaHandlers = new ArrayList<>();
private final MetaType displayNameMetaType; private final MetaType displayNameMetaType;
private final int displayNameIndex; private final int displayNameIndex;
private Map<Integer, Integer> typeMapping; protected IntMap typeMapping;
EntityRewriterBase(T protocol) { EntityRewriterBase(T protocol) {
this(protocol, MetaType1_9.String, 2); this(protocol, MetaType1_9.String, 2);
@ -99,7 +101,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
* @param <T> new type class * @param <T> new type class
*/ */
public <T extends Enum<T> & EntityType> void mapTypes(EntityType[] oldTypes, Class<T> newTypeClass) { public <T extends Enum<T> & EntityType> void mapTypes(EntityType[] oldTypes, Class<T> newTypeClass) {
if (typeMapping == null) typeMapping = new HashMap<>(oldTypes.length); if (typeMapping == null) typeMapping = CollectionUtil.createIntMap(oldTypes.length);
for (EntityType oldType : oldTypes) { for (EntityType oldType : oldTypes) {
try { try {
T newType = Enum.valueOf(newTypeClass, oldType.name()); T newType = Enum.valueOf(newTypeClass, oldType.name());
@ -122,7 +124,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
} }
private void mapEntityDirect(int oldType, int newType) { private void mapEntityDirect(int oldType, int newType) {
if (typeMapping == null) typeMapping = new HashMap<>(); if (typeMapping == null) typeMapping = CollectionUtil.createIntMap();
typeMapping.put(oldType, newType); typeMapping.put(oldType, newType);
} }

Datei anzeigen

@ -22,6 +22,8 @@ import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.rewriters.IdRewriteFunction; import us.myles.ViaVersion.api.rewriters.IdRewriteFunction;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
import us.myles.ViaVersion.util.fastutil.IntObjectMap;
import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.gson.JsonObject;
import us.myles.viaversion.libs.gson.JsonPrimitive; import us.myles.viaversion.libs.gson.JsonPrimitive;
@ -35,13 +37,13 @@ import java.util.Map;
public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> extends ItemRewriterBase<T> { public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> extends ItemRewriterBase<T> {
private static final Map<String, Map<Integer, MappedLegacyBlockItem>> LEGACY_MAPPINGS = new HashMap<>(); private static final Map<String, IntObjectMap<MappedLegacyBlockItem>> LEGACY_MAPPINGS = new HashMap<>();
protected final Map<Integer, MappedLegacyBlockItem> replacementData; protected final IntObjectMap<MappedLegacyBlockItem> replacementData;
static { static {
JsonObject jsonObject = VBMappingDataLoader.loadFromDataDir("legacy-mappings.json"); JsonObject jsonObject = VBMappingDataLoader.loadFromDataDir("legacy-mappings.json");
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
Map<Integer, MappedLegacyBlockItem> mappings = new HashMap<>(); IntObjectMap<MappedLegacyBlockItem> mappings = CollectionUtil.createIntObjectMap(8);
LEGACY_MAPPINGS.put(entry.getKey(), mappings); LEGACY_MAPPINGS.put(entry.getKey(), mappings);
for (Map.Entry<String, JsonElement> dataEntry : entry.getValue().getAsJsonObject().entrySet()) { for (Map.Entry<String, JsonElement> dataEntry : entry.getValue().getAsJsonObject().entrySet()) {
JsonObject object = dataEntry.getValue().getAsJsonObject(); JsonObject object = dataEntry.getValue().getAsJsonObject();

Datei anzeigen

@ -11,12 +11,13 @@
package nl.matsv.viabackwards.api.rewriters; package nl.matsv.viabackwards.api.rewriters;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
import us.myles.ViaVersion.util.fastutil.IntObjectMap;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public abstract class LegacySoundRewriter<T extends BackwardsProtocol> extends Rewriter<T> { public abstract class LegacySoundRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
protected final Map<Integer, SoundData> soundRewrites = new HashMap<>(); protected final IntObjectMap<SoundData> soundRewrites = CollectionUtil.createIntObjectMap(64);
protected LegacySoundRewriter(T protocol) { protected LegacySoundRewriter(T protocol) {
super(protocol); super(protocol);
@ -43,7 +44,7 @@ public abstract class LegacySoundRewriter<T extends BackwardsProtocol> extends R
SoundData data = soundRewrites.get(soundId); SoundData data = soundRewrites.get(soundId);
if (data != null) return data.getReplacementSound(); if (data != null) return data.getReplacementSound();
for (Map.Entry<Integer, SoundData> entry : soundRewrites.entrySet()) { for (Map.Entry<Integer, SoundData> entry : soundRewrites.getMap().entrySet()) {
if (soundId > entry.getKey()) { if (soundId > entry.getKey()) {
if (entry.getValue().isAdded()) { if (entry.getValue().isAdded()) {
newSoundId--; newSoundId--;

Datei anzeigen

@ -1,11 +1,11 @@
package nl.matsv.viabackwards.protocol.protocol1_10to1_11; package nl.matsv.viabackwards.protocol.protocol1_10to1_11;
import java.util.HashMap; import us.myles.ViaVersion.util.fastutil.CollectionUtil;
import java.util.Map; import us.myles.ViaVersion.util.fastutil.IntMap;
public class PotionSplashHandler { public class PotionSplashHandler {
private static final Map<Integer, Integer> DATA = new HashMap<>(); private static final IntMap DATA = CollectionUtil.createIntMap(14);
static { static {
DATA.put(2039713, 5); // night vision DATA.put(2039713, 5); // night vision
@ -24,7 +24,7 @@ public class PotionSplashHandler {
DATA.put(3381504, 36); // luck DATA.put(3381504, 36); // luck
} }
public static Integer getOldData(int data) { public static int getOldData(int data) {
return DATA.get(data); return DATA.get(data);
} }
} }

Datei anzeigen

@ -339,7 +339,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
// Handle spawner block entity (map to itself with custom handler) // Handle spawner block entity (map to itself with custom handler)
MappedLegacyBlockItem data = replacementData.computeIfAbsent(52, s -> new MappedLegacyBlockItem(52, (short) -1, null, false)); MappedLegacyBlockItem data = replacementData.getMap().computeIfAbsent(52, s -> new MappedLegacyBlockItem(52, (short) -1, null, false));
data.setBlockEntityHandler((b, tag) -> { data.setBlockEntityHandler((b, tag) -> {
EntityIdRewriter.toClientSpawner(tag, true); EntityIdRewriter.toClientSpawner(tag, true);
return tag; return tag;

Datei anzeigen

@ -54,8 +54,8 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
wrapper.set(Type.INT, 0, 2002); wrapper.set(Type.INT, 0, 2002);
} }
Integer mappedData = PotionSplashHandler.getOldData(wrapper.get(Type.INT, 1)); int mappedData = PotionSplashHandler.getOldData(wrapper.get(Type.INT, 1));
if (mappedData != null) { if (mappedData != -1) {
wrapper.set(Type.INT, 1, mappedData); wrapper.set(Type.INT, 1, mappedData);
} }
} }

Datei anzeigen

@ -1,10 +1,10 @@
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data;
import java.util.HashMap; import us.myles.ViaVersion.util.fastutil.CollectionUtil;
import java.util.Map; import us.myles.ViaVersion.util.fastutil.IntMap;
public class MapColorMapping { public class MapColorMapping {
private static final Map<Integer, Integer> MAPPING = new HashMap<>(); private static final IntMap MAPPING = CollectionUtil.createIntMap(64);
static { static {
MAPPING.put(144, 59); // (148, 124, 114) -> (148, 124, 114) MAPPING.put(144, 59); // (148, 124, 114) -> (148, 124, 114)

Datei anzeigen

@ -13,20 +13,19 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handler
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
import us.myles.ViaVersion.util.fastutil.IntObjectMap;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag; import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import java.util.HashMap;
import java.util.Map;
public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
private static final Map<Integer, Pair<String, Byte>> flowers = new HashMap<>(); private static final IntObjectMap<Pair<String, Byte>> FLOWERS = CollectionUtil.createIntObjectMap(22);
private static final Pair<String, Byte> AIR = new Pair<>("minecraft:air", (byte) 0); private static final Pair<String, Byte> AIR = new Pair<>("minecraft:air", (byte) 0);
static { static {
flowers.put(5265, AIR); FLOWERS.put(5265, AIR);
register(5266, "minecraft:sapling", (byte) 0); register(5266, "minecraft:sapling", (byte) 0);
register(5267, "minecraft:sapling", (byte) 1); register(5267, "minecraft:sapling", (byte) 1);
register(5268, "minecraft:sapling", (byte) 2); register(5268, "minecraft:sapling", (byte) 2);
@ -51,7 +50,7 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB
} }
private static void register(int id, String identifier, byte data) { private static void register(int id, String identifier, byte data) {
flowers.put(id, new Pair<>(identifier, data)); FLOWERS.put(id, new Pair<>(identifier, data));
} }
public static boolean isFlowah(int id) { public static boolean isFlowah(int id) {
@ -59,7 +58,7 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB
} }
public Pair<String, Byte> getOrDefault(int blockId) { public Pair<String, Byte> getOrDefault(int blockId) {
Pair<String, Byte> pair = flowers.get(blockId); Pair<String, Byte> pair = FLOWERS.get(blockId);
return pair != null ? pair : AIR; return pair != null ? pair : AIR;
} }

Datei anzeigen

@ -1,27 +1,26 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data; package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter;
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
import us.myles.ViaVersion.util.fastutil.IntMap;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class EntityTypeMapping { public class EntityTypeMapping {
private static final Map<Integer, Integer> TYPES = new HashMap<>(); private static final IntMap TYPES = CollectionUtil.createIntMap();
static { static {
try { try {
Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes"); Field field = EntityTypeRewriter.class.getDeclaredField("ENTITY_TYPES");
field.setAccessible(true); field.setAccessible(true);
Map<Integer, Integer> entityTypes = (Map<Integer, Integer>) field.get(null); IntMap entityTypes = (IntMap) field.get(null);
entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.TYPES.put(type1_13, type1_12)); entityTypes.getMap().forEach((type1_12, type1_13) -> EntityTypeMapping.TYPES.put(type1_13, type1_12));
} catch (NoSuchFieldException | IllegalAccessException ex) { } catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public static Optional<Integer> getOldId(int type1_13) { public static int getOldId(int type1_13) {
return Optional.ofNullable(TYPES.get(type1_13)); return TYPES.get(type1_13);
} }
} }

Datei anzeigen

@ -141,12 +141,13 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
EntityType entityType = Entity1_13Types.getTypeFromId(type, false); EntityType entityType = Entity1_13Types.getTypeFromId(type, false);
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType); addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
Optional<Integer> oldId = EntityTypeMapping.getOldId(type); int oldId = EntityTypeMapping.getOldId(type);
if (!oldId.isPresent()) { if (oldId == -1) {
if (!hasData(entityType)) if (!hasData(entityType)) {
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.12 entity type for 1.13 entity type " + type + "/" + entityType); ViaBackwards.getPlatform().getLogger().warning("Could not find 1.12 entity type for 1.13 entity type " + type + "/" + entityType);
}
} else { } else {
wrapper.set(Type.VAR_INT, 1, oldId.get()); wrapper.set(Type.VAR_INT, 1, oldId);
} }
} }
}); });
@ -266,7 +267,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
mapEntity(Entity1_13Types.EntityType.DROWNED, Entity1_13Types.EntityType.ZOMBIE_VILLAGER).mobName("Drowned"); mapEntity(Entity1_13Types.EntityType.DROWNED, Entity1_13Types.EntityType.ZOMBIE_VILLAGER).mobName("Drowned");
// Fishy // Fishy
mapEntity(Entity1_13Types.EntityType.COD_MOB, Entity1_13Types.EntityType.SQUID).mobName("Cod"); mapEntity(Entity1_13Types.EntityType.COD, Entity1_13Types.EntityType.SQUID).mobName("Cod");
mapEntity(Entity1_13Types.EntityType.SALMON, Entity1_13Types.EntityType.SQUID).mobName("Salmon"); mapEntity(Entity1_13Types.EntityType.SALMON, Entity1_13Types.EntityType.SQUID).mobName("Salmon");
mapEntity(Entity1_13Types.EntityType.PUFFERFISH, Entity1_13Types.EntityType.SQUID).mobName("Puffer Fish"); mapEntity(Entity1_13Types.EntityType.PUFFERFISH, Entity1_13Types.EntityType.SQUID).mobName("Puffer Fish");
mapEntity(Entity1_13Types.EntityType.TROPICAL_FISH, Entity1_13Types.EntityType.SQUID).mobName("Tropical Fish"); mapEntity(Entity1_13Types.EntityType.TROPICAL_FISH, Entity1_13Types.EntityType.SQUID).mobName("Tropical Fish");
@ -405,6 +406,6 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<Protocol1_12_2To1_13
@Override @Override
public int getOldEntityId(final int newId) { public int getOldEntityId(final int newId) {
return EntityTypeMapping.getOldId(newId).orElse(newId); return EntityTypeMapping.getOldId(newId);
} }
} }

Datei anzeigen

@ -13,49 +13,53 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
import us.myles.ViaVersion.util.fastutil.IntSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class BackwardsBlockStorage extends StoredObject { public class BackwardsBlockStorage extends StoredObject {
// This BlockStorage is very exclusive (; // This BlockStorage is very exclusive (;
private static final Set<Integer> whitelist = new HashSet<>(); private static final IntSet WHITELIST = CollectionUtil.createIntSet(779);
static { static {
// Flower pots // Flower pots
for (int i = 5265; i <= 5286; i++) for (int i = 5265; i <= 5286; i++) {
whitelist.add(i); WHITELIST.add(i);
}
// Add those beds // Add those beds
for (int i = 0; i < (16 * 16); i++) for (int i = 0; i < (16 * 16); i++) {
whitelist.add(748 + i); WHITELIST.add(748 + i);
}
// Add the banners // Add the banners
for (int i = 6854; i <= 7173; i++) for (int i = 6854; i <= 7173; i++) {
whitelist.add(i); WHITELIST.add(i);
}
// Spawner // Spawner
whitelist.add(1647); WHITELIST.add(1647);
// Skulls // Skulls
for (int i = 5447; i <= 5566; i++) for (int i = 5447; i <= 5566; i++) {
whitelist.add(i); WHITELIST.add(i);
}
// pistons // pistons
for (int i = 1028; i <= 1039; i++) { for (int i = 1028; i <= 1039; i++) {
whitelist.add(i); WHITELIST.add(i);
} }
for (int i = 1047; i <= 1082; i++) { for (int i = 1047; i <= 1082; i++) {
whitelist.add(i); WHITELIST.add(i);
} }
for (int i = 1099; i <= 1110; i++) { for (int i = 1099; i <= 1110; i++) {
whitelist.add(i); WHITELIST.add(i);
} }
} }
private final Map<Position, Integer> blocks = new ConcurrentHashMap<>(); private final Map<Position, Integer> blocks = new ConcurrentHashMap<>();
public BackwardsBlockStorage(UserConnection user) { public BackwardsBlockStorage(UserConnection user) {
@ -63,7 +67,7 @@ public class BackwardsBlockStorage extends StoredObject {
} }
public void checkAndStore(Position position, int block) { public void checkAndStore(Position position, int block) {
if (!whitelist.contains(block)) { if (!WHITELIST.contains(block)) {
// Remove if not whitelisted // Remove if not whitelisted
blocks.remove(position); blocks.remove(position);
return; return;
@ -73,7 +77,7 @@ public class BackwardsBlockStorage extends StoredObject {
} }
public boolean isWelcome(int block) { public boolean isWelcome(int block) {
return whitelist.contains(block); return WHITELIST.contains(block);
} }
public Integer get(Position position) { public Integer get(Position position) {

Datei anzeigen

@ -1,47 +0,0 @@
package nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data;
import us.myles.ViaVersion.api.entities.Entity1_13Types;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
public class EntityTypeMapping {
private static final Map<Integer, Integer> entityTypes = new HashMap<>();
private static final Map<Integer, Integer> oldEntityToOldObject = new HashMap<>();
static {
try {
Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes");
field.setAccessible(true);
Map<Integer, Integer> entityTypes = (Map<Integer, Integer>) field.get(null);
entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.entityTypes.put(type1_13, type1_12));
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
}
for (Map.Entry<Integer, Integer> newToOld : entityTypes.entrySet()) {
Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(newToOld.getValue(), false);
Entity1_13Types.ObjectType object1_13 = null;
for (Entity1_13Types.ObjectType objectType : Entity1_13Types.ObjectType.values()) {
if (objectType.getType() == type1_13) {
object1_13 = objectType;
break;
}
}
if (object1_13 != null) {
oldEntityToOldObject.put(type1_13.getId(), object1_13.getId());
}
}
for (Entity1_13Types.EntityType type : Entity1_13Types.EntityType.values()) {
if (!entityTypes.containsValue(type.getId())) {
entityTypes.put(type.getId(), type.getId());
}
}
entityTypes.put(50, 48); // ocelot
}
public static Integer getOldId(int type1_14) {
return entityTypes.get(type1_14);
}
}

Datei anzeigen

@ -8,7 +8,6 @@ import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.exceptions.RemovedValueException; import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter; import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.EntityTypeMapping;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
@ -134,8 +133,8 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.BYTE, 0); int id = wrapper.get(Type.BYTE, 0);
Integer mappedId = EntityTypeMapping.getOldId(id); int mappedId = getOldEntityId(id);
Entity1_13Types.EntityType entityType = Entity1_13Types.getTypeFromId(mappedId != null ? mappedId : id, false); Entity1_13Types.EntityType entityType = Entity1_13Types.getTypeFromId(mappedId, false);
Entity1_13Types.ObjectType objectType; Entity1_13Types.ObjectType objectType;
if (entityType.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT)) { if (entityType.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT)) {
objectType = Entity1_13Types.ObjectType.MINECART; objectType = Entity1_13Types.ObjectType.MINECART;
@ -207,8 +206,8 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
Entity1_14Types.EntityType entityType = Entity1_14Types.getTypeFromId(type); Entity1_14Types.EntityType entityType = Entity1_14Types.getTypeFromId(type);
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType); addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
Integer oldId = EntityTypeMapping.getOldId(type); int oldId = typeMapping.get(type);
if (oldId == null) { if (oldId == -1) {
EntityData entityData = getEntityData(entityType); EntityData entityData = getEntityData(entityType);
if (entityData == null) { if (entityData == null) {
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13.2 entity type for 1.14 entity type " + type + "/" + entityType); ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13.2 entity type for 1.14 entity type " + type + "/" + entityType);
@ -336,6 +335,8 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
mapEntity(Entity1_14Types.EntityType.WANDERING_TRADER, Entity1_14Types.EntityType.VILLAGER).jsonName("Wandering Trader"); mapEntity(Entity1_14Types.EntityType.WANDERING_TRADER, Entity1_14Types.EntityType.VILLAGER).jsonName("Wandering Trader");
mapEntity(Entity1_14Types.EntityType.RAVAGER, Entity1_14Types.EntityType.COW).jsonName("Ravager"); mapEntity(Entity1_14Types.EntityType.RAVAGER, Entity1_14Types.EntityType.COW).jsonName("Ravager");
mapTypes(Entity1_14Types.EntityType.values(), Entity1_13Types.EntityType.class);
registerMetaHandler().handle(e -> { registerMetaHandler().handle(e -> {
Metadata meta = e.getData(); Metadata meta = e.getData();
int typeId = meta.getMetaType().getTypeID(); int typeId = meta.getMetaType().getTypeID();
@ -575,10 +576,4 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
protected EntityType getTypeFromId(int typeId) { protected EntityType getTypeFromId(int typeId) {
return Entity1_14Types.getTypeFromId(typeId); return Entity1_14Types.getTypeFromId(typeId);
} }
@Override
public int getOldEntityId(final int newId) {
Integer oldId = EntityTypeMapping.getOldId(newId);
return oldId != null ? oldId : newId;
}
} }

Datei anzeigen

@ -104,7 +104,7 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
Chunk chunk = wrapper.read(new Chunk1_15Type(clientWorld)); Chunk chunk = wrapper.read(new Chunk1_15Type(clientWorld));
wrapper.write(new Chunk1_14Type(clientWorld), chunk); wrapper.write(new Chunk1_14Type(clientWorld), chunk);
if (chunk.isGroundUp()) { if (chunk.isFullChunk()) {
int[] biomeData = chunk.getBiomeData(); int[] biomeData = chunk.getBiomeData();
int[] newBiomeData = new int[256]; int[] newBiomeData = new int[256];
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {