Small Implementation Tweaks
All checks were successful
CI / Build (AMD64) (push) Successful in 25m29s
CI / Build (ARM64) (push) Successful in 27m44s
CI / Build (ARMHF) (push) Successful in 17m49s
CI / Test (AMD64, Server) (push) Successful in 3m39s
CI / Test (ARM64, Client) (push) Successful in 7m28s
CI / Build Example Mods (push) Successful in 3m58s
CI / Test (ARM64, Server) (push) Successful in 4m32s
CI / Test (AMD64, Client) (push) Successful in 8m20s
CI / Test (ARMHF, Client) (push) Successful in 8m21s
CI / Test (ARMHF, Server) (push) Successful in 4m46s
CI / Release (push) Has been skipped
All checks were successful
CI / Build (AMD64) (push) Successful in 25m29s
CI / Build (ARM64) (push) Successful in 27m44s
CI / Build (ARMHF) (push) Successful in 17m49s
CI / Test (AMD64, Server) (push) Successful in 3m39s
CI / Test (ARM64, Client) (push) Successful in 7m28s
CI / Build Example Mods (push) Successful in 3m58s
CI / Test (ARM64, Server) (push) Successful in 4m32s
CI / Test (AMD64, Client) (push) Successful in 8m20s
CI / Test (ARMHF, Client) (push) Successful in 8m21s
CI / Test (ARMHF, Server) (push) Successful in 4m46s
CI / Release (push) Has been skipped
This commit is contained in:
parent
eea9b31f70
commit
48373d4a5c
@ -59,7 +59,7 @@ std::map<EntityType, std::pair<std::string, std::string>> &misc_get_entity_type_
|
||||
std::pair<std::string, std::string> misc_get_entity_type_name(Entity *entity);
|
||||
std::string misc_get_entity_name(Entity *entity);
|
||||
|
||||
Entity *misc_make_entity_from_id(Level *level, int id, float x, float y, float z);
|
||||
Entity *misc_make_entity_from_id(Level *level, int id, float x, float y, float z, bool add_to_level = true);
|
||||
|
||||
std::string misc_base64_encode(const std::string &data);
|
||||
std::string misc_base64_decode(const std::string &input);
|
||||
|
@ -142,6 +142,23 @@ static bool is_entity_selected(Entity *entity, const int target_type) {
|
||||
return type > 0 && (target_type == no_entity_id || target_type == type);
|
||||
}
|
||||
|
||||
// Get Selected Item
|
||||
static ItemInstance *get_selected_item(Entity *entity) {
|
||||
ItemInstance *item = nullptr;
|
||||
if (entity->isMob()) {
|
||||
// Mob/Player
|
||||
item = ((Mob *) entity)->getCarriedItem();
|
||||
if (!item) {
|
||||
static ItemInstance air = {0, 0, 0};
|
||||
item = &air;
|
||||
}
|
||||
} else if (entity->getEntityTypeId() == static_cast<int>(EntityType::DROPPED_ITEM)) {
|
||||
// Dropped Item
|
||||
item = &((ItemEntity *) entity)->item;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
// Read Arguments
|
||||
#define next_string(out, required) \
|
||||
std::string out; \
|
||||
@ -214,7 +231,7 @@ static std::string CommandServer_parse_injection(CommandServer_parse_t original,
|
||||
}
|
||||
|
||||
// Read Arguments
|
||||
std::stringstream args(args_str.data());
|
||||
std::istringstream args(std::string(args_str), std::ios::in);
|
||||
|
||||
// Manipulate The Level
|
||||
package(world) {
|
||||
@ -249,9 +266,9 @@ static std::string CommandServer_parse_injection(CommandServer_parse_t original,
|
||||
// Search
|
||||
std::string username = api_get_input(input);
|
||||
for (Player *player : server->minecraft->level->players) {
|
||||
if (misc_get_player_username_utf(player) == username) {
|
||||
if (player->username == username) {
|
||||
// Found
|
||||
return std::to_string(player->id) + "\n";
|
||||
return std::to_string(player->id) + '\n';
|
||||
}
|
||||
}
|
||||
return CommandServer::Fail;
|
||||
@ -341,10 +358,16 @@ static std::string CommandServer_parse_injection(CommandServer_parse_t original,
|
||||
.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);
|
||||
ItemEntity *entity = (ItemEntity *) misc_make_entity_from_id(
|
||||
server->minecraft->level,
|
||||
static_cast<int>(EntityType::DROPPED_ITEM),
|
||||
x, y, z,
|
||||
false
|
||||
);
|
||||
if (!entity) {
|
||||
return CommandServer::Fail;
|
||||
}
|
||||
entity->item = item;
|
||||
server->minecraft->level->addEntity((Entity *) entity);
|
||||
return std::to_string(entity->id) + '\n';
|
||||
}
|
||||
@ -593,18 +616,7 @@ static std::string CommandServer_parse_injection(CommandServer_parse_t original,
|
||||
// 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;
|
||||
}
|
||||
ItemInstance *item = get_selected_item(entity);
|
||||
if (!item) {
|
||||
// Entity Does Not Carry Items
|
||||
return CommandServer::Fail;
|
||||
|
@ -205,7 +205,7 @@ std::map<EntityType, std::pair<std::string, std::string>> &misc_get_entity_type_
|
||||
}
|
||||
|
||||
// Spawn Entities
|
||||
Entity *misc_make_entity_from_id(Level *level, const int id, const float x, const float y, const float z) {
|
||||
Entity *misc_make_entity_from_id(Level *level, const int id, const float x, const float y, const float z, const bool add_to_level) {
|
||||
// Create
|
||||
Entity *entity;
|
||||
if (id < static_cast<int>(EntityType::DROPPED_ITEM)) {
|
||||
@ -254,12 +254,16 @@ Entity *misc_make_entity_from_id(Level *level, const int id, const float x, cons
|
||||
}
|
||||
case static_cast<int>(EntityType::DROPPED_ITEM): {
|
||||
// Sensible Default
|
||||
((ItemEntity *) entity)->item.constructor_item(Item::sword_iron);
|
||||
ItemEntity *item = (ItemEntity *) entity;
|
||||
item->item.constructor_tile(Tile::rock);
|
||||
item->pickup_delay = 10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Add To World
|
||||
level->addEntity(entity);
|
||||
if (add_to_level) {
|
||||
level->addEntity(entity);
|
||||
}
|
||||
}
|
||||
// Return
|
||||
return entity;
|
||||
|
@ -7,4 +7,5 @@ constructor (Level *level, float x, float y, float z, const ItemInstance &item)
|
||||
|
||||
property ItemInstance item = 0xd0;
|
||||
property int age = 0xdc;
|
||||
property float bob_offset = 0xe4;
|
||||
property float bob_offset = 0xe4;
|
||||
property int pickup_delay = 0xe0;
|
@ -99,6 +99,7 @@ static-property Tile *stoneSlab = 0x181b44;
|
||||
static-property Tile *fire = 0x181de0;
|
||||
static-property Tile *sand = 0x181b20;
|
||||
static-property Tile *torch = 0x181d58;
|
||||
static-property Tile *rock = 0x181c90;
|
||||
|
||||
// "Carried" Tiles
|
||||
static-property Tile *leaves_carried = 0x181dd8;
|
||||
|
Loading…
x
Reference in New Issue
Block a user