Skip to content

Commit

Permalink
Fix entity data handling.
Browse files Browse the repository at this point in the history
Co-authored-by: oragejuice <lnadav941@gmail.com>
  • Loading branch information
basaigh and oragejuice committed Apr 29, 2024
1 parent 7cd0541 commit 53f1441
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.geysermc.mcprotocollib.protocol.data.game.entity.type;

import lombok.Getter;

public enum EntityType {
ALLAY,
AREA_EFFECT_CLOUD,
ARMADILLO,
ARMOR_STAND,
ARROW,
ARROW(true),
AXOLOTL,
BAT,
BEE,
Expand All @@ -14,7 +16,7 @@ public enum EntityType {
BOAT,
BOGGED,
BREEZE,
BREEZE_WIND_CHARGE,
BREEZE_WIND_CHARGE(true),
CAMEL,
CAT,
CAVE_SPIDER,
Expand All @@ -27,22 +29,22 @@ public enum EntityType {
CREEPER,
DOLPHIN,
DONKEY,
DRAGON_FIREBALL,
DRAGON_FIREBALL(true),
DROWNED,
EGG,
EGG(true),
ELDER_GUARDIAN,
END_CRYSTAL,
ENDER_DRAGON,
ENDER_PEARL,
ENDER_PEARL(true),
ENDERMAN,
ENDERMITE,
EVOKER,
EVOKER_FANGS,
EXPERIENCE_BOTTLE,
EXPERIENCE_BOTTLE(true),
EXPERIENCE_ORB,
EYE_OF_ENDER,
FALLING_BLOCK,
FIREWORK_ROCKET,
FIREWORK_ROCKET(true),
FOX,
FROG,
FURNACE_MINECART,
Expand All @@ -63,11 +65,11 @@ public enum EntityType {
ITEM_DISPLAY,
ITEM_FRAME,
OMINOUS_ITEM_SPAWNER,
FIREBALL,
FIREBALL(true),
LEASH_KNOT,
LIGHTNING_BOLT,
LLAMA,
LLAMA_SPIT,
LLAMA_SPIT(true),
MAGMA_CUBE,
MARKER,
MINECART,
Expand All @@ -83,24 +85,24 @@ public enum EntityType {
PIGLIN_BRUTE,
PILLAGER,
POLAR_BEAR,
POTION,
POTION(true),
PUFFERFISH,
RABBIT,
RAVAGER,
SALMON,
SHEEP,
SHULKER,
SHULKER_BULLET,
SHULKER_BULLET(true),
SILVERFISH,
SKELETON,
SKELETON_HORSE,
SLIME,
SMALL_FIREBALL,
SMALL_FIREBALL(true),
SNIFFER,
SNOW_GOLEM,
SNOWBALL,
SNOWBALL(true),
SPAWNER_MINECART,
SPECTRAL_ARROW,
SPECTRAL_ARROW(true),
SPIDER,
SQUID,
STRAY,
Expand All @@ -110,27 +112,38 @@ public enum EntityType {
TNT,
TNT_MINECART,
TRADER_LLAMA,
TRIDENT,
TRIDENT(true),
TROPICAL_FISH,
TURTLE,
VEX,
VILLAGER,
VINDICATOR,
WANDERING_TRADER,
WARDEN,
WIND_CHARGE,
WIND_CHARGE(true),
WITCH,
WITHER,
WITHER_SKELETON,
WITHER_SKULL,
WITHER_SKULL(true),
WOLF,
ZOGLIN,
ZOMBIE,
ZOMBIE_HORSE,
ZOMBIE_VILLAGER,
ZOMBIFIED_PIGLIN,
PLAYER,
FISHING_BOBBER;
FISHING_BOBBER(true);

@Getter
private final boolean projectile;

EntityType() {
this.projectile = false;
}

EntityType(boolean projectile) {
this.projectile = projectile;
}

private static final EntityType[] VALUES = values();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.MinecartType;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.ObjectData;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.ProjectileData;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.SplashPotionData;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.WardenData;
import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType;

Expand Down Expand Up @@ -73,11 +72,7 @@ public ClientboundAddEntityPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.data = Direction.VALUES[data];
} else if (this.type == EntityType.FALLING_BLOCK) {
this.data = new FallingBlockData(data & 65535, data >> 16);
} else if (this.type == EntityType.POTION) {
this.data = new SplashPotionData(data);
} else if (this.type == EntityType.SPECTRAL_ARROW || this.type == EntityType.FIREBALL || this.type == EntityType.SMALL_FIREBALL
|| this.type == EntityType.DRAGON_FIREBALL || this.type == EntityType.WITHER_SKULL || this.type == EntityType.FISHING_BOBBER
|| this.type == EntityType.BREEZE_WIND_CHARGE) {
} else if (this.type.isProjectile()) {
this.data = new ProjectileData(data);
} else if (this.type == EntityType.WARDEN) {
this.data = new WardenData(data);
Expand Down Expand Up @@ -113,8 +108,6 @@ public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
data = ((Direction) this.data).ordinal();
} else if (this.data instanceof FallingBlockData) {
data = ((FallingBlockData) this.data).getId() | ((FallingBlockData) this.data).getMetadata() << 16;
} else if (this.data instanceof SplashPotionData) {
data = ((SplashPotionData) this.data).getPotionData();
} else if (this.data instanceof ProjectileData) {
data = ((ProjectileData) this.data).getOwnerId();
} else if (this.data instanceof GenericObjectData) {
Expand Down

0 comments on commit 53f1441

Please sign in to comment.