Update Cake To CustomTile
This commit is contained in:
parent
c80d61216b
commit
8ab3c44e7e
@ -55,8 +55,9 @@ auto extend_struct(auto&&... args) -> decltype(Self::allocate()) {
|
||||
// Helpers
|
||||
#define CREATE_HELPER(name) \
|
||||
struct Custom##name { \
|
||||
__PREVENT_COPY(Custom##name); \
|
||||
using _Self = name; \
|
||||
explicit Custom##name(auto&&... args): self(((name *) this) - 1) { \
|
||||
Custom##name(auto&&... args): self(((name *) this) - 1) { \
|
||||
self->constructor(std::forward<decltype(args)>(args)...); \
|
||||
self->vtable = get_vtable(); \
|
||||
} \
|
||||
|
@ -6,156 +6,148 @@
|
||||
#include <mods/bucket/bucket.h>
|
||||
#include <mods/extend/extend.h>
|
||||
|
||||
#define CAKE_LEN 0.0625f
|
||||
#define CAKE_SLICE_COUNT 6
|
||||
|
||||
// Custom Tile
|
||||
struct Cake final : CustomTile {
|
||||
// Constructor
|
||||
Cake(const int id, const int texture, const Material *material): CustomTile(id, texture, material) {}
|
||||
|
||||
// Textures
|
||||
int getTexture2(const int face, __attribute__((unused)) int data) override {
|
||||
if (face == 1) {
|
||||
// Top Texture
|
||||
return 121;
|
||||
} else if (face == 0) {
|
||||
// Bottom Texture
|
||||
return 124;
|
||||
}
|
||||
// Side Texture
|
||||
return 122;
|
||||
}
|
||||
int getTexture3(LevelSource *level, const int x, const int y, const int z, const int face) override {
|
||||
// Eaten Face
|
||||
if (face == 3) {
|
||||
const int data = level->getData(x, y, z);
|
||||
if (data != 0 && data < CAKE_SLICE_COUNT) {
|
||||
// Sliced Texture
|
||||
return 123;
|
||||
}
|
||||
}
|
||||
// Normal
|
||||
return getTexture2(face, 0);
|
||||
}
|
||||
|
||||
// Rendering
|
||||
bool isSolidRender() override {
|
||||
// Stop From Turning Other Blocks Invisible
|
||||
return false;
|
||||
}
|
||||
int getRenderLayer() override {
|
||||
// Stop Weird Transparency Issues
|
||||
return 1;
|
||||
}
|
||||
bool isCubeShaped() override {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Size
|
||||
static void getShape(const int data, float &x0, float &y0, float &z0, float &x1, float &y1, float &z1) {
|
||||
x0 = CAKE_LEN;
|
||||
y0 = 0;
|
||||
z0 = x0;
|
||||
x1 = 1 - CAKE_LEN;
|
||||
y1 = 0.5f;
|
||||
z1 = x1;
|
||||
z1 -= (1 - (CAKE_LEN * 2)) * (float(data) / float(CAKE_SLICE_COUNT));
|
||||
}
|
||||
void updateShape(const int data) const {
|
||||
float x0, y0, z0;
|
||||
float x1, y1, z1;
|
||||
getShape(data, x0, y0, z0, x1, y1, z1);
|
||||
self->setShape(
|
||||
x0, y0, z0,
|
||||
x1, y1, z1
|
||||
);
|
||||
}
|
||||
void updateDefaultShape() override {
|
||||
updateShape(0);
|
||||
}
|
||||
static int getData(LevelSource *level, const int x, const int y, const int z) {
|
||||
int data = level->getData(x, y, z);
|
||||
if (data >= CAKE_SLICE_COUNT) {
|
||||
data = 0;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
void updateShape(LevelSource *level, const int x, const int y, const int z) override {
|
||||
// Get Cake
|
||||
const int data = getData(level, x, y, z);
|
||||
// Get Slice Amount
|
||||
updateShape(data);
|
||||
}
|
||||
AABB *getAABB(Level *level, const int x, const int y, const int z) override {
|
||||
// Get Shape
|
||||
const int data = getData((LevelSource *) level, x, y, z);
|
||||
float x0, y0, z0;
|
||||
float x1, y1, z1;
|
||||
getShape(data, x0, y0, z0, x1, y1, z1);
|
||||
|
||||
// Corner 1
|
||||
AABB *aabb = &self->aabb;
|
||||
aabb->x1 = float(x) + x0;
|
||||
aabb->y1 = float(y) + y0;
|
||||
aabb->z1 = float(z) + z0;
|
||||
|
||||
// Corner 2
|
||||
aabb->x2 = float(x) + x1;
|
||||
aabb->y2 = float(y) + y1;
|
||||
aabb->z2 = float(z) + z1;
|
||||
|
||||
// Return
|
||||
return aabb;
|
||||
}
|
||||
|
||||
// Eating
|
||||
int use(Level *level, const int x, const int y, const int z, Player *player) override {
|
||||
// Eat
|
||||
player->foodData.eat(3);
|
||||
// Set New Tile
|
||||
int data = level->getData(x, y, z);
|
||||
data++;
|
||||
if (data >= CAKE_SLICE_COUNT) {
|
||||
// Remove the cake, it has been completely gobbled up
|
||||
level->setTileAndData(x, y, z, 0, 0);
|
||||
} else {
|
||||
// Remove a slice
|
||||
level->setTileAndData(x, y, z, self->id, data);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
static Tile *cake = nullptr;
|
||||
|
||||
#define CAKE_LEN 0.0625F
|
||||
|
||||
// Description
|
||||
static std::string Cake_getDescriptionId(__attribute__((unused)) Tile *tile) {
|
||||
return "tile.cake";
|
||||
}
|
||||
|
||||
// Textures
|
||||
static int Cake_getTexture2(__attribute__((unused)) Tile *tile, const int face, __attribute__((unused)) int data) {
|
||||
if (face == 1) {
|
||||
// Top texture
|
||||
return 121;
|
||||
} else if (face == 0) {
|
||||
// Bottom texture
|
||||
return 124;
|
||||
}
|
||||
// Side texture
|
||||
return 122;
|
||||
}
|
||||
|
||||
static int Cake_getTexture3(__attribute__((unused)) Tile *tile, LevelSource *level, int x, int y, int z, const int face) {
|
||||
// Eaten face
|
||||
if (face == 3) {
|
||||
const int data = level->getData(x, y, z);
|
||||
if (data != 0 && data < 6) {
|
||||
// Sliced texture
|
||||
return 123;
|
||||
}
|
||||
}
|
||||
// Normal
|
||||
return Cake_getTexture2(tile, face, 0);
|
||||
}
|
||||
|
||||
// Rendering
|
||||
static bool Cake_isSolidRender(__attribute__((unused)) Tile *tile) {
|
||||
// Stop it from turning other blocks invisable
|
||||
return false;
|
||||
}
|
||||
|
||||
static int Cake_getRenderLayer(__attribute__((unused)) Tile *tile) {
|
||||
// Stop weird transparency issues
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool Cake_isCubeShaped(__attribute__((unused)) Tile *tile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Size
|
||||
static void Cake_updateDefaultShape(Tile *tile) {
|
||||
// Set the default shape
|
||||
tile->setShape(
|
||||
CAKE_LEN, 0.0, CAKE_LEN,
|
||||
1.0 - CAKE_LEN, 0.5, 1.0 - CAKE_LEN
|
||||
);
|
||||
}
|
||||
|
||||
static AABB *Cake_getAABB(Tile *tile, Level *level, int x, int y, int z) {
|
||||
// Get the size of the slices
|
||||
int data = level->getData(x, y, z);
|
||||
if (data >= 6) data = 0;
|
||||
const float slice_size = (1.0f / 7.0f) * (float) data;
|
||||
|
||||
// Corner 1
|
||||
AABB *aabb = &tile->aabb;
|
||||
aabb->x1 = (float) x + CAKE_LEN;
|
||||
aabb->y1 = (float) y;
|
||||
aabb->z1 = (float) z + CAKE_LEN;
|
||||
|
||||
// Corner 2
|
||||
aabb->x2 = (float) x + (1.0f - CAKE_LEN);
|
||||
aabb->y2 = (float) y + 0.5f;
|
||||
aabb->z2 = (float) z + (1.0f - CAKE_LEN) - slice_size;
|
||||
|
||||
return aabb;
|
||||
}
|
||||
|
||||
static void Cake_updateShape(Tile *tile, LevelSource *level, int x, int y, int z) {
|
||||
// Set cake
|
||||
int data = level->getData(x, y, z);
|
||||
if (data >= 6) data = 0;
|
||||
// Get slice amount
|
||||
const float slice_size = (1.0f / 7.0f) * (float) data;
|
||||
tile->setShape(
|
||||
CAKE_LEN, 0.0, CAKE_LEN,
|
||||
1.0 - CAKE_LEN, 0.5, (1.0 - CAKE_LEN) - slice_size
|
||||
);
|
||||
}
|
||||
|
||||
// Eating
|
||||
static int Cake_use(__attribute__((unused)) Tile *tile, Level *level, int x, int y, int z, Player *player) {
|
||||
// Eat
|
||||
player->foodData.eat(3);
|
||||
// Set the new tile
|
||||
const int data = level->getData(x, y, z);
|
||||
if (data >= 5) {
|
||||
// Remove the cake, it has been completely gobbled up
|
||||
level->setTileAndData(x, y, z, 0, 0);
|
||||
} else {
|
||||
// Remove a slice
|
||||
level->setTileAndData(x, y, z, 92, data + 1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Makes the cakes
|
||||
// Makes The Cakes
|
||||
static void make_cake() {
|
||||
// Construct
|
||||
cake = Tile::allocate();
|
||||
int texture = 122;
|
||||
cake->constructor(92, texture, Material::dirt);
|
||||
cake->texture = texture;
|
||||
cake = extend_struct<Cake>(92, 122, Material::dirt);
|
||||
|
||||
// Set VTable
|
||||
cake->vtable = extend_dup_vtable(Tile_vtable::base);
|
||||
|
||||
// Set shape
|
||||
cake->setShape(
|
||||
CAKE_LEN, 0.0, CAKE_LEN,
|
||||
1.0 - CAKE_LEN, 0.5, 1.0 - CAKE_LEN
|
||||
);
|
||||
|
||||
// Modify functions
|
||||
cake->vtable->getDescriptionId = Cake_getDescriptionId;
|
||||
cake->vtable->getTexture3 = Cake_getTexture3;
|
||||
cake->vtable->getTexture2 = Cake_getTexture2;
|
||||
cake->vtable->isSolidRender = Cake_isSolidRender;
|
||||
cake->vtable->getRenderLayer = Cake_getRenderLayer;
|
||||
cake->vtable->isCubeShaped = Cake_isCubeShaped;
|
||||
cake->vtable->updateShape = Cake_updateShape;
|
||||
cake->vtable->updateDefaultShape = Cake_updateDefaultShape;
|
||||
cake->vtable->getAABB = Cake_getAABB;
|
||||
cake->vtable->use = Cake_use;
|
||||
// Set Shape
|
||||
cake->updateDefaultShape();
|
||||
|
||||
// Init
|
||||
cake->init();
|
||||
cake->setDescriptionId("cake");
|
||||
cake->setDestroyTime(1.0f);
|
||||
cake->setExplodeable(20.0f);
|
||||
cake->category = 4;
|
||||
std::string name = "Cake";
|
||||
cake->setDescriptionId(name);
|
||||
}
|
||||
|
||||
static void Tile_initTiles_injection() {
|
||||
make_cake();
|
||||
}
|
||||
|
||||
// Add cake to creative inventory
|
||||
// Add Cake To Creative Inventory
|
||||
static void Inventory_setupDefault_FillingContainer_addItem_call_injection(FillingContainer *filling_container) {
|
||||
ItemInstance *cake_instance = new ItemInstance;
|
||||
cake_instance->count = 255;
|
||||
@ -164,7 +156,7 @@ static void Inventory_setupDefault_FillingContainer_addItem_call_injection(Filli
|
||||
filling_container->addItem(cake_instance);
|
||||
}
|
||||
|
||||
// Recipe (only when buckets are enabled)
|
||||
// Recipe (Only When Buckets Are Enabled)
|
||||
static void Recipes_injection(Recipes *recipes) {
|
||||
// Sugar
|
||||
constexpr Recipes_Type sugar = {
|
||||
@ -224,8 +216,9 @@ static void Recipes_injection(Recipes *recipes) {
|
||||
recipes->addShapedRecipe_3(cake_item, line1, line2, line3, ingredients);
|
||||
}
|
||||
|
||||
// Init
|
||||
void init_cake() {
|
||||
// Add cakes
|
||||
// Add Cakes
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user