Add Cake #81

Merged
TheBrokenRail merged 22 commits from bigjango13/minecraft-pi-reborn:master into master 2024-02-07 06:47:47 +00:00
5 changed files with 17 additions and 9 deletions
Showing only changes of commit c93350a44c - Show all commits

View File

@ -0,0 +1 @@
bool buckets_enabled();
bigjango13 marked this conversation as resolved Outdated

Please add a #pragma once.

Also, instead of a fancy method containing a static bool, why not just use an extern bool buckets_enabled, or just have buckets_enabled() check a variable.

bool buckets_enabled() {
    static bool ret = feature_has("Add Buckets", server_enabled);
    return ret;
}

just seems a bit over-complicated.

Please add a `#pragma once`. Also, instead of a fancy method containing a `static bool`, why not just use an `extern bool buckets_enabled`, or just have `buckets_enabled()` check a variable. ```c++ bool buckets_enabled() { static bool ret = feature_has("Add Buckets", server_enabled); return ret; } ``` just seems a bit over-complicated.

View File

@ -133,13 +133,14 @@ static int BucketItem_getUseDuration(__attribute__((unused)) FoodItem *item, Ite
return 0;
}
static void BucketItem_useTimeDepleted(FoodItem *item, uchar *param_1, ItemInstance *item_instance, Level *level, Player *player) {
static ItemInstance BucketItem_useTimeDepleted(FoodItem *item, ItemInstance *item_instance, Level *level, Player *player) {
if (item_instance->auxiliary == 1) {
(*FoodItem_useTimeDepleted_vtable_addr)(item, param_1, item_instance, level, player);
*item_instance = FoodItem_useTimeDepleted_non_virtual(item, item_instance, level, player);
bigjango13 marked this conversation as resolved Outdated

Use FoodItem_useTimeDepleted_non_virtual rather than de-referencing the address yourself.

Use `FoodItem_useTimeDepleted_non_virtual` rather than de-referencing the address yourself.
// Set it to a empty bucket
item_instance->auxiliary = 0;
item_instance->count = 1;
}
return *item_instance;
}
static int BucketItem_getUseAnimation(__attribute__((unused)) FoodItem *item) {
@ -349,9 +350,14 @@ static void Language_injection(__attribute__((unused)) void *null) {
}
// Init
bool buckets_enabled() {
static bool ret = feature_has("Add Buckets", server_enabled);
return ret;
}
void init_bucket() {
// Add Buckets
if (feature_has("Add Buckets", server_enabled)) {
if (buckets_enabled()) {
// Add Items
misc_run_on_items_setup(Item_initItems_injection);
// Change Max Stack Size Based On Auxiliary

View File

@ -4,8 +4,9 @@
#include <mods/feature/feature.h>
#include <mods/init/init.h>
#include <mods/misc/misc.h>
#include <mods/bucket/bucket.h>
bigjango13 marked this conversation as resolved
Review

This should probably be static.

This should probably be `static`.
Tile *cake = NULL;
static Tile *cake = NULL;
#define CAKE_LEN 0.0625F
@ -166,7 +167,7 @@ static void Inventory_setupDefault_FillingContainer_addItem_call_injection(Filli
cake_instance->count = 255;
cake_instance->auxiliary = 0;
cake_instance->id = 92;
bigjango13 marked this conversation as resolved
Review

Remove the (* and ).

Remove the `(*` and `)`.
(*FillingContainer_addItem)(filling_container, cake_instance);
FillingContainer_addItem(filling_container, cake_instance);
}
// Recipe (only when buckets are enabled)
@ -234,7 +235,7 @@ void init_cake() {
if (feature_has("Add Cake", server_enabled)) {
misc_run_on_tiles_setup(Tile_initTiles_injection);
misc_run_on_creative_inventory_setup(Inventory_setupDefault_FillingContainer_addItem_call_injection);
bigjango13 marked this conversation as resolved
Review

feature_has should ideally only run once per feature (to avoid redundant log entries). Maybe bucket could set a variable if it's enabled?

`feature_has` should ideally only run once per feature (to avoid redundant log entries). Maybe `bucket` could set a variable if it's enabled?
if (feature_has("Add Buckets", server_enabled)) {
if (buckets_enabled()) {
// The recipe needs milk buckets
misc_run_on_recipes_setup(Recipes_injection);
}

View File

@ -1,5 +1,6 @@
extends Screen;
bigjango13 marked this conversation as resolved Outdated

Shouldn't this extend Screen?

Shouldn't this extend `Screen`?
method void craftSelectedItem() = 0x2e0e4;
method void recheckRecipes() = 0x2dc98;
property Minecraft *minecraft = 0x14;
property CItem *item = 0x74;

View File

@ -11,8 +11,7 @@ virtual-method void setIcon(int texture_x, int texture_y) = 0x18;
virtual-method int useOn(ItemInstance *item_instance, Player *player, Level *level, int x, int y, int z, int hit_side, float hit_x, float hit_y, float hit_z) = 0x20;
// Normally returns 0
virtual-method int getUseDuration(ItemInstance *item_instance) = 0x24;
// I don't know much about param_1, it might be some partially initialized ItemInstance*
virtual-method void useTimeDepleted(uchar *param_1, ItemInstance *item_instance, Level *level, Player *player) = 0x28;
virtual-method ItemInstance useTimeDepleted(ItemInstance *item_instance, Level *level, Player *player) = 0x28;
virtual-method int getDestorySpeed(ItemInstance *item_instance, Tile *tile) = 0x2c;
bigjango13 marked this conversation as resolved
Review

This seems wrong. According to Ghidra, this function's signature is Item::useTimeDepleted(ItemInstance*, Level*, Player*) (and of course an extra Item *self).

It could be returning a structure, IIRC if a function returns a structure, the caller allocates the structure and passes a pointer to it as the first argument top the function (like how this is passed) and then the function writes to that pointer. Check out CommandServer::parse in Ghidra.

This seems wrong. According to Ghidra, this function's signature is `Item::useTimeDepleted(ItemInstance*, Level*, Player*)` (and of course an extra `Item *self`). It could be returning a structure, IIRC if a function returns a structure, the caller allocates the structure and passes a pointer to it as the first argument top the function (like how `this` is passed) and then the function writes to that pointer. Check out `CommandServer::parse` in Ghidra.
Review

Hmm, seems like it. it tripped me up because both Item and ItemInstance have the id at 0x4.

Hmm, seems like it. it tripped me up because both Item and ItemInstance have the id at 0x4.
virtual-method ItemInstance *use(ItemInstance *item_instance, Level *level, Player *player) = 0x30;
virtual-method bool mineBlock(ItemInstance *instance, int tile_id, int x, int y, int z) = 0x48;