Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
Fix Potions: ThrownPotion is now correct, and the particles are too.
Fixes #223 Also changes a tiny bit of javadoc :)
Dieser Commit ist enthalten in:
Ursprung
233a2ba5df
Commit
997c2ad6a1
@ -198,6 +198,7 @@ public class PacketWrapper {
|
|||||||
/**
|
/**
|
||||||
* Send this packet to the associated user.
|
* Send this packet to the associated user.
|
||||||
* Be careful not to send packets twice.
|
* Be careful not to send packets twice.
|
||||||
|
* (Sends it after current)
|
||||||
*
|
*
|
||||||
* @throws Exception if it fails to write
|
* @throws Exception if it fails to write
|
||||||
*/
|
*/
|
||||||
|
@ -18,6 +18,8 @@ public class ItemRewriter {
|
|||||||
private static final Map<String, Integer> POTION_NAME_TO_ID = new HashMap<>();
|
private static final Map<String, Integer> POTION_NAME_TO_ID = new HashMap<>();
|
||||||
private static final Map<Integer, String> POTION_ID_TO_NAME = new HashMap<>();
|
private static final Map<Integer, String> POTION_ID_TO_NAME = new HashMap<>();
|
||||||
|
|
||||||
|
private static final Map<Integer, Integer> POTION_INDEX = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
/* Entities */
|
/* Entities */
|
||||||
registerEntity(1, "Item");
|
registerEntity(1, "Item");
|
||||||
@ -84,6 +86,7 @@ public class ItemRewriter {
|
|||||||
registerEntity(200, "EnderCrystal");
|
registerEntity(200, "EnderCrystal");
|
||||||
|
|
||||||
/* Potions */
|
/* Potions */
|
||||||
|
registerPotion(-1, "empty");
|
||||||
registerPotion(0, "water");
|
registerPotion(0, "water");
|
||||||
registerPotion(64, "mundane");
|
registerPotion(64, "mundane");
|
||||||
registerPotion(32, "thick");
|
registerPotion(32, "thick");
|
||||||
@ -242,12 +245,20 @@ public class ItemRewriter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getNewEffectID(int oldID) {
|
||||||
|
if (oldID >= 16384) {
|
||||||
|
oldID -= 8192;
|
||||||
|
}
|
||||||
|
return POTION_INDEX.containsKey(oldID) ? POTION_INDEX.get(oldID) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static void registerEntity(Integer id, String name) {
|
private static void registerEntity(Integer id, String name) {
|
||||||
ENTTIY_ID_TO_NAME.put(id, name);
|
ENTTIY_ID_TO_NAME.put(id, name);
|
||||||
ENTTIY_NAME_TO_ID.put(name, id);
|
ENTTIY_NAME_TO_ID.put(name, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerPotion(Integer id, String name) {
|
private static void registerPotion(Integer id, String name) {
|
||||||
|
POTION_INDEX.put(id, POTION_ID_TO_NAME.size());
|
||||||
POTION_ID_TO_NAME.put(id, name);
|
POTION_ID_TO_NAME.put(id, name);
|
||||||
POTION_NAME_TO_ID.put(name, id);
|
POTION_NAME_TO_ID.put(name, id);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
|
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
@ -11,11 +12,14 @@ import us.myles.ViaVersion.api.remapper.ValueCreator;
|
|||||||
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||||
import us.myles.ViaVersion.util.EntityUtil;
|
import us.myles.ViaVersion.util.EntityUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SpawnPackets {
|
public class SpawnPackets {
|
||||||
@ -81,6 +85,34 @@ public class SpawnPackets {
|
|||||||
wrapper.write(Type.SHORT, vZ);
|
wrapper.write(Type.SHORT, vZ);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle potions
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
final int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||||
|
final int data = wrapper.get(Type.INT, 0); // Data
|
||||||
|
|
||||||
|
int typeID = wrapper.get(Type.BYTE, 0);
|
||||||
|
if (EntityUtil.getTypeFromID(typeID, true) == EntityType.SPLASH_POTION) {
|
||||||
|
// Convert this to meta data, woo!
|
||||||
|
PacketWrapper metaPacket = wrapper.create(0x39, new ValueCreator() {
|
||||||
|
@Override
|
||||||
|
public void write(PacketWrapper wrapper) throws Exception {
|
||||||
|
wrapper.write(Type.VAR_INT, entityID);
|
||||||
|
List<Metadata> meta = new ArrayList<>();
|
||||||
|
Item item = new Item((short) Material.POTION.getId(), (byte) 1, (short) data, null);
|
||||||
|
ItemRewriter.toClient(item); // Rewrite so that it gets the right nbt
|
||||||
|
|
||||||
|
Metadata potion = new Metadata(5, NewType.Slot.getTypeID(), Type.ITEM, item);
|
||||||
|
meta.add(potion);
|
||||||
|
wrapper.write(Protocol1_9TO1_8.METADATA_LIST, meta);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
metaPacket.send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import us.myles.ViaVersion.api.remapper.ValueCreator;
|
|||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.SoundEffect;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.SoundEffect;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
||||||
@ -40,7 +41,9 @@ public class WorldPackets {
|
|||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.INT); // 0 - Effect ID
|
map(Type.INT); // 0 - Effect ID
|
||||||
// Everything else get's written through
|
map(Type.POSITION); // 1 - Position
|
||||||
|
map(Type.INT); // 2 - Data
|
||||||
|
map(Type.BOOLEAN); // 3 - Disable relative volume
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
@ -55,6 +58,18 @@ public class WorldPackets {
|
|||||||
wrapper.set(Type.INT, 0, id);
|
wrapper.set(Type.INT, 0, id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// Rewrite potion effect as it changed to use a dynamic registry
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
int id = wrapper.get(Type.INT, 0);
|
||||||
|
if (id == 2002) {
|
||||||
|
int data = wrapper.get(Type.INT, 1);
|
||||||
|
int newData = ItemRewriter.getNewEffectID(data);
|
||||||
|
wrapper.set(Type.INT, 1, newData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren