mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-24 09:27:52 +01:00
Effect ids start at 1 before 1.20.2
This commit is contained in:
parent
f618f6a7d6
commit
cb073405b7
@ -44,6 +44,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<ClientboundPackets1_19_4, ServerboundPackets1_20_2, Protocol1_20_2To1_20> {
|
public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<ClientboundPackets1_19_4, ServerboundPackets1_20_2, Protocol1_20_2To1_20> {
|
||||||
|
|
||||||
public static final String[] POTION_EFFECTS = {
|
public static final String[] POTION_EFFECTS = {
|
||||||
|
"", // No effect
|
||||||
"speed",
|
"speed",
|
||||||
"slowness",
|
"slowness",
|
||||||
"haste",
|
"haste",
|
||||||
@ -85,6 +86,13 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerPackets() {
|
public void registerPackets() {
|
||||||
|
protocol.registerServerbound(ServerboundPackets1_20_2.SET_BEACON_EFFECT, wrapper -> {
|
||||||
|
if (wrapper.passthrough(Type.BOOLEAN)) {
|
||||||
|
// Effects start at 1 before 1.20.2
|
||||||
|
wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT) + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_19_4.UNLOAD_CHUNK, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_19_4.UNLOAD_CHUNK, wrapper -> {
|
||||||
final int x = wrapper.read(Type.INT);
|
final int x = wrapper.read(Type.INT);
|
||||||
final int z = wrapper.read(Type.INT);
|
final int z = wrapper.read(Type.INT);
|
||||||
@ -346,20 +354,19 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Weird disconnect when setting effect type in inventory, probably unrelated to this, but needs fixing
|
|
||||||
final IntTag primaryEffect = tag.remove("Primary");
|
final IntTag primaryEffect = tag.remove("Primary");
|
||||||
if (primaryEffect != null) {
|
if (primaryEffect != null && primaryEffect.asInt() != 0) {
|
||||||
tag.put("primary_effect", new StringTag(effect(primaryEffect.asInt())));
|
tag.put("primary_effect", new StringTag(effect(primaryEffect.asInt())));
|
||||||
}
|
}
|
||||||
|
|
||||||
final IntTag secondaryEffect = tag.remove("Secondary");
|
final IntTag secondaryEffect = tag.remove("Secondary");
|
||||||
if (secondaryEffect != null) {
|
if (secondaryEffect != null && secondaryEffect.asInt() != 0) {
|
||||||
tag.put("secondary_effect", new StringTag(effect(secondaryEffect.asInt())));
|
tag.put("secondary_effect", new StringTag(effect(secondaryEffect.asInt())));
|
||||||
}
|
}
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String effect(final int id) {
|
private String effect(final int id) {
|
||||||
return id >= 0 && id < POTION_EFFECTS.length ? Key.namespaced(POTION_EFFECTS[id]) : "minecraft:speed";
|
return id >= 1 && id < POTION_EFFECTS.length ? Key.namespaced(POTION_EFFECTS[id]) : "minecraft:luck";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -127,7 +127,7 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
|
|||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_19_4.ENTITY_EFFECT, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_19_4.ENTITY_EFFECT, wrapper -> {
|
||||||
wrapper.passthrough(Type.VAR_INT); // Entity id
|
wrapper.passthrough(Type.VAR_INT); // Entity id
|
||||||
wrapper.passthrough(Type.VAR_INT); // Effect id
|
wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT) - 1); // Effect id
|
||||||
wrapper.passthrough(Type.BYTE); // Amplifier
|
wrapper.passthrough(Type.BYTE); // Amplifier
|
||||||
wrapper.passthrough(Type.VAR_INT); // Duration
|
wrapper.passthrough(Type.VAR_INT); // Duration
|
||||||
wrapper.passthrough(Type.BYTE); // Flags
|
wrapper.passthrough(Type.BYTE); // Flags
|
||||||
@ -135,6 +135,11 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter<Clientbound
|
|||||||
wrapper.write(Type.NAMELESS_NBT, wrapper.read(Type.NBT)); // Factor data
|
wrapper.write(Type.NAMELESS_NBT, wrapper.read(Type.NBT)); // Factor data
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
protocol.registerClientbound(ClientboundPackets1_19_4.REMOVE_ENTITY_EFFECT, wrapper -> {
|
||||||
|
wrapper.passthrough(Type.VAR_INT); // Entity id
|
||||||
|
wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT) - 1); // Effect id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user