mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-23 12:25:24 +01:00
Move to proper FU usage
This commit is contained in:
parent
79708fe952
commit
6de1ba9f30
@ -4,8 +4,8 @@ import nl.matsv.viabackwards.ViaBackwards;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
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.fastutil.ints.Int2ObjectMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
import us.myles.viaversion.libs.gson.JsonObject;
|
||||
|
||||
@ -17,7 +17,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class VBItemMappings {
|
||||
|
||||
private final IntObjectMap<MappedItem> itemMapping;
|
||||
private final Int2ObjectMap<MappedItem> itemMapping;
|
||||
|
||||
public VBItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) {
|
||||
Map<Integer, MappedItem> itemMapping = new HashMap<>();
|
||||
@ -46,7 +46,7 @@ public class VBItemMappings {
|
||||
itemMapping.put(id, new MappedItem(mappedId, name));
|
||||
}
|
||||
|
||||
this.itemMapping = CollectionUtil.createIntObjectMap(itemMapping);
|
||||
this.itemMapping = new Int2ObjectOpenHashMap<>(itemMapping, 1F);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -23,8 +23,8 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.exception.CancelException;
|
||||
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 us.myles.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@ -45,7 +45,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
|
||||
private final List<MetaHandlerSettings> metaHandlers = new ArrayList<>();
|
||||
private final MetaType displayNameMetaType;
|
||||
private final int displayNameIndex;
|
||||
protected IntMap typeMapping;
|
||||
protected Int2IntMap typeMapping;
|
||||
|
||||
EntityRewriterBase(T protocol) {
|
||||
this(protocol, MetaType1_9.String, 2);
|
||||
@ -101,7 +101,10 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
|
||||
* @param <T> new type class
|
||||
*/
|
||||
public <T extends Enum<T> & EntityType> void mapTypes(EntityType[] oldTypes, Class<T> newTypeClass) {
|
||||
if (typeMapping == null) typeMapping = CollectionUtil.createIntMap(oldTypes.length);
|
||||
if (typeMapping == null) {
|
||||
typeMapping = new Int2IntOpenHashMap(oldTypes.length, 1F);
|
||||
typeMapping.defaultReturnValue(-1);
|
||||
}
|
||||
for (EntityType oldType : oldTypes) {
|
||||
try {
|
||||
T newType = Enum.valueOf(newTypeClass, oldType.name());
|
||||
@ -124,7 +127,10 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
|
||||
}
|
||||
|
||||
private void mapEntityDirect(int oldType, int newType) {
|
||||
if (typeMapping == null) typeMapping = CollectionUtil.createIntMap();
|
||||
if (typeMapping == null) {
|
||||
typeMapping = new Int2IntOpenHashMap();
|
||||
typeMapping.defaultReturnValue(-1);
|
||||
}
|
||||
typeMapping.put(oldType, newType);
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.rewriters.IdRewriteFunction;
|
||||
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.fastutil.ints.Int2ObjectMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
import us.myles.viaversion.libs.gson.JsonObject;
|
||||
import us.myles.viaversion.libs.gson.JsonPrimitive;
|
||||
@ -37,13 +37,13 @@ import java.util.Map;
|
||||
|
||||
public abstract class LegacyBlockItemRewriter<T extends BackwardsProtocol> extends ItemRewriterBase<T> {
|
||||
|
||||
private static final Map<String, IntObjectMap<MappedLegacyBlockItem>> LEGACY_MAPPINGS = new HashMap<>();
|
||||
protected final IntObjectMap<MappedLegacyBlockItem> replacementData;
|
||||
private static final Map<String, Int2ObjectMap<MappedLegacyBlockItem>> LEGACY_MAPPINGS = new HashMap<>();
|
||||
protected final Int2ObjectMap<MappedLegacyBlockItem> replacementData;
|
||||
|
||||
static {
|
||||
JsonObject jsonObject = VBMappingDataLoader.loadFromDataDir("legacy-mappings.json");
|
||||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
|
||||
IntObjectMap<MappedLegacyBlockItem> mappings = CollectionUtil.createIntObjectMap(8);
|
||||
Int2ObjectMap<MappedLegacyBlockItem> mappings = new Int2ObjectOpenHashMap<>(8);
|
||||
LEGACY_MAPPINGS.put(entry.getKey(), mappings);
|
||||
for (Map.Entry<String, JsonElement> dataEntry : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
JsonObject object = dataEntry.getValue().getAsJsonObject();
|
||||
|
@ -11,13 +11,11 @@
|
||||
package nl.matsv.viabackwards.api.rewriters;
|
||||
|
||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||
import us.myles.ViaVersion.util.fastutil.IntObjectMap;
|
||||
|
||||
import java.util.Map;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public abstract class LegacySoundRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
|
||||
protected final IntObjectMap<SoundData> soundRewrites = CollectionUtil.createIntObjectMap(64);
|
||||
protected final Int2ObjectMap<SoundData> soundRewrites = new Int2ObjectOpenHashMap<>(64);
|
||||
|
||||
protected LegacySoundRewriter(T protocol) {
|
||||
super(protocol);
|
||||
@ -44,8 +42,8 @@ public abstract class LegacySoundRewriter<T extends BackwardsProtocol> extends R
|
||||
SoundData data = soundRewrites.get(soundId);
|
||||
if (data != null) return data.getReplacementSound();
|
||||
|
||||
for (Map.Entry<Integer, SoundData> entry : soundRewrites.getMap().entrySet()) {
|
||||
if (soundId > entry.getKey()) {
|
||||
for (Int2ObjectMap.Entry<SoundData> entry : soundRewrites.int2ObjectEntrySet()) {
|
||||
if (soundId > entry.getIntKey()) {
|
||||
if (entry.getValue().isAdded()) {
|
||||
newSoundId--;
|
||||
} else {
|
||||
|
@ -1,13 +1,14 @@
|
||||
package nl.matsv.viabackwards.protocol.protocol1_10to1_11;
|
||||
|
||||
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||
import us.myles.ViaVersion.util.fastutil.IntMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
public class PotionSplashHandler {
|
||||
|
||||
private static final IntMap DATA = CollectionUtil.createIntMap(14);
|
||||
private static final Int2IntMap DATA = new Int2IntOpenHashMap(14, 1F);
|
||||
|
||||
static {
|
||||
DATA.defaultReturnValue(-1);
|
||||
DATA.put(2039713, 5); // night vision
|
||||
DATA.put(8356754, 7); // invisibility
|
||||
DATA.put(2293580, 9); // jump boost
|
||||
|
@ -339,7 +339,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<Protocol1_10To
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
// Handle spawner block entity (map to itself with custom handler)
|
||||
MappedLegacyBlockItem data = replacementData.getMap().computeIfAbsent(52, s -> new MappedLegacyBlockItem(52, (short) -1, null, false));
|
||||
MappedLegacyBlockItem data = replacementData.computeIfAbsent(52, s -> new MappedLegacyBlockItem(52, (short) -1, null, false));
|
||||
data.setBlockEntityHandler((b, tag) -> {
|
||||
EntityIdRewriter.toClientSpawner(tag, true);
|
||||
return tag;
|
||||
|
@ -1,12 +1,13 @@
|
||||
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data;
|
||||
|
||||
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||
import us.myles.ViaVersion.util.fastutil.IntMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
public class MapColorMapping {
|
||||
private static final IntMap MAPPING = CollectionUtil.createIntMap(64);
|
||||
private static final Int2IntMap MAPPING = new Int2IntOpenHashMap(64, 1F);
|
||||
|
||||
static {
|
||||
MAPPING.defaultReturnValue(-1);
|
||||
MAPPING.put(144, 59); // (148, 124, 114) -> (148, 124, 114)
|
||||
MAPPING.put(145, 56); // (180, 153, 139) -> (180, 153, 139)
|
||||
MAPPING.put(146, 56); // (209, 177, 161) -> (209, 177, 161)
|
||||
|
@ -13,15 +13,15 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handler
|
||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
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.fastutil.ints.Int2ObjectMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
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.StringTag;
|
||||
|
||||
public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
|
||||
|
||||
private static final IntObjectMap<Pair<String, Byte>> FLOWERS = CollectionUtil.createIntObjectMap(22);
|
||||
private static final Int2ObjectMap<Pair<String, Byte>> FLOWERS = new Int2ObjectOpenHashMap<>(22, 1F);
|
||||
private static final Pair<String, Byte> AIR = new Pair<>("minecraft:air", (byte) 0);
|
||||
|
||||
static {
|
||||
|
@ -1,20 +1,23 @@
|
||||
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.util.fastutil.CollectionUtil;
|
||||
import us.myles.ViaVersion.util.fastutil.IntMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import us.myles.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class EntityTypeMapping {
|
||||
private static final IntMap TYPES = CollectionUtil.createIntMap();
|
||||
private static final Int2IntMap TYPES = new Int2IntOpenHashMap();
|
||||
|
||||
static {
|
||||
TYPES.defaultReturnValue(-1);
|
||||
try {
|
||||
Field field = EntityTypeRewriter.class.getDeclaredField("ENTITY_TYPES");
|
||||
field.setAccessible(true);
|
||||
IntMap entityTypes = (IntMap) field.get(null);
|
||||
entityTypes.getMap().forEach((type1_12, type1_13) -> EntityTypeMapping.TYPES.put(type1_13, type1_12));
|
||||
Int2IntMap entityTypes = (Int2IntMap) field.get(null);
|
||||
for (Int2IntMap.Entry entry : entityTypes.int2IntEntrySet()) {
|
||||
EntityTypeMapping.TYPES.put(entry.getIntValue(), entry.getIntKey());
|
||||
}
|
||||
} catch (NoSuchFieldException | IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
@ -101,8 +101,8 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int itemId = wrapper.read(Type.VAR_INT);
|
||||
Integer oldId = MappingData.oldToNewItems.inverse().get(itemId);
|
||||
if (oldId != null) {
|
||||
int oldId = MappingData.oldToNewItems.inverse().get(itemId);
|
||||
if (oldId != -1) {
|
||||
Optional<String> eggEntityId = SpawnEggRewriter.getEntityId(oldId);
|
||||
if (eggEntityId.isPresent()) {
|
||||
itemId = 383 << 16;
|
||||
@ -413,12 +413,12 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
int id = wrapper.get(Type.INT, 0);
|
||||
int data = wrapper.get(Type.INT, 1);
|
||||
if (id == 1010) { // Play record
|
||||
wrapper.set(Type.INT, 1, data = MappingData.oldToNewItems.inverse().get(data) >> 4);
|
||||
wrapper.set(Type.INT, 1, MappingData.oldToNewItems.inverse().get(data) >> 4);
|
||||
} else if (id == 2001) { // Block break + block break sound
|
||||
data = toOldId(data);
|
||||
int blockId = data >> 4;
|
||||
int blockData = data & 0xF;
|
||||
wrapper.set(Type.INT, 1, data = (blockId & 0xFFF) | (blockData << 12));
|
||||
wrapper.set(Type.INT, 1, (blockId & 0xFFF) | (blockData << 12));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -543,8 +543,8 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
|
||||
// No custom mapping found, look at VV mappings
|
||||
if (item.getIdentifier() == originalId) {
|
||||
Integer oldId = MappingData.oldToNewItems.inverse().get(item.getIdentifier());
|
||||
if (oldId != null) {
|
||||
int oldId = MappingData.oldToNewItems.inverse().get(item.getIdentifier());
|
||||
if (oldId != -1) {
|
||||
rawId = itemIdToRaw(oldId, item, tag);
|
||||
} else if (item.getIdentifier() == 362) { // base/colorless shulker box
|
||||
rawId = 0xe50000; // purple shulker box
|
||||
|
@ -13,16 +13,15 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage;
|
||||
import us.myles.ViaVersion.api.data.StoredObject;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||
import us.myles.ViaVersion.util.fastutil.IntSet;
|
||||
import us.myles.viaversion.libs.fastutil.ints.IntOpenHashSet;
|
||||
import us.myles.viaversion.libs.fastutil.ints.IntSet;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class BackwardsBlockStorage extends StoredObject {
|
||||
// This BlockStorage is very exclusive (;
|
||||
private static final IntSet WHITELIST = CollectionUtil.createIntSet(779);
|
||||
private static final IntSet WHITELIST = new IntOpenHashSet(779);
|
||||
|
||||
static {
|
||||
// Flower pots
|
||||
|
@ -122,8 +122,8 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
|
||||
for (int j = 0; j < itemIds.length; j++) {
|
||||
int itemId = itemIds[j];
|
||||
// Ignore new itemtags
|
||||
Integer oldId = MappingData.oldToNewItems.inverse().get(itemId);
|
||||
itemIds[j] = oldId != null ? oldId : -1;
|
||||
int oldId = MappingData.oldToNewItems.inverse().get(itemId);
|
||||
itemIds[j] = oldId;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -586,8 +586,8 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
|
||||
|
||||
public static int getNewItemId(int id) {
|
||||
Integer newId = MappingData.oldToNewItems.get(id);
|
||||
if (newId == null) {
|
||||
int newId = MappingData.oldToNewItems.get(id);
|
||||
if (newId == -1) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Missing 1.14 item for 1.13.2 item " + id);
|
||||
return 1;
|
||||
}
|
||||
@ -595,8 +595,8 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
}
|
||||
|
||||
public static int getOldItemId(int id) {
|
||||
Integer oldId = MappingData.oldToNewItems.inverse().get(id);
|
||||
if (oldId == null) {
|
||||
int oldId = MappingData.oldToNewItems.inverse().get(id);
|
||||
if (oldId == -1) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Missing 1.13.2 item for 1.14 item " + id);
|
||||
return 1;
|
||||
}
|
||||
|
@ -140,8 +140,8 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
|
||||
wrapper.passthrough(Type.STRING);
|
||||
int[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
|
||||
for (int j = 0; j < itemIds.length; j++) {
|
||||
Integer oldId = MappingData.oldToNewItems.inverse().get(itemIds[j]);
|
||||
itemIds[j] = oldId != null ? oldId : -1;
|
||||
int oldId = MappingData.oldToNewItems.inverse().get(itemIds[j]);
|
||||
itemIds[j] = oldId;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,8 +179,8 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
}
|
||||
|
||||
public static int getNewItemId(int id) {
|
||||
Integer newId = MappingData.oldToNewItems.get(id);
|
||||
if (newId == null) {
|
||||
int newId = MappingData.oldToNewItems.get(id);
|
||||
if (newId == -1) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Missing 1.15 item for 1.14.4 item " + id);
|
||||
return 1;
|
||||
}
|
||||
@ -189,8 +189,8 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
|
||||
|
||||
public static int getOldItemId(int id) {
|
||||
Integer oldId = MappingData.oldToNewItems.inverse().get(id);
|
||||
if (oldId == null) {
|
||||
int oldId = MappingData.oldToNewItems.inverse().get(id);
|
||||
if (oldId == -1) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Missing 1.14.4 item for 1.15 item " + id);
|
||||
return 1;
|
||||
}
|
||||
|
@ -159,10 +159,8 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
});
|
||||
|
||||
new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> {
|
||||
Integer oldId = MappingData.oldToNewItems.inverse().get(id);
|
||||
return oldId != null ? oldId : -1;
|
||||
}, entityPackets::getOldEntityId).register(ClientboundPackets1_16.TAGS);
|
||||
new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id ->
|
||||
MappingData.oldToNewItems.inverse().get(id), entityPackets::getOldEntityId).register(ClientboundPackets1_16.TAGS);
|
||||
|
||||
cancelIncoming(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK);
|
||||
}
|
||||
|
@ -274,8 +274,8 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
}
|
||||
|
||||
public static int getNewItemId(int id) {
|
||||
Integer newId = MappingData.oldToNewItems.get(id);
|
||||
if (newId == null) {
|
||||
int newId = MappingData.oldToNewItems.get(id);
|
||||
if (newId == -1) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Missing 1.16 item for 1.15 item " + id);
|
||||
return 1;
|
||||
}
|
||||
@ -283,8 +283,8 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
}
|
||||
|
||||
public static int getOldItemId(int id) {
|
||||
Integer oldId = MappingData.oldToNewItems.inverse().get(id);
|
||||
if (oldId == null) {
|
||||
int oldId = MappingData.oldToNewItems.inverse().get(id);
|
||||
if (oldId == -1) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Missing 1.15 item for 1.16 item " + id);
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user