minor code improvements

This commit is contained in:
Koppe 2020-08-10 22:28:40 +02:00
parent 0b17b81b63
commit 93c84b1912
2 changed files with 10 additions and 12 deletions

View File

@ -270,17 +270,19 @@ public class Protocol1_11To1_10 extends Protocol<ClientboundPackets1_9_3, Client
this.map(Type.INT); //effectData this.map(Type.INT); //effectData
this.map(Type.BOOLEAN); //serverwide / global this.map(Type.BOOLEAN); //serverwide / global
handler(packetWrapper -> { handler(packetWrapper -> {
final int effectID = packetWrapper.get(Type.INT, 0); int effectID = packetWrapper.get(Type.INT, 0);
if (effectID == 2002) { if (effectID == 2002) {
int data = packetWrapper.get(Type.INT, 1); int data = packetWrapper.get(Type.INT, 1);
final Pair<Integer, Boolean> newData = PotionColorMapping.getNewData(data); boolean isInstant = false;
if (newData.getKey() == -1) { Pair<Integer, Boolean> newData = PotionColorMapping.getNewData(data);
if (newData == null) {
Via.getPlatform().getLogger().warning("Received unknown 1.11 -> 1.10.2 potion data (" + data + ")"); Via.getPlatform().getLogger().warning("Received unknown 1.11 -> 1.10.2 potion data (" + data + ")");
data = 0; data = 0;
} else { } else {
data = newData.getKey(); data = newData.getKey();
isInstant = newData.getValue();
} }
if (newData.getValue()) { if (isInstant) {
packetWrapper.set(Type.INT, 0, 2007); packetWrapper.set(Type.INT, 0, 2007);
} }
packetWrapper.set(Type.INT, 1, data); packetWrapper.set(Type.INT, 1, data);

View File

@ -7,7 +7,7 @@ import us.myles.ViaVersion.api.Pair;
public class PotionColorMapping { public class PotionColorMapping {
//<oldData> to <newData, isInstant> mapping //<oldData> to <newData, isInstant> mapping
private static final Int2ObjectMap<Pair<Integer, Boolean>> POTIONS = new Int2ObjectOpenHashMap<>(17, 1.0F); private static final Int2ObjectMap<Pair<Integer, Boolean>> POTIONS = new Int2ObjectOpenHashMap<>(37, 1.0F);
static { static {
addRewrite(0, 3694022, false); addRewrite(0, 3694022, false);
@ -49,15 +49,11 @@ public class PotionColorMapping {
addRewrite(36, 3381504, false); addRewrite(36, 3381504, false);
} }
public static Pair<Integer, Boolean> getNewData(final int oldData) { public static Pair<Integer, Boolean> getNewData(int oldData) {
return POTIONS.getOrDefault(oldData, new Pair<>(-1, false)); return POTIONS.get(oldData);
} }
public static boolean contains(final int oldData) { private static void addRewrite(int oldData, int newData, boolean isInstant) {
return POTIONS.containsKey(oldData);
}
private static void addRewrite(final int oldData, final int newData, final boolean isInstant) {
POTIONS.put(oldData, new Pair<>(newData, isInstant)); POTIONS.put(oldData, new Pair<>(newData, isInstant));
} }