Add world.spawnItem And entity.getSelectedItem (Closes #124)
All checks were successful
CI / Build (AMD64) (push) Successful in 22m35s
CI / Build (ARM64) (push) Successful in 24m8s
CI / Build (ARMHF) (push) Successful in 13m17s
CI / Test (AMD64, Server) (push) Successful in 3m32s
CI / Build Example Mods (push) Successful in 1m44s
CI / Test (AMD64, Client) (push) Successful in 7m29s
CI / Test (ARM64, Client) (push) Successful in 7m32s
CI / Test (ARM64, Server) (push) Successful in 4m24s
CI / Test (ARMHF, Client) (push) Successful in 7m49s
CI / Test (ARMHF, Server) (push) Successful in 4m49s
CI / Release (push) Has been skipped
All checks were successful
CI / Build (AMD64) (push) Successful in 22m35s
CI / Build (ARM64) (push) Successful in 24m8s
CI / Build (ARMHF) (push) Successful in 13m17s
CI / Test (AMD64, Server) (push) Successful in 3m32s
CI / Build Example Mods (push) Successful in 1m44s
CI / Test (AMD64, Client) (push) Successful in 7m29s
CI / Test (ARM64, Client) (push) Successful in 7m32s
CI / Test (ARM64, Server) (push) Successful in 4m24s
CI / Test (ARMHF, Client) (push) Successful in 7m49s
CI / Test (ARMHF, Server) (push) Successful in 4m49s
CI / Release (push) Has been skipped
This commit is contained in:
parent
0dad883459
commit
eea9b31f70
@ -76,7 +76,7 @@ By default, MCPI-Reborn runs in a "compatibility mode." This makes it completely
|
||||
* Description: Clear all queued events.
|
||||
* Note: On RaspberryJuice, this *does not* clear projectile events. This behavior is maintained only in the compatibility mode.
|
||||
* `events.block.hits()`
|
||||
* Description: Retrieve all queued block hit events.
|
||||
* Description: Retrieve all queued block hit events. These events are generated by players using an [Iron Sword](https://minecraft.wiki/w/Iron_Sword) on blocks.
|
||||
* Output: List of `x,y,z,face,entity_id`
|
||||
|
||||
### RaspberryJuice
|
||||
@ -170,6 +170,9 @@ By default, MCPI-Reborn runs in a "compatibility mode." This makes it completely
|
||||
* `world.getGameMode()`
|
||||
* Description: Retrieve the game-mode of the loaded world.
|
||||
* Output: `game_mode`
|
||||
* `world.spawnItem(:x:,:y:,:z:,item_id,count,data)`
|
||||
* Description: Spawn the specified [Dropped Item](https://minecraft.wiki/w/Item_(entity)) at the given position.
|
||||
* Output: `entity_id`
|
||||
* `entity.getType(entity_id)`
|
||||
* Description: Check the type of the given entity. For special entities like players, this will be `0`.
|
||||
* Output: `entity_type_id`
|
||||
@ -182,6 +185,9 @@ By default, MCPI-Reborn runs in a "compatibility mode." This makes it completely
|
||||
* Description: Retrieve the specified entity's ID.
|
||||
* Note: Only the `player.getId()` version of this command is useful.
|
||||
* Output: `entity_id`
|
||||
* `entity.getSelectedItem(entity_id)`
|
||||
* Description: Retrieve the selected item of the specified entity. For humanoid mobs (like players), this will be their current carried item. For [Dropped Items](https://minecraft.wiki/w/Item_(entity)), this will be the item itself. This will return an item ID of `0` if the entity is not currently selecting an item.
|
||||
* Output: `item_id,count,data`
|
||||
|
||||
[^1]: These commands will never match players.
|
||||
[^2]: If the ID is `-1`, it will match all entities.
|
||||
|
@ -321,6 +321,33 @@ static std::string CommandServer_parse_injection(CommandServer_parse_t original,
|
||||
}
|
||||
return std::to_string(entity->id) + '\n';
|
||||
}
|
||||
command(spawnItem) {
|
||||
// Parse
|
||||
next_float(x);
|
||||
next_float(y);
|
||||
next_float(z);
|
||||
next_int(item_id);
|
||||
next_int(count);
|
||||
next_int(data);
|
||||
// Translate
|
||||
server->pos_translator.from_float(x, y, z);
|
||||
// Check Item Type
|
||||
if (count <= 0 || !Item::items[item_id]) {
|
||||
return CommandServer::Fail;
|
||||
}
|
||||
ItemInstance item = {
|
||||
.count = count,
|
||||
.id = item_id,
|
||||
.auxiliary = data
|
||||
};
|
||||
// Spawn
|
||||
ItemEntity *entity = ItemEntity::allocate();
|
||||
entity->constructor(server->minecraft->level, x, y, z, item);
|
||||
entity->velocity_x = entity->velocity_y = entity->velocity_z = 0;
|
||||
entity->moveTo(x, y, z, 0, 0);
|
||||
server->minecraft->level->addEntity((Entity *) entity);
|
||||
return std::to_string(entity->id) + '\n';
|
||||
}
|
||||
|
||||
// Get All Valid Entity Types
|
||||
command(getEntityTypes) {
|
||||
@ -560,6 +587,35 @@ static std::string CommandServer_parse_injection(CommandServer_parse_t original,
|
||||
// Get
|
||||
return api_join_outputs({std::to_string(entity->velocity_x), std::to_string(entity->velocity_y), std::to_string(entity->velocity_z)}, arg_separator);
|
||||
}
|
||||
|
||||
// Selected Item
|
||||
command(getSelectedItem) {
|
||||
// Parse
|
||||
get_entity(Fail);
|
||||
// Get Item
|
||||
ItemInstance air = {0, 0, 0};
|
||||
ItemInstance *item = nullptr;
|
||||
if (entity->isMob()) {
|
||||
// Mob/Player
|
||||
item = ((Mob *) entity)->getCarriedItem();
|
||||
if (!item) {
|
||||
item = &air;
|
||||
}
|
||||
} else if (entity->getEntityTypeId() == static_cast<int>(EntityType::DROPPED_ITEM)) {
|
||||
// Dropped Item
|
||||
item = &((ItemEntity *) entity)->item;
|
||||
}
|
||||
if (!item) {
|
||||
// Entity Does Not Carry Items
|
||||
return CommandServer::Fail;
|
||||
}
|
||||
// Return
|
||||
return api_join_outputs({
|
||||
std::to_string(item->id),
|
||||
std::to_string(item->count),
|
||||
std::to_string(item->auxiliary)
|
||||
}, arg_separator);
|
||||
}
|
||||
#undef get_entity
|
||||
#undef _get_entity
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
extends Entity;
|
||||
|
||||
size 0xf4;
|
||||
vtable 0x10c5b0;
|
||||
|
||||
constructor (Level *level, float x, float y, float z, const ItemInstance &item) = 0x86d70;
|
||||
|
||||
property ItemInstance item = 0xd0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user