package protocolsupport.protocol.typeremapper.legacy;

import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.map.hash.TObjectIntHashMap;
import protocolsupport.protocol.utils.minecraftdata.MinecraftData;

public class LegacyPotion {

	private static final TObjectIntHashMap<String> toLegacyId = new TObjectIntHashMap<>();
	private static final TIntObjectHashMap<String> fromLegacyId = new TIntObjectHashMap<>();
	static {
		register("night_vision", 8198);
		register("long_night_vision", 8262);
        register("invisibility", 8206);
        register("long_invisibility", 8270);
        register("leaping", 8203);
        register("long_leaping", 8267);
        register("strong_leaping", 8235);
        register("fire_resistance", 8195);
        register("long_fire_resistance", 8259);
        register("swiftness", 8194);
        register("long_swiftness", 8258);
        register("strong_swiftness", 8226);
        register("slowness", 8202);
        register("long_slowness", 8266);
        register("water_breathing", 8205);
        register("long_water_breathing", 8269);
        register("healing", 8197);
        register("strong_healing", 8229);
        register("harming", 8204);
        register("strong_harming", 8236);
        register("poison", 8196);
        register("long_poison", 8260);
        register("strong_poison", 8228);
        register("regeneration", 8193);
        register("long_regeneration", 8257);
        register("strong_regeneration", 8225);
        register("strength", 8201);
        register("long_strength", 8265);
        register("strong_strength", 8233);
        register("weakness", 8200);
        register("long_weakness", 8264);
	}

	private static void register(String name, int id) {
		toLegacyId.put(name, id);
		toLegacyId.put(MinecraftData.addNamespacePrefix(name), id);
		fromLegacyId.put(id, MinecraftData.addNamespacePrefix(name));
	}

	public static int toLegacyId(String nbttag, boolean isThrowable) {
		int value = toLegacyId.get(nbttag);
		return isThrowable ? value + 8192 : value;
	}

	public static boolean isThrowable(int legacyId) {
		return legacyId > 16384;
	}

	public static String fromLegacyId(int legacyId) {
		if (isThrowable(legacyId)) {
			legacyId -= 8192;
		}
		return fromLegacyId.get(legacyId);
	}

	public static String getBasicTypeName(String nbttag) {
		switch (nbttag) {
			case "mundane":
			case "minecraft:mundane": {
				return "potion.effect.mundane";
			}
			case "thick":
			case "minecraft:thick": {
				return "potion.effect.thick";
			}
			case "awkward":
			case "minecraft:awkward": {
				return "potion.effect.awkward";
			}
			default: {
				return null;
			}
		}
	}

}

@@ -455,11 +455,11 @@
 %22, 8
-198
+230
 );%0A%09
@@ -535,10 +535,10 @@
 , 82
-06
+38
 );%0A 
@@ -739,11 +739,11 @@
 %22, 8
-195
+227
 );%0A 
@@ -947,10 +947,10 @@
 , 82
-02
+34
 );%0A 
@@ -1031,10 +1031,10 @@
 , 82
-05
+37
 );%0A 
@@ -1113,11 +1113,11 @@
 %22, 8
-197
+261
 );%0A 
@@ -1191,10 +1191,10 @@
 , 82
-04
+68
 );%0A 
@@ -1635,10 +1635,10 @@
 , 82
-00
+32
 );%0A 

Use correct legacy potion ids