From 6e57f871296c4c7cca260955b4e382514a363b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=B2=90=E5=91=80?= <163636894+zimuya4153@users.noreply.github.com> Date: Tue, 17 Dec 2024 22:13:46 +0800 Subject: [PATCH] feat: add interface related to entity type --- lib/GMLIB_API-JS.d.ts | 174 ++++++++++++++++++++ lib/GMLIB_API-JS.js | 335 +++++++++++++++++++++++++++++++-------- src/CompatibilityApi.cpp | 9 ++ 3 files changed, 448 insertions(+), 70 deletions(-) diff --git a/lib/GMLIB_API-JS.d.ts b/lib/GMLIB_API-JS.d.ts index 496cc60..edebf71 100644 --- a/lib/GMLIB_API-JS.d.ts +++ b/lib/GMLIB_API-JS.d.ts @@ -1347,6 +1347,165 @@ export class GMLIB_BinaryStream { ): GMLIB_BinaryStream; } +export enum ActorType { + Undefined = 1, + TypeMask = 0b11111111, + None = 0, + Mob = 1 << 8, + PathfinderMob = 1 << 9 | Mob, + UnknownType = 1 << 10, + Monster = 1 << 11 | PathfinderMob, + Animal = 1 << 12 | PathfinderMob, + WaterAnimal = 1 << 13 | PathfinderMob, + TamableAnimal = 1 << 14 | Animal, + Ambient = 1 << 15 | Mob, + UndeadMob = 1 << 16 | Monster, + ZombieMonster = 1 << 17 | UndeadMob, + Arthropod = 1 << 18 | Monster, + Minecart = 1 << 19, + SkeletonMonster = 1 << 20 | UndeadMob, + EquineAnimal = 1 << 21 | TamableAnimal, + Projectile = 1 << 22, + AbstractArrow = 1 << 23, + VillagerBase = 1 << 24 | PathfinderMob, + + Chicken = 10 | Animal, + Cow = 11 | Animal, + Pig = 12 | Animal, + Sheep = 13 | Animal, + Wolf = 14 | TamableAnimal, + Villager = 15 | VillagerBase, + MushroomCow = 16 | Animal, + Squid = 17 | WaterAnimal, + Rabbit = 18 | Animal, + Bat = 19 | Ambient, + IronGolem = 20 | PathfinderMob, + SnowGolem = 21 | PathfinderMob, + Ocelot = 22 | TamableAnimal, + Horse = 23 | EquineAnimal, + Donkey = 24 | EquineAnimal, + Mule = 25 | EquineAnimal, + SkeletonHorse = 26 | EquineAnimal | UndeadMob, + ZombieHorse = 27 | EquineAnimal | UndeadMob, + PolarBear = 28 | Animal, + Llama = 29 | Animal, + Parrot = 30 | TamableAnimal, + Dolphin = 31 | WaterAnimal, + Zombie = 32 | ZombieMonster, + Creeper = 33 | Monster, + Skeleton = 34 | SkeletonMonster, + Spider = 35 | Arthropod, + PigZombie = 36 | UndeadMob, + Slime = 37 | Monster, + EnderMan = 38 | Monster, + Silverfish = 39 | Arthropod, + CaveSpider = 40 | Arthropod, + Ghast = 41 | Monster, + LavaSlime = 42 | Monster, + Blaze = 43 | Monster, + ZombieVillager = 44 | ZombieMonster, + Witch = 45 | Monster, + Stray = 46 | SkeletonMonster, + Husk = 47 | ZombieMonster, + WitherSkeleton = 48 | SkeletonMonster, + Guardian = 49 | Monster, + ElderGuardian = 50 | Monster, + Npc = 51 | Mob, + WitherBoss = 52 | UndeadMob, + Dragon = 53 | Monster, + Shulker = 54 | Monster, + Endermite = 55 | Arthropod, + Agent = 56 | Mob, + Vindicator = 57 | Monster, + Phantom = 58 | UndeadMob, + IllagerBeast = 59 | Monster, + UNUSED60 = 60, + ArmorStand = 61 | Mob, + TripodCamera = 62 | Mob, + Player = 63 | Mob, + ItemEntity = 64 | None, + PrimedTnt = 65 | None, + FallingBlock = 66 | None, + MovingBlock = 67 | None, + ExperiencePotion = 68 | Projectile, + Experience = 69 | None, + EyeOfEnder = 70 | None, + EnderCrystal = 71 | None, + FireworksRocket = 72 | None, + Trident = 73 | Projectile | AbstractArrow, + Turtle = 74 | Animal, + Cat = 75 | TamableAnimal, + ShulkerBullet = 76 | Projectile, + FishingHook = 77 | None, + Chalkboard = 78 | None, + DragonFireball = 79 | Projectile, + Arrow = 80 | Projectile | AbstractArrow, + Snowball = 81 | Projectile, + ThrownEgg = 82 | Projectile, + Painting = 83 | None, + MinecartRideable = 84 | Minecart, + LargeFireball = 85 | Projectile, + ThrownPotion = 86 | Projectile, + Enderpearl = 87 | Projectile, + LeashKnot = 88 | None, + WitherSkull = 89 | Projectile, + BoatRideable = 90 | None, + WitherSkullDangerous = 91 | Projectile, + UNUSED92 = 92, + LightningBolt = 93 | None, + SmallFireball = 94 | Projectile, + AreaEffectCloud = 95 | None, + MinecartHopper = 96 | Minecart, + MinecartTNT = 97 | Minecart, + MinecartChest = 98 | Minecart, + MinecartFurnace = 99 | Minecart, + MinecartCommandBlock = 100 | Minecart, + LingeringPotion = 101 | Projectile, + LlamaSpit = 102 | Projectile, + EvocationFang = 103 | Projectile, + EvocationIllager = 104 | Monster, + Vex = 105 | Monster, + IceBomb = 106 | Projectile, + Balloon = 107 | None, + Pufferfish = 108 | WaterAnimal, + Salmon = 109 | WaterAnimal, + Drowned = 110 | ZombieMonster, + Tropicalfish = 111 | WaterAnimal, + Fish = 112 | WaterAnimal, + Panda = 113 | Animal, + Pillager = 114 | Monster, + VillagerV2 = 115 | VillagerBase, + ZombieVillagerV2 = 116 | ZombieMonster, + Shield = 117 | None, + WanderingTrader = 118 | PathfinderMob, + Lectern = 119 | None, + ElderGuardianGhost = 120 | Monster, + Fox = 121 | Animal, + Bee = 122 | Mob, + Piglin = 123 | Mob, + Hoglin = 124 | Animal, + Strider = 125 | Animal, + Zoglin = 126 | UndeadMob, + PiglinBrute = 127 | Mob, + Goat = 128 | Animal, + GlowSquid = 129 | WaterAnimal, + Axolotl = 130 | Animal, + Warden = 131 | Monster, + Frog = 132 | Animal, + Tadpole = 133 | WaterAnimal, + Allay = 134 | Mob, + ChestBoatRideable = 136 | BoatRideable, + TraderLlama = 137 | Llama, + Camel = 138 | Animal, + Sniffer = 139 | Animal, + Breeze = 140 | Monster, + BreezeWindChargeProjectile = 141 | Projectile, + Armadillo = 142 | Animal, + WindChargeProjectile = 143 | Projectile, + Bogged = 144 | SkeletonMonster, + OminousItemSpawner = 145 +} + interface Player { /** (GMLIB)转换成实体对象 */ toEntity(): Entity; @@ -1519,6 +1678,21 @@ interface Entity { /** 是否显示粒子效果 */ ShowParticles: boolean }[]; + + /** 实体是否为某类型 */ + isType( + /** 实体类型 */ + type: ActorType + ): boolean; + + /** 实体是否包含某类型 */ + hasType( + /** 实体类型 */ + type: ActorType + ): boolean; + + /** 获取实体类型ID */ + getEntityTypeId(): ActorType; } interface Block { diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index e999d67..f056f04 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -374,6 +374,12 @@ const GMLIB_API = { getDefaultGameMode: ll.import("GMLIB_API", "getDefaultGameMode"), /** 设置默认游戏模式 @type {function(mode):void} */ setDefaultGameMode: ll.import("GMLIB_API", "setDefaultGameMode"), + /** 实体是否为某类型 @type {function(Entity, number):boolean} */ + entityIsType: ll.import("GMLIB_API", "entityIsType"), + /** 实体是包含某类型 @type {function(Entity, number):boolean} */ + entityHasType: ll.import("GMLIB_API", "entityHasType"), + /** 获取实体类型ID @type {function(Entity):number} */ + getEntityTypeId: ll.import("GMLIB_API", "getEntityTypeId"), }; /** LRCA的二进制流数据包导出接口 */ @@ -1055,7 +1061,7 @@ class Minecraft { * @returns {number} 方块的亮度(-1为不存在) */ static getBlockLightEmission(block, legacyData = 0) { - return GMLIB_API.getBlockLightEmission(block, legacyData) + return GMLIB_API.getBlockLightEmission(block, legacyData); } /** @@ -2122,7 +2128,7 @@ class GMLIB_BinaryStream { * @returns {GMLIB_BinaryStream} */ constructor(value) { - this.#id = value instanceof GMLIB_BinaryStream ? GMLIB_BinaryStream_API.copy(value.getId()) : GMLIB_BinaryStream_API.create(); + this.#id = value instanceof GMLIB_BinaryStream ? GMLIB_BinaryStream_API.copy(value.getId()) : GMLIB_BinaryStream_API.create(); if (Array.isArray(value)) this.write(value); } @@ -2218,8 +2224,8 @@ class GMLIB_BinaryStream { * 转换成字符串 * @returns {string} 字符串 */ - toString(){ - return `` + toString() { + return ``; } /** @@ -2529,7 +2535,7 @@ class GMLIB_BinaryStream { GMLIB_BinaryStream_API.writeVarInt64(this.#id, value); return this; } -} +} LLSE_Player.prototype.toEntity = /** @@ -2538,7 +2544,7 @@ LLSE_Player.prototype.toEntity = */ function () { return GMLIB_API.PlayerToEntity(this); - } + }; LLSE_Player.prototype.getSpawnPoint = /** @@ -2547,7 +2553,7 @@ LLSE_Player.prototype.getSpawnPoint = */ function () { return GMLIB_API.getPlayerSpawnPoint(this); - } + }; LLSE_Player.prototype.setSpawnPoint = /** @@ -2556,7 +2562,7 @@ LLSE_Player.prototype.setSpawnPoint = */ function (pos) { GMLIB_API.setPlayerSpawnPoint(this, pos); - } + }; LLSE_Player.prototype.clearSpawnPoint = /** @@ -2564,7 +2570,7 @@ LLSE_Player.prototype.clearSpawnPoint = */ function () { GMLIB_API.clearPlayerSpawnPoint(this); - } + }; LLSE_Entity.prototype.shootProjectile = /** @@ -2576,7 +2582,7 @@ LLSE_Entity.prototype.shootProjectile = */ function (proj, speed = 2, offset = 3) { return GMLIB_API.shootProjectile(this, proj, speed, offset); - } + }; LLSE_Entity.prototype.throwEntity = /** @@ -2588,7 +2594,7 @@ LLSE_Entity.prototype.throwEntity = */ function (proj, speed = 2, offset = 3) { return GMLIB_API.throwEntity(this, proj, speed, offset); - } + }; LLSE_Entity.prototype.getTranslateKey = /** @@ -2597,7 +2603,7 @@ LLSE_Entity.prototype.getTranslateKey = */ function () { return GMLIB_API.getEntityTranslateKey(this); - } + }; LLSE_Entity.prototype.getTranslateName = /** @@ -2607,7 +2613,7 @@ LLSE_Entity.prototype.getTranslateName = */ function (language) { return I18nAPI.get(this.getTranslateKey(), [], language); - } + }; LLSE_Block.prototype.getTranslateKey = /** @@ -2616,7 +2622,7 @@ LLSE_Block.prototype.getTranslateKey = */ function () { return GMLIB_API.getBlockTranslateKey(this); - } + }; LLSE_Block.prototype.getTranslateName = /** @@ -2626,7 +2632,7 @@ LLSE_Block.prototype.getTranslateName = */ function (language) { return I18nAPI.get(this.getTranslateKey(), [], language); - } + }; LLSE_Item.prototype.getTranslateKey = /** @@ -2635,7 +2641,7 @@ LLSE_Item.prototype.getTranslateKey = */ function () { return GMLIB_API.getItemTranslateKey(this); - } + }; LLSE_Item.prototype.getTranslateName = /** @@ -2645,7 +2651,7 @@ LLSE_Item.prototype.getTranslateName = */ function (language) { return I18nAPI.get(this.getTranslateKey(), [], language); - } + }; LLSE_Block.prototype.getBlockDestroySpeed = /** @@ -2654,7 +2660,7 @@ LLSE_Block.prototype.getBlockDestroySpeed = */ function () { return GMLIB_API.getBlockDestroySpeed(this); - } + }; LLSE_Item.prototype.getDestroyBlockSpeed = /** @@ -2664,7 +2670,7 @@ LLSE_Item.prototype.getDestroyBlockSpeed = */ function (block) { return GMLIB_API.getDestroyBlockSpeed(this, block); - } + }; LLSE_Block.prototype.playerDestroy = /** @@ -2673,7 +2679,7 @@ LLSE_Block.prototype.playerDestroy = */ function (player) { GMLIB_API.playerDestroyBlock(this, this.pos, player); - } + }; LLSE_Item.prototype.canDestroy = /** @@ -2683,7 +2689,7 @@ LLSE_Item.prototype.canDestroy = */ function (block) { return GMLIB_API.itemCanDestroyBlock(this, block); - } + }; LLSE_Item.prototype.canDestroyInCreative = /** @@ -2692,7 +2698,7 @@ LLSE_Item.prototype.canDestroyInCreative = */ function () { return GMLIB_API.itemCanDestroyInCreative(this); - } + }; LLSE_Item.prototype.canDestroySpecial = /** @@ -2702,7 +2708,7 @@ LLSE_Item.prototype.canDestroySpecial = */ function (block) { return GMLIB_API.itemCanDestroySpecial(this, block); - } + }; LLSE_Block.prototype.canDropWithAnyTool = /** @@ -2711,7 +2717,7 @@ LLSE_Block.prototype.canDropWithAnyTool = */ function () { return GMLIB_API.blockCanDropWithAnyTool(this); - } + }; LLSE_Block.prototype.isAlwaysDestroyable = /** @@ -2720,7 +2726,7 @@ LLSE_Block.prototype.isAlwaysDestroyable = */ function () { return GMLIB_API.blockIsAlwaysDestroyable(this); - } + }; LLSE_Block.prototype.playerWillDestroy = /** @@ -2730,7 +2736,7 @@ LLSE_Block.prototype.playerWillDestroy = */ function (player) { return GMLIB_API.blockPlayerWillDestroy(this, player, this.pos); - } + }; LLSE_Player.prototype.attack = /** @@ -2740,7 +2746,7 @@ LLSE_Player.prototype.attack = */ function (entity) { return GMLIB_API.playerAttack(this, entity); - } + }; LLSE_Player.prototype.pullInEntity = /** @@ -2750,7 +2756,7 @@ LLSE_Player.prototype.pullInEntity = */ function (entity) { return GMLIB_API.playerPullInEntity(this, entity); - } + }; LLSE_Item.prototype.getLegalEnchants = /** @@ -2759,7 +2765,7 @@ LLSE_Item.prototype.getLegalEnchants = */ function () { return GMLIB_API.getLegalEnchants(this); - } + }; LLSE_Item.prototype.applyEnchant = /** @@ -2771,7 +2777,7 @@ LLSE_Item.prototype.applyEnchant = */ function (typeName, level, allowNonVanilla = true) { return GMLIB_API.applyEnchant(this, typeName, level, allowNonVanilla); - } + }; LLSE_Item.prototype.removeEnchants = /** @@ -2779,7 +2785,7 @@ LLSE_Item.prototype.removeEnchants = */ function () { GMLIB_API.removeEnchants(this); - } + }; LLSE_Item.prototype.hasEnchant = /** @@ -2789,7 +2795,7 @@ LLSE_Item.prototype.hasEnchant = */ function (typeName) { return GMLIB_API.hasEnchant(this, typeName); - } + }; LLSE_Item.prototype.getEnchantLevel = /** @@ -2799,7 +2805,7 @@ LLSE_Item.prototype.getEnchantLevel = */ function (typeName) { return GMLIB_API.getEnchantLevel(this, typeName); - } + }; LLSE_Player.prototype.dropItem = /** @@ -2810,7 +2816,7 @@ LLSE_Player.prototype.dropItem = */ function (item, randomly = false) { return GMLIB_API.dropPlayerItem(this, item, randomly); - } + }; LLSE_Player.prototype.getRuntimeId = /** @@ -2819,7 +2825,7 @@ LLSE_Player.prototype.getRuntimeId = */ function () { return GMLIB_API.getPlayerRuntimeId(this); - } + }; LLSE_Entity.prototype.getRuntimeId = /** @@ -2828,7 +2834,7 @@ LLSE_Entity.prototype.getRuntimeId = */ function () { return GMLIB_API.getEntityRuntimeId(this); - } + }; LLSE_Entity.prototype.getNameTag = /** @@ -2837,7 +2843,7 @@ LLSE_Entity.prototype.getNameTag = */ function () { return GMLIB_API.getEntityNameTag(this); - } + }; LLSE_Item.prototype.isUnbreakable = /** @@ -2846,7 +2852,7 @@ LLSE_Item.prototype.isUnbreakable = */ function () { return GMLIB_API.ItemisUnbreakable(this); - } + }; LLSE_Item.prototype.setUnbreakable = /** @@ -2855,7 +2861,7 @@ LLSE_Item.prototype.setUnbreakable = */ function (value) { GMLIB_API.setItemUnbreakable(this, value); - } + }; LLSE_Item.prototype.getShouldKeepOnDeath = /** @@ -2864,7 +2870,7 @@ LLSE_Item.prototype.getShouldKeepOnDeath = */ function () { return GMLIB_API.getItemShouldKeepOnDeath(this); - } + }; LLSE_Item.prototype.setShouldKeepOnDeath = /** @@ -2873,7 +2879,7 @@ LLSE_Item.prototype.setShouldKeepOnDeath = */ function (value) { GMLIB_API.setItemShouldKeepOnDeath(this, value); - } + }; LLSE_Item.prototype.getItemLockMode = /** @@ -2881,8 +2887,8 @@ LLSE_Item.prototype.getItemLockMode = * @returns {0|1|2} 锁定的模式 0:无 1:锁定在格子里 2:锁定在背包里 */ function () { - return GMLIB_API.getItemLockMode(this) - } + return GMLIB_API.getItemLockMode(this); + }; LLSE_Item.prototype.setItemLockMode = /** @@ -2891,7 +2897,7 @@ LLSE_Item.prototype.setItemLockMode = */ function (mode) { GMLIB_API.setItemLockMode(this, mode); - } + }; LLSE_Item.prototype.getRepairCost = /** @@ -2900,7 +2906,7 @@ LLSE_Item.prototype.getRepairCost = */ function () { return GMLIB_API.getItemRepairCost(this); - } + }; LLSE_Item.prototype.setRepairCost = /** @@ -2909,7 +2915,7 @@ LLSE_Item.prototype.setRepairCost = */ function (cost) { return GMLIB_API.setItemRepairCost(this, cost); - } + }; LLSE_Item.prototype.getCanDestroy = /** @@ -2918,7 +2924,7 @@ LLSE_Item.prototype.getCanDestroy = */ function () { return GMLIB_API.getItemCanDestroy(this); - } + }; LLSE_Item.prototype.setCanDestroy = /** @@ -2927,7 +2933,7 @@ LLSE_Item.prototype.setCanDestroy = */ function (blocks) { GMLIB_API.setItemCanDestroy(this, blocks); - } + }; LLSE_Item.prototype.getCanPlaceOn = /** @@ -2936,7 +2942,7 @@ LLSE_Item.prototype.getCanPlaceOn = */ function () { return GMLIB_API.getItemCanPlaceOn(this); - } + }; LLSE_Item.prototype.setCanPlaceOn = /** @@ -2945,7 +2951,7 @@ LLSE_Item.prototype.setCanPlaceOn = */ function (blocks) { GMLIB_API.setItemCanPlaceOn(this, blocks); - } + }; LLSE_Player.prototype.getHungry = /** @@ -2954,7 +2960,7 @@ LLSE_Player.prototype.getHungry = */ function () { return GMLIB_API.getPlayerHungry(this); - } + }; LLSE_Player.prototype.getArmorCoverPercentage = /** @@ -2963,7 +2969,7 @@ LLSE_Player.prototype.getArmorCoverPercentage = */ function () { return GMLIB_API.getPlayerArmorCoverPercentage(this); - } + }; LLSE_Player.prototype.getArmorValue = /** @@ -2972,7 +2978,7 @@ LLSE_Player.prototype.getArmorValue = */ function () { return GMLIB_API.getPlayerArmorValue(this); - } + }; LLSE_Entity.prototype.getEntityOwner = /** @@ -2982,7 +2988,7 @@ LLSE_Entity.prototype.getEntityOwner = function () { const uniqueId = GMLIB_API.getEntityOwnerUniqueId(this); return uniqueId === -1 ? null : Minecraft.getEntityFromUniqueId(uniqueId); - } + }; LLSE_Item.prototype.getCategoryName = /** @@ -2991,7 +2997,7 @@ LLSE_Item.prototype.getCategoryName = */ function () { return GMLIB_API.getItemCategoryName(this); - } + }; LLSE_Item.prototype.getCustomName = /** @@ -3000,7 +3006,7 @@ LLSE_Item.prototype.getCustomName = */ function () { return GMLIB_API.getItemCustomName(this); - } + }; LLSE_Item.prototype.getEffecName = /** @@ -3009,7 +3015,7 @@ LLSE_Item.prototype.getEffecName = */ function () { return GMLIB_API.getItemEffecName(this); - } + }; LLSE_Item.prototype.isFood = /** @@ -3018,7 +3024,7 @@ LLSE_Item.prototype.isFood = */ function () { return GMLIB_API.itemIsFood(this); - } + }; LLSE_Player.prototype.setPlayerUIItem = /** @@ -3028,7 +3034,7 @@ LLSE_Player.prototype.setPlayerUIItem = */ function (slot, item) { GMLIB_API.setPlayerUIItem(this, slot, item); - } + }; LLSE_Player.prototype.getPlayerUIItem = /** @@ -3038,7 +3044,7 @@ LLSE_Player.prototype.getPlayerUIItem = */ function (slot) { return GMLIB_API.getPlayerUIItem(this, slot); - } + }; LLSE_Player.prototype.sendInventorySlotPacket = /** @@ -3049,7 +3055,7 @@ LLSE_Player.prototype.sendInventorySlotPacket = */ function (containerId, slot, item) { GMLIB_API.sendInventorySlotPacket(this, containerId, slot, item); - } + }; LLSE_Container.prototype.getContainerType = /** @@ -3058,7 +3064,7 @@ LLSE_Container.prototype.getContainerType = */ function () { return GMLIB_API.getContainerType(this); - } + }; LLSE_Item.prototype.getMaxCount = /** @@ -3067,7 +3073,7 @@ LLSE_Item.prototype.getMaxCount = */ function () { return GMLIB_API.getItemMaxCount(this); - } + }; LLSE_Entity.prototype.hasFamily = /** @@ -3077,7 +3083,7 @@ LLSE_Entity.prototype.hasFamily = */ function (family) { return GMLIB_API.entityHasFamily(this, family); - } + }; LLSE_Player.prototype.getDestroyProgress = /** @@ -3087,7 +3093,7 @@ LLSE_Player.prototype.getDestroyProgress = */ function (block) { return GMLIB_API.getPlayerDestroyBlockProgress(this, block); - } + }; LLSE_Entity.prototype.hasEffect = /** @@ -3097,7 +3103,7 @@ LLSE_Entity.prototype.hasEffect = */ function (effectId) { return GMLIB_API.entityHasEffect(this, effectId); - } + }; LLSE_Entity.prototype.getEffectInfo = /** @@ -3116,8 +3122,8 @@ LLSE_Entity.prototype.getEffectInfo = DurationHard: GMLIB_API.getEntityEffectDurationHard(this, effectId), Ambient: GMLIB_API.getEntityEffectAmbient(this, effectId), ShowParticles: GMLIB_API.getEntityEffectVisible(this, effectId), - } - } + }; + }; LLSE_Entity.prototype.getAllEffectsInfo = /** @@ -3126,7 +3132,195 @@ LLSE_Entity.prototype.getAllEffectsInfo = */ function () { return this.getAllEffects().map(effectId => this.getEffectInfo(effectId)); - } + }; + +LLSE_Entity.prototype.isType = + /** + * 是否为某类型 + * @param {number} type 类型 + * @returns {boolean} + */ + function (type) { + return GMLIB_API.entityIsType(this, type); + }; + +LLSE_Entity.prototype.hasType = + /** + * 是否包含某类型 + * @param {number} type 类型 + * @returns {boolean} + */ + function (type) { + return GMLIB_API.entityHasType(this, type); + }; + +LLSE_Entity.prototype.getEntityTypeId = + /** + * 获取实体类型ID + * @returns {number} + */ + function () { + return GMLIB_API.getEntityTypeId(this); + }; + +const ActorType = Object.freeze({ + Undefined: 1, + TypeMask: 0b11111111, + None: 0, + Mob: 1 << 8, + PathfinderMob: 1 << 9 | this.Mob, + UnknownType: 1 << 10, + Monster: 1 << 11 | this.PathfinderMob, + Animal: 1 << 12 | this.PathfinderMob, + WaterAnimal: 1 << 13 | this.PathfinderMob, + TamableAnimal: 1 << 14 | this.Animal, + Ambient: 1 << 15 | this.Mob, + UndeadMob: 1 << 16 | this.Monster, + ZombieMonster: 1 << 17 | this.UndeadMob, + Arthropod: 1 << 18 | this.Monster, + Minecart: 1 << 19, + SkeletonMonster: 1 << 20 | this.UndeadMob, + EquineAnimal: 1 << 21 | this.TamableAnimal, + Projectile: 1 << 22, + AbstractArrow: 1 << 23, + VillagerBase: 1 << 24 | this.PathfinderMob, + + Chicken: 10 | this.Animal, + Cow: 11 | this.Animal, + Pig: 12 | this.Animal, + Sheep: 13 | this.Animal, + Wolf: 14 | this.TamableAnimal, + Villager: 15 | this.VillagerBase, + MushroomCow: 16 | this.Animal, + Squid: 17 | this.WaterAnimal, + Rabbit: 18 | this.Animal, + Bat: 19 | this.Ambient, + IronGolem: 20 | this.PathfinderMob, + SnowGolem: 21 | this.PathfinderMob, + Ocelot: 22 | this.TamableAnimal, + Horse: 23 | this.EquineAnimal, + Donkey: 24 | this.EquineAnimal, + Mule: 25 | this.EquineAnimal, + SkeletonHorse: 26 | this.EquineAnimal | this.UndeadMob, + ZombieHorse: 27 | this.EquineAnimal | this.UndeadMob, + PolarBear: 28 | this.Animal, + Llama: 29 | this.Animal, + Parrot: 30 | this.TamableAnimal, + Dolphin: 31 | this.WaterAnimal, + Zombie: 32 | this.ZombieMonster, + Creeper: 33 | this.Monster, + Skeleton: 34 | this.SkeletonMonster, + Spider: 35 | this.Arthropod, + PigZombie: 36 | this.UndeadMob, + Slime: 37 | this.Monster, + EnderMan: 38 | this.Monster, + Silverfish: 39 | this.Arthropod, + CaveSpider: 40 | this.Arthropod, + Ghast: 41 | this.Monster, + LavaSlime: 42 | this.Monster, + Blaze: 43 | this.Monster, + ZombieVillager: 44 | this.ZombieMonster, + Witch: 45 | this.Monster, + Stray: 46 | this.SkeletonMonster, + Husk: 47 | this.ZombieMonster, + WitherSkeleton: 48 | this.SkeletonMonster, + Guardian: 49 | this.Monster, + ElderGuardian: 50 | this.Monster, + Npc: 51 | this.Mob, + WitherBoss: 52 | this.UndeadMob, + Dragon: 53 | this.Monster, + Shulker: 54 | this.Monster, + Endermite: 55 | this.Arthropod, + Agent: 56 | this.Mob, + Vindicator: 57 | this.Monster, + Phantom: 58 | this.UndeadMob, + IllagerBeast: 59 | this.Monster, + UNUSED60: 60, + ArmorStand: 61 | this.Mob, + TripodCamera: 62 | this.Mob, + Player: 63 | this.Mob, + ItemEntity: 64 | this.None, + PrimedTnt: 65 | this.None, + FallingBlock: 66 | this.None, + MovingBlock: 67 | this.None, + ExperiencePotion: 68 | this.Projectile, + Experience: 69 | this.None, + EyeOfEnder: 70 | this.None, + EnderCrystal: 71 | this.None, + FireworksRocket: 72 | this.None, + Trident: 73 | this.Projectile | this.AbstractArrow, + Turtle: 74 | this.Animal, + Cat: 75 | this.TamableAnimal, + ShulkerBullet: 76 | this.Projectile, + FishingHook: 77 | this.None, + Chalkboard: 78 | this.None, + DragonFireball: 79 | this.Projectile, + Arrow: 80 | this.Projectile | this.AbstractArrow, + Snowball: 81 | this.Projectile, + ThrownEgg: 82 | this.Projectile, + Painting: 83 | this.None, + MinecartRideable: 84 | this.Minecart, + LargeFireball: 85 | this.Projectile, + ThrownPotion: 86 | this.Projectile, + Enderpearl: 87 | this.Projectile, + LeashKnot: 88 | this.None, + WitherSkull: 89 | this.Projectile, + BoatRideable: 90 | this.None, + WitherSkullDangerous: 91 | this.Projectile, + UNUSED92: 92, + LightningBolt: 93 | this.None, + SmallFireball: 94 | this.Projectile, + AreaEffectCloud: 95 | this.None, + MinecartHopper: 96 | this.Minecart, + MinecartTNT: 97 | this.Minecart, + MinecartChest: 98 | this.Minecart, + MinecartFurnace: 99 | this.Minecart, + MinecartCommandBlock: 100 | this.Minecart, + LingeringPotion: 101 | this.Projectile, + LlamaSpit: 102 | this.Projectile, + EvocationFang: 103 | this.Projectile, + EvocationIllager: 104 | this.Monster, + Vex: 105 | this.Monster, + IceBomb: 106 | this.Projectile, + Balloon: 107 | this.None, + Pufferfish: 108 | this.WaterAnimal, + Salmon: 109 | this.WaterAnimal, + Drowned: 110 | this.ZombieMonster, + Tropicalfish: 111 | this.WaterAnimal, + Fish: 112 | this.WaterAnimal, + Panda: 113 | this.Animal, + Pillager: 114 | this.Monster, + VillagerV2: 115 | this.VillagerBase, + ZombieVillagerV2: 116 | this.ZombieMonster, + Shield: 117 | this.None, + WanderingTrader: 118 | this.PathfinderMob, + Lectern: 119 | this.None, + ElderGuardianGhost: 120 | this.Monster, + Fox: 121 | this.Animal, + Bee: 122 | this.Mob, + Piglin: 123 | this.Mob, + Hoglin: 124 | this.Animal, + Strider: 125 | this.Animal, + Zoglin: 126 | this.UndeadMob, + PiglinBrute: 127 | this.Mob, + Goat: 128 | this.Animal, + GlowSquid: 129 | this.WaterAnimal, + Axolotl: 130 | this.Animal, + Warden: 131 | this.Monster, + Frog: 132 | this.Animal, + Tadpole: 133 | this.WaterAnimal, + Allay: 134 | this.Mob, + ChestBoatRideable: 136 | this.BoatRideable, + TraderLlama: 137 | this.Llama, + Camel: 138 | this.Animal, + Sniffer: 139 | this.Animal, + Breeze: 140 | this.Monster, + BreezeWindChargeProjectile: 141 | this.Projectile, + Armadillo: 142 | this.Animal, + WindChargeProjectile: 143 | this.Projectile, + Bogged: 144 | this.SkeletonMonster, + OminousItemSpawner: 145, +}); module.exports = { StaticFloatingText, @@ -3141,5 +3335,6 @@ module.exports = { Version, I18nAPI, UserCache, - GMLIB_BinaryStream + GMLIB_BinaryStream, + ActorType }; \ No newline at end of file diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 68e997a..914d14f 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -878,4 +878,13 @@ void Export_Compatibility_API() { GMLIB::Mod::CustomRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, *result); } ); + RemoteCall::exportAs("GMLIB_API", "entityIsType", [](Actor* entity, int type) -> bool { + return entity->isType((ActorType)type); + }); + RemoteCall::exportAs("GMLIB_API", "entityHasType", [](Actor* entity, int type) -> bool { + return entity->hasType((ActorType)type); + }); + RemoteCall::exportAs("GMLIB_API", "getEntityTypeId", [](Actor* entity) -> int { + return (int)entity->getEntityTypeId(); + }); } \ No newline at end of file