Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-11-20 06:50:10 +01:00
Merge pull request #77 from Gerrygames/1.13
sound and entity id mappings
Dieser Commit ist enthalten in:
Commit
cc68ef758f
@ -0,0 +1,309 @@
|
|||||||
|
package nl.matsv.viabackwards.api.entities.types;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import nl.matsv.viabackwards.ViaBackwards;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
public class EntityType1_13 {
|
||||||
|
|
||||||
|
public static EntityType getTypeFromId(int typeID, boolean isObject) {
|
||||||
|
Optional<EntityType> type;
|
||||||
|
|
||||||
|
if (isObject)
|
||||||
|
type = ObjectType.getPCEntity(typeID);
|
||||||
|
else
|
||||||
|
type = EntityType.findById(typeID);
|
||||||
|
|
||||||
|
if (!type.isPresent()) {
|
||||||
|
ViaBackwards.getPlatform().getLogger().severe("[EntityType1_13] Could not find type id " + typeID + " isObject=" + isObject);
|
||||||
|
return EntityType.ENTITY; // Fall back to the basic ENTITY
|
||||||
|
}
|
||||||
|
|
||||||
|
return type.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum EntityType implements AbstractEntityType {
|
||||||
|
ENTITY(-1),
|
||||||
|
|
||||||
|
AREA_EFFECT_CLOUD(0, ENTITY),
|
||||||
|
ENDER_CRYSTAL(16, ENTITY),
|
||||||
|
EVOCATION_FANGS(20, ENTITY),
|
||||||
|
XP_ORB(22, ENTITY),
|
||||||
|
EYE_OF_ENDER_SIGNAL(23, ENTITY),
|
||||||
|
FALLING_BLOCK(24, ENTITY),
|
||||||
|
FIREWORKS_ROCKET(25, ENTITY),
|
||||||
|
ITEM(32, ENTITY),
|
||||||
|
LLAMA_SPIT(37, ENTITY),
|
||||||
|
TNT(55, ENTITY),
|
||||||
|
SHULKER_BULLET(60, ENTITY),
|
||||||
|
FISHING_BOBBER(93, ENTITY),
|
||||||
|
|
||||||
|
LIVINGENTITY(-1, ENTITY),
|
||||||
|
ARMOR_STAND(1, LIVINGENTITY),
|
||||||
|
PLAYER(92, LIVINGENTITY),
|
||||||
|
|
||||||
|
ABSTRACT_INSENTIENT(-1, LIVINGENTITY),
|
||||||
|
ENDER_DRAGON(17, ABSTRACT_INSENTIENT),
|
||||||
|
|
||||||
|
ABSTRACT_CREATURE(-1, ABSTRACT_INSENTIENT),
|
||||||
|
|
||||||
|
ABSTRACT_AGEABLE(-1, ABSTRACT_CREATURE),
|
||||||
|
VILLAGER(79, ABSTRACT_AGEABLE),
|
||||||
|
|
||||||
|
// Animals
|
||||||
|
ABSTRACT_ANIMAL(-1, ABSTRACT_AGEABLE),
|
||||||
|
CHICKEN(7, ABSTRACT_ANIMAL),
|
||||||
|
COW(9, ABSTRACT_ANIMAL),
|
||||||
|
MOOSHROOM(47, COW),
|
||||||
|
PIG(51, ABSTRACT_ANIMAL),
|
||||||
|
POLAR_BEAR(54, ABSTRACT_ANIMAL),
|
||||||
|
RABBIT(56, ABSTRACT_ANIMAL),
|
||||||
|
SHEEP(58, ABSTRACT_ANIMAL),
|
||||||
|
TURTLE(73, ABSTRACT_ANIMAL),
|
||||||
|
|
||||||
|
ABSTRACT_TAMEABLE_ANIMAL(-1, ABSTRACT_ANIMAL),
|
||||||
|
OCELOT(48, ABSTRACT_TAMEABLE_ANIMAL),
|
||||||
|
WOLF(86, ABSTRACT_TAMEABLE_ANIMAL),
|
||||||
|
|
||||||
|
ABSTRACT_PARROT(-1, ABSTRACT_TAMEABLE_ANIMAL),
|
||||||
|
PARROT(50, ABSTRACT_PARROT),
|
||||||
|
|
||||||
|
|
||||||
|
// Horses
|
||||||
|
ABSTRACT_HORSE(-1, ABSTRACT_ANIMAL),
|
||||||
|
CHESTED_HORSE(-1, ABSTRACT_HORSE),
|
||||||
|
DONKEY(11, CHESTED_HORSE),
|
||||||
|
MULE(46, CHESTED_HORSE),
|
||||||
|
LLAMA(36, CHESTED_HORSE),
|
||||||
|
HORSE(29, ABSTRACT_HORSE),
|
||||||
|
SKELETON_HORSE(63, ABSTRACT_HORSE),
|
||||||
|
ZOMBIE_HORSE(88, ABSTRACT_HORSE),
|
||||||
|
|
||||||
|
// Golem
|
||||||
|
ABSTRACT_GOLEM(-1, ABSTRACT_CREATURE),
|
||||||
|
SNOWMAN(66, ABSTRACT_GOLEM),
|
||||||
|
VILLAGER_GOLEM(80, ABSTRACT_GOLEM),
|
||||||
|
SHULKER(59, ABSTRACT_GOLEM),
|
||||||
|
|
||||||
|
// Fish
|
||||||
|
ABSTRACT_FISHES(-1, ABSTRACT_CREATURE),
|
||||||
|
COD_MOB(8, ABSTRACT_FISHES),
|
||||||
|
PUFFER_FISH(52, ABSTRACT_FISHES),
|
||||||
|
SALMON_MOB(57, ABSTRACT_FISHES),
|
||||||
|
TROPICAL_FISH(72, ABSTRACT_FISHES),
|
||||||
|
|
||||||
|
|
||||||
|
// Monsters
|
||||||
|
ABSTRACT_MONSTER(-1, ABSTRACT_CREATURE),
|
||||||
|
BLAZE(4, ABSTRACT_MONSTER),
|
||||||
|
CREEPER(10, ABSTRACT_MONSTER),
|
||||||
|
ENDERMITE(19, ABSTRACT_MONSTER),
|
||||||
|
ENDERMAN(18, ABSTRACT_MONSTER),
|
||||||
|
GIANT(27, ABSTRACT_MONSTER),
|
||||||
|
SILVERFISH(61, ABSTRACT_MONSTER),
|
||||||
|
VEX(78, ABSTRACT_MONSTER),
|
||||||
|
WITCH(82, ABSTRACT_MONSTER),
|
||||||
|
WITHER(83, ABSTRACT_MONSTER),
|
||||||
|
|
||||||
|
// Illagers
|
||||||
|
ABSTRACT_ILLAGER_BASE(-1, ABSTRACT_MONSTER),
|
||||||
|
ABSTRACT_EVO_ILLU_ILLAGER(-1, ABSTRACT_ILLAGER_BASE),
|
||||||
|
EVOCATION_ILLAGER(21, ABSTRACT_EVO_ILLU_ILLAGER),
|
||||||
|
ILLUSION_ILLAGER(31, ABSTRACT_EVO_ILLU_ILLAGER),
|
||||||
|
VINDICATION_ILLAGER(81, ABSTRACT_ILLAGER_BASE),
|
||||||
|
|
||||||
|
// Skeletons
|
||||||
|
ABSTRACT_SKELETON(-1, ABSTRACT_MONSTER),
|
||||||
|
SKELETON(62, ABSTRACT_SKELETON),
|
||||||
|
STRAY(71, ABSTRACT_SKELETON),
|
||||||
|
WITHER_SKELETON(84, ABSTRACT_SKELETON),
|
||||||
|
|
||||||
|
// Guardians
|
||||||
|
GUARDIAN(28, ABSTRACT_MONSTER),
|
||||||
|
ELDER_GUARDIAN(15, GUARDIAN),
|
||||||
|
|
||||||
|
// Spiders
|
||||||
|
SPIDER(69, ABSTRACT_MONSTER),
|
||||||
|
CAVE_SPIDER(6, SPIDER),
|
||||||
|
|
||||||
|
// Zombies - META CHECKED
|
||||||
|
ZOMBIE(87, ABSTRACT_MONSTER),
|
||||||
|
DROWNED(14, ZOMBIE),
|
||||||
|
HUSK(30, ZOMBIE),
|
||||||
|
ZOMBIE_PIGMAN(53, ZOMBIE),
|
||||||
|
ZOMBIE_VILLAGER(89, ZOMBIE),
|
||||||
|
|
||||||
|
// Flying entities
|
||||||
|
ABSTRACT_FLYING(-1, ABSTRACT_INSENTIENT),
|
||||||
|
GHAST(26, ABSTRACT_FLYING),
|
||||||
|
PHANTOM(90, ABSTRACT_FLYING),
|
||||||
|
|
||||||
|
ABSTRACT_AMBIENT(-1, ABSTRACT_INSENTIENT),
|
||||||
|
BAT(3, ABSTRACT_AMBIENT),
|
||||||
|
|
||||||
|
ABSTRACT_WATERMOB(-1, ABSTRACT_INSENTIENT),
|
||||||
|
SQUID(70, ABSTRACT_WATERMOB),
|
||||||
|
|
||||||
|
// Slimes
|
||||||
|
SLIME(64, ABSTRACT_INSENTIENT),
|
||||||
|
MAGMA_CUBE(38, SLIME),
|
||||||
|
|
||||||
|
// Hangable objects
|
||||||
|
ABSTRACT_HANGING(-1, ENTITY),
|
||||||
|
LEASH_KNOT(35, ABSTRACT_HANGING),
|
||||||
|
ITEM_FRAME(33, ABSTRACT_HANGING),
|
||||||
|
PAINTING(49, ABSTRACT_HANGING),
|
||||||
|
|
||||||
|
ABSTRACT_LIGHTNING(-1, ENTITY),
|
||||||
|
LIGHTNING_BOLT(91, ABSTRACT_LIGHTNING),
|
||||||
|
|
||||||
|
// Arrows
|
||||||
|
ABSTRACT_ARROW(-1, ENTITY),
|
||||||
|
ARROW(2, ABSTRACT_ARROW),
|
||||||
|
SPECTRAL_ARROW(68, ABSTRACT_ARROW),
|
||||||
|
TRIDENT(94, ABSTRACT_ARROW),
|
||||||
|
|
||||||
|
// Fireballs
|
||||||
|
ABSTRACT_FIREBALL(-1, ENTITY),
|
||||||
|
DRAGON_FIREBALL(13, ABSTRACT_FIREBALL),
|
||||||
|
FIREBALL(34, ABSTRACT_FIREBALL),
|
||||||
|
SMALL_FIREBALL(65, ABSTRACT_FIREBALL),
|
||||||
|
WITHER_SKULL(85, ABSTRACT_FIREBALL),
|
||||||
|
|
||||||
|
// Projectiles
|
||||||
|
PROJECTILE_ABSTRACT(-1, ENTITY),
|
||||||
|
SNOWBALL(67, PROJECTILE_ABSTRACT),
|
||||||
|
ENDER_PEARL(75, PROJECTILE_ABSTRACT),
|
||||||
|
EGG(74, PROJECTILE_ABSTRACT),
|
||||||
|
POTION(77, PROJECTILE_ABSTRACT),
|
||||||
|
XP_BOTTLE(76, PROJECTILE_ABSTRACT),
|
||||||
|
|
||||||
|
// Vehicles
|
||||||
|
MINECART_ABSTRACT(-1, ENTITY),
|
||||||
|
CHESTED_MINECART_ABSTRACT(-1, MINECART_ABSTRACT),
|
||||||
|
CHEST_MINECART(40, CHESTED_MINECART_ABSTRACT),
|
||||||
|
HOPPER_MINECART(43, CHESTED_MINECART_ABSTRACT),
|
||||||
|
MINECART(39, MINECART_ABSTRACT),
|
||||||
|
FURNACE_MINECART(42, MINECART_ABSTRACT),
|
||||||
|
COMMANDBLOCK_MINECART(41, MINECART_ABSTRACT),
|
||||||
|
TNT_MINECART(45, MINECART_ABSTRACT),
|
||||||
|
SPAWNER_MINECART(44, MINECART_ABSTRACT),
|
||||||
|
BOAT(5, ENTITY);
|
||||||
|
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
private final EntityType parent;
|
||||||
|
|
||||||
|
EntityType(int id) {
|
||||||
|
this.id = id;
|
||||||
|
this.parent = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<EntityType> findById(int id) {
|
||||||
|
if (id == -1) // Check if this is called
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
for (EntityType ent : EntityType.values())
|
||||||
|
if (ent.getId() == id)
|
||||||
|
return Optional.of(ent);
|
||||||
|
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean is(AbstractEntityType... types) {
|
||||||
|
for (AbstractEntityType type : types)
|
||||||
|
if (is(type))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean is(AbstractEntityType type) {
|
||||||
|
return this == type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOrHasParent(AbstractEntityType type) {
|
||||||
|
EntityType parent = this;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (parent == type)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
parent = parent.getParent();
|
||||||
|
} while (parent != null);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AbstractEntityType> getParents() {
|
||||||
|
List<AbstractEntityType> types = new ArrayList<>();
|
||||||
|
EntityType parent = this;
|
||||||
|
|
||||||
|
do {
|
||||||
|
types.add(parent);
|
||||||
|
parent = parent.getParent();
|
||||||
|
} while (parent != null);
|
||||||
|
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum ObjectType implements AbstractObjectType {
|
||||||
|
BOAT(1, EntityType.BOAT),
|
||||||
|
ITEM(2, EntityType.ITEM),
|
||||||
|
AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD),
|
||||||
|
MINECART(10, EntityType.MINECART_ABSTRACT),
|
||||||
|
TNT_PRIMED(50, EntityType.TNT),
|
||||||
|
ENDER_CRYSTAL(51, EntityType.ENDER_CRYSTAL),
|
||||||
|
TIPPED_ARROW(60, EntityType.ARROW),
|
||||||
|
SNOWBALL(61, EntityType.SNOWBALL),
|
||||||
|
EGG(62, EntityType.EGG),
|
||||||
|
FIREBALL(63, EntityType.FIREBALL),
|
||||||
|
SMALL_FIREBALL(64, EntityType.SMALL_FIREBALL),
|
||||||
|
ENDER_PEARL(65, EntityType.ENDER_PEARL),
|
||||||
|
WITHER_SKULL(66, EntityType.WITHER_SKULL),
|
||||||
|
SHULKER_BULLET(67, EntityType.SHULKER_BULLET),
|
||||||
|
LIAMA_SPIT(68, EntityType.LLAMA_SPIT),
|
||||||
|
FALLING_BLOCK(70, EntityType.FALLING_BLOCK),
|
||||||
|
ITEM_FRAME(71, EntityType.ITEM_FRAME),
|
||||||
|
ENDER_SIGNAL(72, EntityType.EYE_OF_ENDER_SIGNAL),
|
||||||
|
POTION(73, EntityType.POTION),
|
||||||
|
THROWN_EXP_BOTTLE(75, EntityType.XP_BOTTLE),
|
||||||
|
FIREWORK(76, EntityType.FIREWORKS_ROCKET),
|
||||||
|
LEASH(77, EntityType.LEASH_KNOT),
|
||||||
|
ARMOR_STAND(78, EntityType.ARMOR_STAND),
|
||||||
|
EVOCATION_FANGS(79, EntityType.EVOCATION_FANGS),
|
||||||
|
FISHIHNG_HOOK(90, EntityType.FISHING_BOBBER),
|
||||||
|
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||||
|
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
private final EntityType type;
|
||||||
|
|
||||||
|
public static Optional<ObjectType> findById(int id) {
|
||||||
|
if (id == -1)
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
|
for (ObjectType ent : ObjectType.values())
|
||||||
|
if (ent.getId() == id)
|
||||||
|
return Optional.of(ent);
|
||||||
|
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<EntityType> getPCEntity(int id) {
|
||||||
|
Optional<ObjectType> output = findById(id);
|
||||||
|
|
||||||
|
return output.map(ObjectType::getType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,11 +11,14 @@
|
|||||||
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13;
|
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13;
|
||||||
|
|
||||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||||
|
import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
|
||||||
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.SoundMapping;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPackets1_13;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPackets1_13;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.EntityPackets1_13;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.EntityPackets1_13;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.PlayerPacket1_13;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.PlayerPacket1_13;
|
||||||
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.SoundPackets1_13;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
@ -30,12 +33,11 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
|
|||||||
new BlockItemPackets1_13().register(this);
|
new BlockItemPackets1_13().register(this);
|
||||||
new EntityPackets1_13().register(this);
|
new EntityPackets1_13().register(this);
|
||||||
new PlayerPacket1_13().register(this);
|
new PlayerPacket1_13().register(this);
|
||||||
|
new SoundPackets1_13().register(this);
|
||||||
|
|
||||||
// Thanks to https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14150
|
// Thanks to https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14150
|
||||||
|
|
||||||
|
|
||||||
out(State.PLAY, 0x00, 0x00, cancel()); // Spawn Object TODO type ids
|
|
||||||
out(State.PLAY, 0x03, 0x03, cancel()); // Spawn Mob TODO Metadata, type ids
|
|
||||||
out(State.PLAY, 0x07, 0x07, cancel()); // Statistics TODO MODIFIED
|
out(State.PLAY, 0x07, 0x07, cancel()); // Statistics TODO MODIFIED
|
||||||
out(State.PLAY, 0x09, 0x09, cancel()); // Update Block Entity TODO MODIFIED
|
out(State.PLAY, 0x09, 0x09, cancel()); // Update Block Entity TODO MODIFIED
|
||||||
out(State.PLAY, 0x0E, 0x0F); // Chat Message (clientbound)
|
out(State.PLAY, 0x0E, 0x0F); // Chat Message (clientbound)
|
||||||
@ -48,7 +50,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
|
|||||||
out(State.PLAY, 0x16, 0x15); // Window Property
|
out(State.PLAY, 0x16, 0x15); // Window Property
|
||||||
out(State.PLAY, 0x18, 0x17); // Set Cooldown
|
out(State.PLAY, 0x18, 0x17); // Set Cooldown
|
||||||
out(State.PLAY, 0x19, 0x18); // Plugin Message (clientbound) TODO MODIFIED
|
out(State.PLAY, 0x19, 0x18); // Plugin Message (clientbound) TODO MODIFIED
|
||||||
out(State.PLAY, 0x1A, 0x19, cancel()); // Named Sound Effect TODO MODIFIED
|
|
||||||
out(State.PLAY, 0x1B, 0x1A); // Disconnect (play)
|
out(State.PLAY, 0x1B, 0x1A); // Disconnect (play)
|
||||||
out(State.PLAY, 0x1C, 0x1B); // Entity Status
|
out(State.PLAY, 0x1C, 0x1B); // Entity Status
|
||||||
out(State.PLAY, 0x1D, -1, cancel()); // NBT Query Response (client won't send a request, so the server should not answer)
|
out(State.PLAY, 0x1D, -1, cancel()); // NBT Query Response (client won't send a request, so the server should not answer)
|
||||||
@ -114,7 +115,6 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
|
|||||||
out(State.PLAY, 0x4A, 0x47); // Time Update
|
out(State.PLAY, 0x4A, 0x47); // Time Update
|
||||||
out(State.PLAY, 0x4B, 0x48); // Title
|
out(State.PLAY, 0x4B, 0x48); // Title
|
||||||
out(State.PLAY, 0x4C, -1, cancel()); // Stop Sound TODO NEW
|
out(State.PLAY, 0x4C, -1, cancel()); // Stop Sound TODO NEW
|
||||||
out(State.PLAY, 0x4D, 0x49); // Sound Effect
|
|
||||||
out(State.PLAY, 0x4E, 0x4A); // Player List Header And Footer
|
out(State.PLAY, 0x4E, 0x4A); // Player List Header And Footer
|
||||||
out(State.PLAY, 0x4F, 0x4B); // Collect Item
|
out(State.PLAY, 0x4F, 0x4B); // Collect Item
|
||||||
out(State.PLAY, 0x50, 0x4C); // Entity Teleport
|
out(State.PLAY, 0x50, 0x4C); // Entity Teleport
|
||||||
@ -169,6 +169,12 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
|
|||||||
if (!user.has(ClientWorld.class))
|
if (!user.has(ClientWorld.class))
|
||||||
user.put(new ClientWorld(user));
|
user.put(new ClientWorld(user));
|
||||||
|
|
||||||
|
// Register EntityTracker if it doesn't exist yet.
|
||||||
|
if (!user.has(EntityTracker.class))
|
||||||
|
user.put(new EntityTracker(user));
|
||||||
|
|
||||||
|
// Init protocol in EntityTracker
|
||||||
|
user.get(EntityTracker.class).initProtocol(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketRemapper cancel() {
|
public PacketRemapper cancel() {
|
||||||
@ -188,6 +194,7 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol {
|
|||||||
static {
|
static {
|
||||||
BackwardsMappings.init();
|
BackwardsMappings.init();
|
||||||
PaintingMapping.init();
|
PaintingMapping.init();
|
||||||
|
SoundMapping.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class EntityTypeMapping {
|
||||||
|
private static Map<Integer, Integer> entityTypes = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes");
|
||||||
|
field.setAccessible(true);
|
||||||
|
Map<Integer, Integer> entityTypes = (Map<Integer, Integer>) field.get(null);
|
||||||
|
entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.entityTypes.put(type1_13, type1_12));
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<Integer> getOldId(int type1_13) {
|
||||||
|
return Optional.ofNullable(entityTypes.get(type1_13));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class NamedSoundMapping {
|
||||||
|
private static Map<String, String> sounds = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
Field field = NamedSoundRewriter.class.getDeclaredField("oldToNew");
|
||||||
|
field.setAccessible(true);
|
||||||
|
Map<String, String> sounds = (Map<String, String>) field.get(null);
|
||||||
|
sounds.forEach((sound1_12, sound1_13) -> NamedSoundMapping.sounds.put(sound1_13, sound1_12));
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getOldId(String sound1_13) {
|
||||||
|
return sounds.get(sound1_13);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
|
||||||
|
|
||||||
|
import us.myles.viaversion.libs.gson.JsonArray;
|
||||||
|
import us.myles.viaversion.libs.gson.JsonElement;
|
||||||
|
import us.myles.viaversion.libs.gson.JsonObject;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData.loadData;
|
||||||
|
|
||||||
|
public class SoundMapping {
|
||||||
|
private static short[] sounds = new short[662];
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
JsonObject mapping1_12 = loadData("mapping-1.12.json");
|
||||||
|
JsonObject mapping1_13 = loadData("mapping-1.13.json");
|
||||||
|
|
||||||
|
Arrays.fill(sounds, (short) -1);
|
||||||
|
mapIdentifiers(sounds, mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
|
||||||
|
for (int i = 0; i < oldIdentifiers.size(); i++) {
|
||||||
|
JsonElement v = oldIdentifiers.get(i);
|
||||||
|
Integer index = findIndex(newIdentifiers, v.getAsString());
|
||||||
|
if (index == null) continue; //There will be missing sounds, since we are goind backwards
|
||||||
|
output[i] = index.shortValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Integer findIndex(JsonArray array, String value) {
|
||||||
|
for (int i = 0; i < array.size(); i++) {
|
||||||
|
JsonElement v = array.get(i);
|
||||||
|
if (v.getAsString().equals(value)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getOldSound(int newSound) {
|
||||||
|
return newSound >= sounds.length ? -1 : sounds[newSound];
|
||||||
|
}
|
||||||
|
}
|
@ -1,25 +1,213 @@
|
|||||||
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
|
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
|
||||||
|
|
||||||
|
import nl.matsv.viabackwards.ViaBackwards;
|
||||||
|
import nl.matsv.viabackwards.api.entities.types.EntityType1_13;
|
||||||
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
|
||||||
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.EntityTypeMapping;
|
||||||
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.api.type.types.version.Types1_12;
|
||||||
|
import us.myles.ViaVersion.api.type.types.version.Types1_13;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
public class EntityPackets1_13 extends EntityRewriter<Protocol1_12_2To1_13> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerPackets(Protocol1_12_2To1_13 protocol) {
|
protected void registerPackets(Protocol1_12_2To1_13 protocol) {
|
||||||
|
|
||||||
|
//Spawn Object
|
||||||
|
protocol.out(State.PLAY, 0x00, 0x00, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.VAR_INT);
|
||||||
|
map(Type.UUID);
|
||||||
|
map(Type.BYTE);
|
||||||
|
map(Type.DOUBLE);
|
||||||
|
map(Type.DOUBLE);
|
||||||
|
map(Type.DOUBLE);
|
||||||
|
map(Type.BYTE);
|
||||||
|
map(Type.BYTE);
|
||||||
|
map(Type.INT);
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
byte type = wrapper.get(Type.BYTE, 0);
|
||||||
|
EntityType1_13.EntityType entityType = EntityType1_13.getTypeFromId(type, true);
|
||||||
|
if (entityType == null) {
|
||||||
|
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addTrackedEntity(
|
||||||
|
wrapper.user(),
|
||||||
|
wrapper.get(Type.VAR_INT, 0),
|
||||||
|
entityType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
Optional<EntityType1_13.ObjectType> type = EntityType1_13.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||||
|
if (type.isPresent() && type.get() == EntityType1_13.ObjectType.FALLING_BLOCK) {
|
||||||
|
int blockState = wrapper.get(Type.INT, 0);
|
||||||
|
int combined = BlockItemPackets1_13.toOldId(blockState);
|
||||||
|
combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12);
|
||||||
|
wrapper.set(Type.INT, 0, combined);
|
||||||
|
} else if (type.isPresent() && type.get() == EntityType1_13.ObjectType.ITEM_FRAME) {
|
||||||
|
int data = wrapper.get(Type.INT, 0);
|
||||||
|
switch (data) {
|
||||||
|
case 3:
|
||||||
|
data = 0;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
data = 1;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
data = 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wrapper.set(Type.INT, 0, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Spawn Experience Orb
|
||||||
|
protocol.out(State.PLAY, 0x01, 0x01, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.VAR_INT);
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
addTrackedEntity(
|
||||||
|
wrapper.user(),
|
||||||
|
wrapper.get(Type.VAR_INT, 0),
|
||||||
|
EntityType1_13.EntityType.XP_ORB
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Spawn Global Entity
|
||||||
|
protocol.registerOutgoing(State.PLAY, 0x02, 0x02, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.VAR_INT);
|
||||||
|
map(Type.BYTE);
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
addTrackedEntity(
|
||||||
|
wrapper.user(),
|
||||||
|
wrapper.get(Type.VAR_INT, 0),
|
||||||
|
EntityType1_13.EntityType.LIGHTNING_BOLT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Spawn Mob
|
||||||
|
protocol.out(State.PLAY, 0x03, 0x03, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.VAR_INT);
|
||||||
|
map(Type.UUID);
|
||||||
|
map(Type.VAR_INT);
|
||||||
|
map(Type.DOUBLE);
|
||||||
|
map(Type.DOUBLE);
|
||||||
|
map(Type.DOUBLE);
|
||||||
|
map(Type.BYTE);
|
||||||
|
map(Type.BYTE);
|
||||||
|
map(Type.BYTE);
|
||||||
|
map(Type.SHORT);
|
||||||
|
map(Type.SHORT);
|
||||||
|
map(Type.SHORT);
|
||||||
|
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST);
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
int type = wrapper.get(Type.VAR_INT, 1);
|
||||||
|
EntityType1_13.EntityType entityType = EntityType1_13.getTypeFromId(type, false);
|
||||||
|
addTrackedEntity(
|
||||||
|
wrapper.user(),
|
||||||
|
wrapper.get(Type.VAR_INT, 0),
|
||||||
|
entityType
|
||||||
|
);
|
||||||
|
Optional<Integer> oldId = EntityTypeMapping.getOldId(type);
|
||||||
|
if (!oldId.isPresent()) {
|
||||||
|
ViaBackwards.getPlatform().getLogger().warning("Could not find 1.12 entity type for 1.13 entity type " + type + "/" + entityType);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
wrapper.set(Type.VAR_INT, 1, oldId.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
wrapper.get(Types1_12.METADATA_LIST, 0).clear(); //TODO handle metadata
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Spawn Player
|
||||||
|
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.VAR_INT);
|
||||||
|
map(Type.UUID);
|
||||||
|
map(Type.DOUBLE);
|
||||||
|
map(Type.DOUBLE);
|
||||||
|
map(Type.DOUBLE);
|
||||||
|
map(Type.BYTE);
|
||||||
|
map(Type.BYTE);
|
||||||
|
map(Types1_13.METADATA_LIST, Types1_12.METADATA_LIST);
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
addTrackedEntity(
|
||||||
|
wrapper.user(),
|
||||||
|
wrapper.get(Type.VAR_INT, 0),
|
||||||
|
EntityType1_13.EntityType.PLAYER
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
wrapper.get(Types1_12.METADATA_LIST, 0).clear(); //TODO handle metadata
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Spawn Painting
|
//Spawn Painting
|
||||||
protocol.out(State.PLAY, 0x04, 0x04, new PacketRemapper() {
|
protocol.out(State.PLAY, 0x04, 0x04, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.VAR_INT);
|
map(Type.VAR_INT);
|
||||||
map(Type.UUID);
|
map(Type.UUID);
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
addTrackedEntity(
|
||||||
|
wrapper.user(),
|
||||||
|
wrapper.get(Type.VAR_INT, 0),
|
||||||
|
EntityType1_13.EntityType.PAINTING
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets;
|
||||||
|
|
||||||
|
import nl.matsv.viabackwards.api.rewriters.Rewriter;
|
||||||
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
|
||||||
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.NamedSoundMapping;
|
||||||
|
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.SoundMapping;
|
||||||
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.packets.State;
|
||||||
|
|
||||||
|
public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
|
||||||
|
@Override
|
||||||
|
protected void registerPackets(Protocol1_12_2To1_13 protocol) {
|
||||||
|
|
||||||
|
//Named Sound Event
|
||||||
|
protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.STRING);
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
String newSound = wrapper.get(Type.STRING, 0);
|
||||||
|
String oldSound = NamedSoundMapping.getOldId(newSound);
|
||||||
|
if (oldSound != null) {
|
||||||
|
wrapper.set(Type.STRING, 0, oldSound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Sound Effect
|
||||||
|
protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.VAR_INT);
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
int newSound = wrapper.get(Type.VAR_INT, 0);
|
||||||
|
int oldSound = SoundMapping.getOldSound(newSound);
|
||||||
|
if (oldSound == -1) {
|
||||||
|
wrapper.cancel();
|
||||||
|
} else {
|
||||||
|
wrapper.set(Type.VAR_INT, 0, oldSound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerRewrites() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren