mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 04:26:52 -04:00
Add /client blockedit command that allows changing some properties of blocks
This commit is contained in:
parent
33217d464d
commit
d453eb3d97
79
src/Chat.c
79
src/Chat.c
@ -646,6 +646,84 @@ static struct ChatCommand TeleportCommand = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*------------------------------------------------------BlockEditCommand----------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
static cc_bool BlockEditCommand_GetTexture(const cc_string* value, int* tex) {
|
||||||
|
int maxTexs = ATLAS1D_MAX_ATLASES;
|
||||||
|
|
||||||
|
if (!Convert_ParseInt(value, tex)) {
|
||||||
|
Chat_AddRaw("&eBlockEdit: &eTexture must be an integer");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*tex < 0 || *tex >= maxTexs) {
|
||||||
|
Chat_Add1("&eBlockEdit: &eTexture must be between 0 and %i", &maxTexs);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void BlockEditCommand_Execute(const cc_string* args, int argsCount__) {
|
||||||
|
cc_string parts[3];
|
||||||
|
cc_string* prop;
|
||||||
|
cc_string* value;
|
||||||
|
int argsCount, block, tex;
|
||||||
|
|
||||||
|
if (String_CaselessEqualsConst(args, "properties")) {
|
||||||
|
Chat_AddRaw("&eEditable block properties:");
|
||||||
|
Chat_AddRaw("&a name &e- Sets the name of the block");
|
||||||
|
Chat_AddRaw("&a all &e- Sets textures on all six sides of the block");
|
||||||
|
Chat_AddRaw("&a sides &e- Sets textures on four sides of the block");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
argsCount = String_UNSAFE_Split(args, ' ', parts, 3);
|
||||||
|
if (argsCount < 3) {
|
||||||
|
Chat_AddRaw("&eBlockEdit: &eThree arguments required &e(See &a/client help blockedit&e)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
block = Block_Parse(&parts[0]);
|
||||||
|
if (block == -1) {
|
||||||
|
Chat_Add1("&eBlockEdit: &c\"%s\" is not a valid block name or ID", &parts[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
prop = &parts[1];
|
||||||
|
value = &parts[2];
|
||||||
|
if (String_CaselessEqualsConst(prop, "name")) {
|
||||||
|
Block_SetName(block, value);
|
||||||
|
} else if (String_CaselessEqualsConst(prop, "all")) {
|
||||||
|
if (!BlockEditCommand_GetTexture(value, &tex)) return;
|
||||||
|
|
||||||
|
Block_SetSide(tex, block);
|
||||||
|
Block_Tex(block, FACE_YMAX) = tex;
|
||||||
|
Block_Tex(block, FACE_YMIN) = tex;
|
||||||
|
} else if (String_CaselessEqualsConst(prop, "sides")) {
|
||||||
|
if (!BlockEditCommand_GetTexture(value, &tex)) return;
|
||||||
|
|
||||||
|
Block_SetSide(tex, block);
|
||||||
|
} else {
|
||||||
|
Chat_Add1("&eBlockEdit: &eUnknown property %s &e(See &a/client help blockedit&e)", prop);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block_DefineCustom(block, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct ChatCommand BlockEditCommand = {
|
||||||
|
"BlockEdit", BlockEditCommand_Execute,
|
||||||
|
COMMAND_FLAG_SINGLEPLAYER_ONLY | COMMAND_FLAG_UNSPLIT_ARGS,
|
||||||
|
{
|
||||||
|
"&a/client blockedit [block] [property] [value]",
|
||||||
|
"&eEdits the given property of the given block",
|
||||||
|
"&a/client blockedit properties",
|
||||||
|
"&eLists the editable block properties",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-------------------------------------------------------Generic chat------------------------------------------------------*
|
*-------------------------------------------------------Generic chat------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
@ -681,6 +759,7 @@ static void OnInit(void) {
|
|||||||
Commands_Register(&CuboidCommand);
|
Commands_Register(&CuboidCommand);
|
||||||
Commands_Register(&TeleportCommand);
|
Commands_Register(&TeleportCommand);
|
||||||
Commands_Register(&ClearDeniedCommand);
|
Commands_Register(&ClearDeniedCommand);
|
||||||
|
Commands_Register(&BlockEditCommand);
|
||||||
|
|
||||||
#if defined CC_BUILD_MOBILE || defined CC_BUILD_WEB
|
#if defined CC_BUILD_MOBILE || defined CC_BUILD_WEB
|
||||||
/* Better to not log chat by default on mobile/web, */
|
/* Better to not log chat by default on mobile/web, */
|
||||||
|
@ -15,26 +15,19 @@ static int* iso_state_base;
|
|||||||
|
|
||||||
static cc_bool iso_cacheInited;
|
static cc_bool iso_cacheInited;
|
||||||
static PackedCol iso_colorXSide, iso_colorZSide, iso_colorYBottom;
|
static PackedCol iso_colorXSide, iso_colorZSide, iso_colorYBottom;
|
||||||
|
static float iso_posX, iso_posY;
|
||||||
|
|
||||||
#define iso_cosX (0.86602540378443864f) /* cos(30 * MATH_DEG2RAD) */
|
#define iso_cosX (0.86602540378443864f) /* cos(30 * MATH_DEG2RAD) */
|
||||||
#define iso_sinX (0.50000000000000000f) /* sin(30 * MATH_DEG2RAD) */
|
#define iso_sinX (0.50000000000000000f) /* sin(30 * MATH_DEG2RAD) */
|
||||||
#define iso_cosY (0.70710678118654752f) /* cos(-45 * MATH_DEG2RAD) */
|
#define iso_cosY (0.70710678118654752f) /* cos(-45 * MATH_DEG2RAD) */
|
||||||
#define iso_sinY (-0.70710678118654752f) /* sin(-45 * MATH_DEG2RAD) */
|
#define iso_sinY (-0.70710678118654752f) /* sin(-45 * MATH_DEG2RAD) */
|
||||||
|
|
||||||
static struct Matrix iso_transform;
|
|
||||||
static float iso_posX, iso_posY;
|
|
||||||
|
|
||||||
static void IsometricDrawer_InitCache(void) {
|
static void IsometricDrawer_InitCache(void) {
|
||||||
struct Matrix rotY, rotX;
|
|
||||||
if (iso_cacheInited) return;
|
if (iso_cacheInited) return;
|
||||||
|
|
||||||
iso_cacheInited = true;
|
iso_cacheInited = true;
|
||||||
PackedCol_GetShaded(PACKEDCOL_WHITE,
|
PackedCol_GetShaded(PACKEDCOL_WHITE,
|
||||||
&iso_colorXSide, &iso_colorZSide, &iso_colorYBottom);
|
&iso_colorXSide, &iso_colorZSide, &iso_colorYBottom);
|
||||||
|
|
||||||
Matrix_RotateY(&rotY, 45.0f * MATH_DEG2RAD);
|
|
||||||
Matrix_RotateX(&rotX, -30.0f * MATH_DEG2RAD);
|
|
||||||
Matrix_Mul(&iso_transform, &rotY, &rotX);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static TextureLoc IsometricDrawer_GetTexLoc(BlockID block, Face face) {
|
static TextureLoc IsometricDrawer_GetTexLoc(BlockID block, Face face) {
|
||||||
@ -76,6 +69,7 @@ static void IsometricDrawer_Angled(BlockID block, float size) {
|
|||||||
cc_bool bright;
|
cc_bool bright;
|
||||||
Vec3 min, max;
|
Vec3 min, max;
|
||||||
struct VertexTextured* beg = iso_vertices;
|
struct VertexTextured* beg = iso_vertices;
|
||||||
|
struct VertexTextured* v;
|
||||||
float x, y, scale;
|
float x, y, scale;
|
||||||
|
|
||||||
/* isometric coords size: cosY * -scale - sinY * scale */
|
/* isometric coords size: cosY * -scale - sinY * scale */
|
||||||
@ -104,12 +98,18 @@ static void IsometricDrawer_Angled(BlockID block, float size) {
|
|||||||
Drawer_YMax(1, PACKEDCOL_WHITE,
|
Drawer_YMax(1, PACKEDCOL_WHITE,
|
||||||
IsometricDrawer_GetTexLoc(block, FACE_YMAX), &iso_vertices);
|
IsometricDrawer_GetTexLoc(block, FACE_YMAX), &iso_vertices);
|
||||||
|
|
||||||
for (struct VertexTextured* v = beg; v < iso_vertices; v++)
|
for (v = beg; v < iso_vertices; v++)
|
||||||
{
|
{
|
||||||
/* Cut down Vec3_Transform (row4 is always 0, and don't need Z) */
|
/* Cut down form of: */
|
||||||
struct Matrix* mat = &iso_transform;
|
/* Matrix_RotateY(&rotY, 45.0f * MATH_DEG2RAD); */
|
||||||
x = v->X * mat->row1.X + v->Y * mat->row2.X + v->Z * mat->row3.X;
|
/* Matrix_RotateX(&rotX, -30.0f * MATH_DEG2RAD); */
|
||||||
y = v->X * mat->row1.Y + v->Y * mat->row2.Y + v->Z * mat->row3.Y;
|
/* Matrix_Mul(&iso_transform, &rotY, &rotX); */
|
||||||
|
/* ... */
|
||||||
|
/* Vec3 vec = { v.X, v.Y, v.Z }; */
|
||||||
|
/* Vec3_Transform(&vec, &vec, &iso_transform); */
|
||||||
|
/* With all unnecessary operations either simplified or removed */
|
||||||
|
x = v->X * iso_cosY + v->Z * -iso_sinY;
|
||||||
|
y = v->X * iso_sinX * iso_sinY + v->Y * iso_cosX + v->Z * iso_sinX * iso_cosY;
|
||||||
|
|
||||||
v->X = x + iso_posX;
|
v->X = x + iso_posX;
|
||||||
v->Y = y + iso_posY;
|
v->Y = y + iso_posY;
|
||||||
@ -173,5 +173,4 @@ void IsometricDrawer_EndBatch(GfxResourceID vb) {
|
|||||||
if (iso_state != iso_state_base) {
|
if (iso_state != iso_state_base) {
|
||||||
IsometricDrawer_Render(vb);
|
IsometricDrawer_Render(vb);
|
||||||
}
|
}
|
||||||
Gfx_LoadIdentityMatrix(MATRIX_VIEW);
|
|
||||||
}
|
}
|
@ -1518,9 +1518,13 @@ static void InventoryScreen_Init(void* screen) {
|
|||||||
Event_Register_(&BlockEvents.BlockDefChanged, s, InventoryScreen_OnBlockChanged);
|
Event_Register_(&BlockEvents.BlockDefChanged, s, InventoryScreen_OnBlockChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InventoryScreen_Render(void* screen, double delta) {
|
static void InventoryScreen_Update(void* screen, double delta) {
|
||||||
struct InventoryScreen* s = (struct InventoryScreen*)screen;
|
struct InventoryScreen* s = (struct InventoryScreen*)screen;
|
||||||
if (s->deferredSelect) InventoryScreen_MoveToSelected(s);
|
if (s->deferredSelect) InventoryScreen_MoveToSelected(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void InventoryScreen_Render(void* screen, double delta) {
|
||||||
|
struct InventoryScreen* s = (struct InventoryScreen*)screen;
|
||||||
Elem_Render(&s->table, delta);
|
Elem_Render(&s->table, delta);
|
||||||
Elem_Render(&s->title, delta);
|
Elem_Render(&s->title, delta);
|
||||||
}
|
}
|
||||||
@ -1604,7 +1608,7 @@ static int InventoryScreen_MouseScroll(void* screen, float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct ScreenVTABLE InventoryScreen_VTABLE = {
|
static const struct ScreenVTABLE InventoryScreen_VTABLE = {
|
||||||
InventoryScreen_Init, Screen_NullUpdate, InventoryScreen_Free,
|
InventoryScreen_Init, InventoryScreen_Update, InventoryScreen_Free,
|
||||||
InventoryScreen_Render, InventoryScreen_BuildMesh,
|
InventoryScreen_Render, InventoryScreen_BuildMesh,
|
||||||
InventoryScreen_KeyDown, InventoryScreen_KeyUp, Screen_TKeyPress, Screen_TText,
|
InventoryScreen_KeyDown, InventoryScreen_KeyUp, Screen_TKeyPress, Screen_TText,
|
||||||
InventoryScreen_PointerDown, InventoryScreen_PointerUp, InventoryScreen_PointerMove, InventoryScreen_MouseScroll,
|
InventoryScreen_PointerDown, InventoryScreen_PointerUp, InventoryScreen_PointerMove, InventoryScreen_MouseScroll,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user