Skip to content

Commit

Permalink
start adding crafter
Browse files Browse the repository at this point in the history
  • Loading branch information
erich666 committed Jun 20, 2024
1 parent 945262f commit 0827cd6
Show file tree
Hide file tree
Showing 5 changed files with 630 additions and 491 deletions.
140 changes: 126 additions & 14 deletions Win/ObjFileManip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22998,24 +22998,24 @@ static int getSwatch(int type, int dataVal, int faceDirection, int backgroundInd
if (faceDirection == DIRECTION_BLOCK_BOTTOM)
{
// easy
swatchLoc = SWATCH_INDEX(5, 64);
swatchLoc = SWATCH_INDEX(4, 64);
}
else if (faceDirection == DIRECTION_BLOCK_TOP) {
// top has ejecting_reward/active/inactive
if ( (dataVal & 0x3) == 0)
{
// inactive
// stays the same: swatchLoc = SWATCH_INDEX(14, 64);
// stays the same: swatchLoc = SWATCH_INDEX(12, 64);
}
else if ((dataVal & 0x3) == 3)
{
// ejecting
swatchLoc = SWATCH_INDEX(12, 64);
swatchLoc = SWATCH_INDEX(11, 64);
}
else
{
// active, waiting for
swatchLoc = SWATCH_INDEX(10, 64);
swatchLoc = SWATCH_INDEX(9, 64);
}

if (dataVal & 0x4) {
Expand All @@ -23028,12 +23028,12 @@ static int getSwatch(int type, int dataVal, int faceDirection, int backgroundInd
if ((dataVal & 0x3) == 0)
{
// inactive
swatchLoc = SWATCH_INDEX(8, 64);
swatchLoc = SWATCH_INDEX(7, 64);
}
else
{
// active or ejecting - same
swatchLoc = SWATCH_INDEX(6, 64);
swatchLoc = SWATCH_INDEX(5, 64);
}

if (dataVal & 0x4) {
Expand All @@ -23051,19 +23051,19 @@ static int getSwatch(int type, int dataVal, int faceDirection, int backgroundInd
if (faceDirection == DIRECTION_BLOCK_BOTTOM)
{
// easy
swatchLoc = SWATCH_INDEX(1, 65);
swatchLoc = SWATCH_INDEX(0, 65);
}
else if (faceDirection == DIRECTION_BLOCK_TOP) {
// top has ejecting
if (dataVal & (0x3 << 3))
{
// ejecting
swatchLoc = SWATCH_INDEX(15, 65);
swatchLoc = SWATCH_INDEX(14, 65);
}
//else
//{
// everything else - default
//swatchLoc = SWATCH_INDEX(13, 65);
//swatchLoc = SWATCH_INDEX(12, 65);
//}
}
else {
Expand All @@ -23076,30 +23076,30 @@ static int getSwatch(int type, int dataVal, int faceDirection, int backgroundInd
if ((dataVal & (0x3 << 3)) == ((0x0) << 3))
{
// inactive
swatchLoc = SWATCH_INDEX(5, 65);
swatchLoc = SWATCH_INDEX(4, 65);
}
else if ((dataVal & (0x3 << 3)) == ((0x1) << 3))
{
// active
swatchLoc = SWATCH_INDEX(7, 65);
swatchLoc = SWATCH_INDEX(6, 65);
}
else // if ((dataVal & (0x3 << 3)) == ((0x2) << 3))
{
// unlocking and ejecting are the same
swatchLoc = SWATCH_INDEX(3, 65);
swatchLoc = SWATCH_INDEX(2, 65);
}
}
else {
// side facing: off, on
if ((dataVal & (0x3 << 3)) == ((0x0) << 3))
{
// inactive
swatchLoc = SWATCH_INDEX(9, 65);
swatchLoc = SWATCH_INDEX(8, 65);
}
else
{
// everything else
swatchLoc = SWATCH_INDEX(11, 65);
swatchLoc = SWATCH_INDEX(10, 65);
}
}
}
Expand All @@ -23110,6 +23110,118 @@ static int getSwatch(int type, int dataVal, int faceDirection, int backgroundInd
}
break;

case BLOCK_CRAFTER:
// given 0-11 for the orientation (the bottom four bits), we return whether it's a bottom, top, north, south, east, or west face
// Input order is orientation order: south, west, north, east; then up_ then down_
// Order is: bottom, top, south, west, north, east == 0-5
// In other words
{
// faceDirection => west/bottom/north/east/top/south
int crafterFaceType[6 * 12] = {
0,0,0,0,0,0,0,0,0,0,0,0, // west
1,1,1,1,1,1,1,1,1,1,1,1, // bottom
2,2,2,2,2,2,2,2,2,2,2,2, // north
3,3,3,3,3,3,3,3,3,3,3,3, // east
4,4,4,4,4,4,4,4,4,4,4,4, // top
5,5,5,5,5,5,5,5,5,5,5,5 // south
};
int crafterAngle[6 * 12] = {
0,0,0,0,0,0,0,0,0,0,0,0, // west
0,0,0,0,0,0,0,0,0,0,0,0, // bottom
0,0,0,0,0,0,0,0,0,0,0,0, // north
0,0,0,0,0,0,0,0,0,0,0,0, // east
0,0,0,0,0,0,0,0,0,0,0,0, // top
0,0,0,0,0,0,0,0,0,0,0,0 // south
};

int swatchSide = crafterFaceType[12 * faceDirection + (dataVal & 0xF)];
switch (swatchSide) {
default:
assert(0);
// fall through, just in case
case DIRECTION_BLOCK_SIDE_LO_X:
// west
if (dataVal & BIT_16) {
// crafting - overrides triggered for the top
swatchLoc = SWATCH_INDEX(14, 62);
}
else if (dataVal & BIT_32) {
// triggered
swatchLoc = SWATCH_INDEX(15, 62);
}
else {
// normal
swatchLoc = SWATCH_INDEX(13, 62);
}
break;
case DIRECTION_BLOCK_BOTTOM:
swatchLoc = SWATCH_INDEX(2, 62);
break;
case DIRECTION_BLOCK_SIDE_LO_Z:
// north
if (dataVal & BIT_16) {
// crafting - overrides triggered for the top
swatchLoc = SWATCH_INDEX(7, 62);
}
else {
// normal
swatchLoc = SWATCH_INDEX(6, 62);
}
break;
case DIRECTION_BLOCK_SIDE_HI_X:
// east
if (dataVal & BIT_16) {
// crafting - overrides triggered for the top
swatchLoc = SWATCH_INDEX(4, 62);
}
else if (dataVal & BIT_32) {
// triggered
swatchLoc = SWATCH_INDEX(5, 62);
}
else {
// normal
swatchLoc = SWATCH_INDEX(3, 62);
}
break;
case DIRECTION_BLOCK_TOP:
if (dataVal & BIT_16) {
// crafting - overrides triggered for the top
swatchLoc = SWATCH_INDEX(11, 62);
}
else if (dataVal & BIT_32) {
// triggered
swatchLoc = SWATCH_INDEX(12, 62);
}
else {
// normal
swatchLoc = SWATCH_INDEX(10, 62);
}
break;
case DIRECTION_BLOCK_SIDE_HI_Z:
// south
if (dataVal & BIT_32) {
// triggered
swatchLoc = SWATCH_INDEX(9, 62);
}
else {
// normal
swatchLoc = SWATCH_INDEX(8, 62);
}
break;
}
// need to rotate?
if (uvIndices)
{
int swatchAngle = crafterAngle[12 * faceDirection + (dataVal & 0xF)];
if (swatchAngle != 0)
{
rotateIndices(localIndices, swatchAngle);
}
}
}
break;

//================================================================================================
default:
// if something has cutouts, it almost assuredly needs to have a case above with a call to getCompositeSwatch()
#ifdef _DEBUG
Expand Down
6 changes: 3 additions & 3 deletions Win/blockInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,9 @@ BlockDefinition gBlockDefinitions[NUM_BLOCKS_DEFINED] = {
{ /* 462 */ "Crimson Hanging Sign", 0x8A3A5A, 1.000f, 0xff7711, 0xff7711, 0.12345f, 13, 43, 0x20, BLF_SMALL_MIDDLER | BLF_TRUE_GEOMETRY | BLF_3D_BIT | BLF_DNE_FLUID | BLF_MAYWATERLOG },
{ /* 463 */ "Mangrove Hanging Sign", 0x783730, 1.000f, 0xff7711, 0xff7711, 0.12345f, 15, 54, 0x20, BLF_SMALL_MIDDLER | BLF_TRUE_GEOMETRY | BLF_3D_BIT | BLF_DNE_FLUID | BLF_MAYWATERLOG },
{ /* 464 */ "Bamboo Hanging Sign", 0xC4AF52, 1.000f, 0xff7711, 0xff7711, 0.12345f, 11, 60, 0x00, BLF_SMALL_MIDDLER | BLF_TRUE_GEOMETRY | BLF_3D_BIT | BLF_DNE_FLUID | BLF_MAYWATERLOG },
{ /* 465 */ "Trial Spawner", 0x767677, 1.000f, 0xff7711, 0xff7711, 0.12345f, 14, 64, 0x00, BLF_WHOLE | BLF_FENCE_NEIGHBOR | BLF_EMITTER },
{ /* 466 */ "Vault", 0x404E56, 1.000f, 0xff7711, 0xff7711, 0.12345f, 13, 65, 0x00, BLF_WHOLE | BLF_FENCE_NEIGHBOR | BLF_EMITTER },
{ /* 467 */ "Crafter", 0x777272, 1.000f, 0xff7711, 0xff7711, 0.12345f, 11, 62, 0x00, BLF_WHOLE | BLF_FENCE_NEIGHBOR },
{ /* 465 */ "Trial Spawner", 0x767677, 1.000f, 0xff7711, 0xff7711, 0.12345f, 13, 64, 0x00, BLF_WHOLE | BLF_FENCE_NEIGHBOR | BLF_EMITTER },
{ /* 466 */ "Vault", 0x404E56, 1.000f, 0xff7711, 0xff7711, 0.12345f, 12, 65, 0x00, BLF_WHOLE | BLF_FENCE_NEIGHBOR | BLF_EMITTER },
{ /* 467 */ "Crafter", 0x777272, 1.000f, 0xff7711, 0xff7711, 0.12345f, 10, 62, 0x00, BLF_WHOLE | BLF_FENCE_NEIGHBOR },

// Important note: 396 is skipped, it's the BLOCK_FLOWER_POT, also skip 400, BLOCK_HEAD. Nicer still would be to redo the code for those two blocks (and redo IDBlock() method) so that we don't use up all 8 bits
};
Expand Down
49 changes: 38 additions & 11 deletions Win/nbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ static TranslationTuple* modTranslations = NULL;
// rotation: 0-15
// attached: true/false
#define ATTACHED_HANGING_SIGN 65
// orientation 0-11
// crafting 0-1 (0x10)
// triggered 0-1 (0x20)
#define CRAFTER_PROP 66

#define NUM_TRANS 1015

Expand Down Expand Up @@ -1414,7 +1418,7 @@ BlockTranslator BlockTranslations[NUM_TRANS] = {
{ 0, 144, 0x80 | 6 << 4, "piglin_head", HEAD_PROP },
{ 0, 209, HIGH_BIT, "trial_spawner", NO_PROP },
{ 0, 210, HIGH_BIT, "vault", NO_PROP },
{ 0, 211, HIGH_BIT, "crafter", NO_PROP },
{ 0, 211, HIGH_BIT, "crafter", CRAFTER_PROP },

// 1.20.3 additions (short_grass added next to "grass", above), https://minecraft.wiki/w/Java_Edition_1.20.3#General_2

Expand Down Expand Up @@ -3242,17 +3246,17 @@ static int readPalette(int& returnCode, bfFile* pbf, int mcVersion, unsigned cha

// for doors
bool half, north, south, east, west, down, lit, powered, triggered, extended, attached, disarmed,
conditional, inverted, enabled, doubleSlab, mode, waterlogged, in_wall, signal_fire, has_book, up, hanging;
conditional, inverted, enabled, doubleSlab, mode, waterlogged, in_wall, signal_fire, has_book, up, hanging, crafting;
int axis, door_facing, hinge, open, face, rails, occupied, part, dropper_facing, eye, age,
delay, locked, sticky, hatch, leaves, single, attachment, honey_level, stairs, bites, tilt,
thickness, vertical_direction, berries, flower_amount;
thickness, vertical_direction, berries, flower_amount, orientation;
// to avoid Release build warning, but should always be set by code in practice
int typeIndex = 0;
half = north = south = east = west = down = lit = powered = triggered = extended = attached = disarmed
= conditional = inverted = enabled = doubleSlab = mode = in_wall = signal_fire = has_book = up = hanging = false; // waterlogged is always set false in loop
= conditional = inverted = enabled = doubleSlab = mode = in_wall = signal_fire = has_book = up = hanging = crafting = false; // waterlogged is always set false in loop
axis = door_facing = hinge = open = face = rails = occupied = part = dropper_facing = eye = age =
delay = locked = sticky = hatch = leaves = single = attachment = honey_level = stairs = bites = tilt =
thickness = vertical_direction = berries = flower_amount = 0;
thickness = vertical_direction = berries = flower_amount = orientation = 0;

// IMPORTANT: if any PROP field uses any of these:
// triggered, extended, sticky, enabled, conditional, open, powered, face, has_book, powered, attachment, lit, signal_fire, honey_level
Expand Down Expand Up @@ -3704,12 +3708,11 @@ static int readPalette(int& returnCode, bfFile* pbf, int mcVersion, unsigned cha
else if (strcmp(token, "part") == 0) {
part = (strcmp(value, "head") == 0) ? 8 : 0;
}
// dropper/dispenser
// dropper/dispenser and crafter
else if (strcmp(token, "triggered") == 0) {
// ignore, non-graphical
#ifndef GRAPHICAL_ONLY
// ignore, non-graphical for some things.
// matters for crafter
triggered = (strcmp(value, "true") == 0);
#endif
}
// END_PORTAL_PROP (really, the frame)
else if (strcmp(token, "eye") == 0) {
Expand Down Expand Up @@ -3835,43 +3838,56 @@ static int readPalette(int& returnCode, bfFile* pbf, int mcVersion, unsigned cha
else if (strcmp(token, "charges") == 0) {
dataVal = atoi(value);
}
// for jigsaw
// for jigsaw and crafter
else if (strcmp(token, "orientation") == 0) {
// orientation order: south, west, north, east; then up_ then down_
if (strcmp(value, "south_up") == 0) {
dropper_facing = 3;
orientation = 0;
}
else if (strcmp(value, "west_up") == 0) {
dropper_facing = 2;
orientation = 1;
}
else if (strcmp(value, "north_up") == 0) {
dropper_facing = 4;
orientation = 2;
}
else if (strcmp(value, "east_up") == 0) {
dropper_facing = 5;
orientation = 3;
}
else if (strcmp(value, "up_east") == 0) {
dropper_facing = 1 | BIT_16 | BIT_8;
orientation = 7;
}
else if (strcmp(value, "up_north") == 0) {
dropper_facing = 1 | BIT_16;
orientation = 6;
}
else if (strcmp(value, "up_west") == 0) {
dropper_facing = 1;
orientation = 5;
}
else if (strcmp(value, "up_south") == 0) {
dropper_facing = 1 | BIT_8;
orientation = 4;
}
else if (strcmp(value, "down_east") == 0) {
dropper_facing = 0 | BIT_16 | BIT_8;
orientation = 11;
}
else if (strcmp(value, "down_north") == 0) {
dropper_facing = 0 | BIT_16;
orientation = 10;
}
else if (strcmp(value, "down_west") == 0) {
dropper_facing = 0;
orientation = 9;
}
else if (strcmp(value, "down_south") == 0) {
dropper_facing = 0 | BIT_8;
orientation = 8;
}
else {
// unknown state found
Expand Down Expand Up @@ -4041,7 +4057,12 @@ static int readPalette(int& returnCode, bfFile* pbf, int mcVersion, unsigned cha
// cooldown and inactive are the same, ignore as 0x0 state
assert(0);
}
}
}

// for crafter
else if (strcmp(token, "crafting") == 0) {
crafting = (strcmp(value, "true") == 0) ? 1 : 0;
}

#ifdef _DEBUG
else {
Expand Down Expand Up @@ -4583,6 +4604,12 @@ static int readPalette(int& returnCode, bfFile* pbf, int mcVersion, unsigned cha
// south/west/north/east == 0/1/2/3
dataVal |= (attached ? BIT_16 : 0x0);
break;
case CRAFTER_PROP:
// for crafter
dataVal = orientation | (crafting ? BIT_16 : 0) | (triggered ? BIT_32 : 0);
// Normally we don't have to reset, as all of these properties get set for the crafter. Note that "triggered" is not graphical
// for the jigsaw that uses it. Does matter to the crafter.
break;
}

// make sure upper bits are not set - they should not be! Well, except for heads. So, comment out this test
Expand Down
Loading

0 comments on commit 0827cd6

Please sign in to comment.