| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859 |
- #pragma once
- #include <memory.h>
- #include <vector>
- #include <stdint.h>
- #include <glad/glad.h>
- #include <glm/vec3.hpp>
- constexpr static float BLOCK_DEFAULT_FRICTION = 8.f;
- enum BlockTypes : unsigned short
- {
- air = 0,
- grassBlock,
- dirt,
- stone,
- ice,
- woodLog,
- wooden_plank,
- cobblestone,
- gold_block,
- bricks,
- sand,
- sand_stone,
- snow_dirt,
- leaves,
- goldOre,
- copperOre,
- stoneBrick,
- ironOre,
- silverOre,
- bookShelf,
- birch_log,
- gravel,
- grass,
- rose,
- water,
- jungle_log,
- jungle_leaves,
- palm_log,
- palm_leaves,
- cactus_bud,
- dead_bush,
- jungle_planks,
- clay,
- clayBricks,
- mud,
- redClay,
- redClayBricks,
- control1,
- control2,
- control3,
- control4,
- snow_block,
- birch_leaves,
- spruce_log,
- spruce_leaves,
- spruce_leaves_red,
- glowstone,
- glass,
- testBlock,
- torch,
- leadOre,
- coarseDirt,
- birchPlanks,
- pathBlock,
- plankedWallBlock,
- plankedWallBlock_stairs,
- plankedWallBlock_wall,
- terracotta,
- terracotta_stairs,
- terracotta_slabs,
- terracotta_wall,
- glassNotClear,
- vitral1,
- vitral2,
- glassNotClear2,
- glass2,
- mossyCobblestone,
- magenta_stained_glass,
- pink_stained_glass,
- clothBlock,
- wooden_stairs,
- wooden_slab,
- wooden_wall,
- tiledStoneBricks,
- stone_stairts,
- stone_slabs,
- stone_wall,
- cobbleStone_stairts,
- cobbleStone_slabs,
- cobbleStone_wall,
- tiledStoneBricks_stairs,
- tiledStoneBricks_slab,
- tiledStoneBricks_wall,
- bricks_stairs,
- bricks_slabs,
- bricks_wall,
- stoneBricks_stairts,
- stoneBricks_slabs,
- stoneBricks_wall,
- structureBase,
- hardSandStone,
- hardSandStone_stairs,
- hardSandStone_slabs,
- hardSandStone_wall,
- sandStone_stairts,
- sandStone_slabs,
- sandStone_wall,
- dungeonBricks,
- dungeonBricks_stairts,
- dungeonBricks_slabs,
- dungeonBricks_wall,
- volcanicHotRock,
- volcanicRock,
- volcanicRock_stairts,
- volcanicRock_slabs,
- volcanicRock_wall,
- smoothStone,
- smoothStone_stairts,
- smoothStone_slabs,
- smoothStone_wall,
- limeStone,
- smoothLimeStone,
- smoothLimeStone_stairs,
- smoothLimeStone_slabs,
- smoothLimeStone_wall,
- marbleBlock,
- marbleBlock_stairs,
- marbleBlock_slabs,
- marbleBlock_wall,
- smoothMarbleBlock,
- marbleBricks,
- marbleBricks_stairs,
- marbleBricks_slabs,
- marbleBricks_wall,
- marblePillar,
- logWall,
- yellowGrass,
- blueBricks,
- blueBricks_stairs,
- blueBricks_slabs,
- blueBricks_wall,
- oakChair,
- oakLogChair,
- mug,
- goblet,
- wineBottle,
- skull,
- skullTorch,
- book,
- candleHolder,
- pot,
- jar,
- globe,
- keg,
- workBench,
- oakTable,
- oakLogTable,
- craftingItems,
- oakBigChair,
- oakLogBigChair,
- cookingPot,
- chickenCaracas,
- chickenWingsPlate,
- fishPlate,
- ladder,
- vines,
- cloth_stairs,
- cloth_slabs,
- cloth_wall,
- birchPlanks_stairs,
- birchPlanks_slabs,
- birchPlanks_wall,
- oakLogSlab,
- smallRock,
- strippedOakLog,
- strippedBirchLog,
- strippedSpruceLog,
- sprucePlank,
- sprucePlank_stairs,
- sprucePlank_slabs,
- sprucePlank_wall,
- dungeonStone,
- dungeonStone_stairs,
- dungeonStone_slabs,
- dungeonStone_wall,
-
- dungeonCobblestone,
- dungeonCobblestone_stairs,
- dungeonCobblestone_slabs,
- dungeonCobblestone_wall,
- dungeonSmoothStone,
- dungeonSmoothStone_stairs,
- dungeonSmoothStone_slabs,
- dungeonSmoothStone_wall,
- dungeonPillar,
- dungeonSkullBlock,
- chiseledDungeonBrick,
- dungeonGlass,
-
- woddenChest,
- goblinChest,
- copperChest,
- ironChest,
- silverChest,
- goldChest,
- crate,
- smallCrate,
- lamp,
- torchWood,
- mossyCobblestone_stairs,
- mossyCobblestone_slab,
- mossyCobblestone_wall,
- cobweb,
- hayBalde,
- trainingDummy,
- target,
- furnace,
- goblinWorkBench,
- goblinChair,
- goblinTable,
- goblinTorch,
- goblinStitchingPost,
- woodenFence,
- woodenLogFence,
- spruceFence,
- spruceLogFence,
- birchFence,
- birchLogFence,
- BlocksCount
- };
- int getBlockReorder(int index);
- using BlockType = uint16_t;
- //todo look into this
- bool isBlockMesh(BlockType type);
- bool canWallMountedBlocksBePlacedOn(BlockType type);
- bool isStairsMesh(BlockType type);
- bool isSlabMesh(BlockType type);
- bool isWallMesh(BlockType type);
- bool isCrossMesh(BlockType type);
- bool isControlBlock(BlockType type);
- bool isWallMountedBlock(BlockType type);
- bool isWallMountedOrStangingBlock(BlockType type);
- bool isOpaque(BlockType type);
- bool isDecorativeFurniture(BlockType type);
- bool isLightEmitor(BlockType type);
- bool isTransparentGeometry(BlockType type);
- bool isGrassMesh(BlockType type);
- bool isColidable(BlockType type);
- bool isWoodPlank(BlockType type);
- bool isChairMesh(BlockType type);
- bool isGobletMesh(BlockType type);
- //used for breaking
- bool isAnyWoddenBlock(BlockType type);
- bool isBricksSound(BlockType type);
- bool isVolcanicActiveSound(BlockType type);
- bool isVolcanicInActiveSound(BlockType type);
- bool isFenceConnectorBlock(std::uint16_t type);
- bool isAnyWoddenLOG(BlockType type);
- //used for breaking, cloth blocks
- bool isAnyWool(BlockType type);
- //used for breaking
- bool isAnyDirtBlock(BlockType type);
- //used for breaking
- bool isAnyClayBlock(BlockType type);
- //used for breaking
- bool isAnySandyBlock(BlockType type);
- //used for breaking
- bool isAnySemiHardBlock(BlockType type);
- //used for breaking
- bool isAnyStone(BlockType type);
- bool isChest(BlockType type);
- //block transitions
- bool canHaveDecals(BlockType type);
- //used for breaking
- bool isDungeonBrick(BlockType type);
- //used for breaking
- bool isAnyPlant(BlockType type);
- //used for breaking
- bool isAnyGlass(BlockType type);
- //used for breaking
- bool isTriviallyBreakable(BlockType type);
- //used for breaking, bedrock type blocks, that can be breaked in creative!
- bool isAnyUnbreakable(BlockType type);
- //used for sound
- bool isAnyHotSoundingBlock(BlockType type);
- //used for breaking
- bool isAnyLeaves(BlockType type);
- bool isStainedGlass(BlockType type);
- unsigned char isInteractable(BlockType type);
- bool isBlock(std::uint16_t type);
- bool noRotationForFurniture(std::uint16_t type);
- bool isFenceMesh(std::uint16_t type);
- bool canBeMinedByHand(std::uint16_t type);
- bool canBeMinedByPickaxe(std::uint16_t type);
- bool canBeMinedByShovel(std::uint16_t type);
- bool canBeMinedByAxe(std::uint16_t type);
- int isCraftingStation(unsigned short type);
- BlockType fromAnyShapeToNormalBlockType(BlockType b);
- //true for standing on wall!
- unsigned char getRotatedOrStandingForWallOrStandingBlocks(BlockType b);
- struct BlockCollider
- {
- glm::vec3 size = {1,1,1};
- glm::vec3 offset = {};
- };
- enum WorkStationType
- {
- WorkStationType_None = 0,
- WorkStationType_WorkBench,
- WorkStationType_Furnace,
- WorkStationType_CookingPot,
- WorkStationType_Anvil,
- WorkStationType_GoblinStitchingPost,
- //DONT FORGET TO ALSO UPDATE TOWARDS THE BOTTOM OF THE FILE
- };
- namespace BlockColor
- {
- enum
- {
- none,
- white,
- lightGray,
- darkGrayP,
- black,
- brown,
- red,
- orange,
- yellow,
- lime,
- green,
- turqoise,
- cyan,
- blue,
- purple,
- magenta,
- pink,
- };
- };
- struct Block
- {
- BlockType typeAndFlags = 0;
- unsigned char lightLevel = 0; //first 4 bytes represent the sun level and bottom 4 bytes the other lights level
- unsigned char colorAndOtherFlags = 0;
- bool operator==(const Block &other)
- {
- return typeAndFlags == other.typeAndFlags && lightLevel == other.lightLevel &&
- colorAndOtherFlags == other.colorAndOtherFlags;
- };
- unsigned short getColor()
- {
- return colorAndOtherFlags & 0b0001'1111;
- }
- void setColor(unsigned short color)
- {
- if (color >= 32) { color = 31; }
- colorAndOtherFlags &= 0b1110'0000;
- colorAndOtherFlags |= color;
- }
- bool normalize();
- BlockType getType()
- {
- return typeAndFlags & 0b0111'1111'1111;
- }
- unsigned char getFlagsBytes()
- {
- return typeAndFlags >> 11;
- }
- //used for stairs, or furniture type blocks
- unsigned char getRotationFor365RotationTypeBlocks()
- {
- return (typeAndFlags >> 11) & 0b0001'1;
- }
- //true for standing on wall!
- unsigned char getRotatedOrStandingForWallOrStandingBlocks()
- {
- return ::getRotatedOrStandingForWallOrStandingBlocks(typeAndFlags);
- }
- void setRotatedOrStandingForWallOrStandingBlocks(bool isOnWall)
- {
- unsigned int is = isOnWall;
- is <<= 13;
- typeAndFlags &= 0b1101'1111'1111'1111;
- typeAndFlags |= is;
- }
- void setRotationFor365RotationTypeBlocks(int rotation)
- {
- rotation <<= 11;
- typeAndFlags &= 0b1110'0111'1111'1111;
- typeAndFlags |= rotation;
- }
- void setTopPartForSlabs(int topPart)
- {
- topPart = (bool)topPart;
- topPart <<= 11;
- typeAndFlags &= 0b1111'0111'1111'1111;
- typeAndFlags |= topPart;
- }
- void rotate(int rotation)
- {
- if (rotation == 0)
- {
- return;
- }
- assert(rotation <= 3);
- if (hasRotationFor365RotationTypeBlocks() && !noRotationForFurniture())
- {
- if (!isWallMountedOrStangingBlock()
- ||
- getRotatedOrStandingForWallOrStandingBlocks()
- )
- {
- int r = getRotationFor365RotationTypeBlocks();
- setRotationFor365RotationTypeBlocks((r + rotation) % 4);
- }
- }
- }
- bool getTopPartForSlabs()
- {
- return (typeAndFlags >> 11) & 0b0000'1;
- }
- bool isDecorativeFurniture()
- {
- auto type = getType();
- return ::isDecorativeFurniture(getType());
- }
- //used for stairs, or furniture type blocks
- bool hasRotationFor365RotationTypeBlocks()
- {
- return isStairsMesh() || isWallMesh() || isDecorativeFurniture() || isWallMountedBlock()
- || isWallMountedOrStangingBlock();
- }
- bool noRotationForFurniture()
- {
- return ::noRotationForFurniture(getType());
- }
- void setType(BlockType t)
- {
- typeAndFlags = t & 0b0111'1111'1111;
- }
- bool air() { return getType() == 0; }
- bool canBePainted() { return getType() != 0; }
- bool isOpaque()
- {
- return ::isOpaque(getType());
- }
- bool isWallMountedBlock()
- {
- return ::isWallMountedBlock(getType());
- }
- bool isWallMountedOrStangingBlock()
- {
- return::isWallMountedOrStangingBlock(getType());
- }
- bool isFenceMesh()
- {
- return ::isFenceMesh(getType());
- }
- bool isChest()
- {
- return ::isChest(getType());
- }
- bool canHaveDecals()
- {
- return ::canHaveDecals(getType());
- }
- bool hasSecondCollider()
- {
- return isStairsMesh();
- }
- bool isFenceConnectorBlock()
- {
- return ::isFenceConnectorBlock(getType());
- }
- BlockCollider getCollider()
- {
- if (isChairMesh())
- {
- BlockCollider b{};
- b.size.y = 0.5;
- b.size.x = 0.8;
- b.size.z = 0.8;
- return b;
- }else
- if (isStairsMesh())
- {
- BlockCollider b{};
- b.size.y = 0.5;
- return b;
- }else
- if (isSlabMesh())
- {
- if (getTopPartForSlabs())
- {
- BlockCollider b{};
- b.size.y = 0.5;
- b.offset.y = 0.5;
- return b;
- }
- else
- {
- BlockCollider b{};
- b.size.y = 0.5;
- return b;
- }
- }else
- if (isWallMesh())
- {
- int rotation = getRotationFor365RotationTypeBlocks();
- if (rotation == 0)
- {
- BlockCollider b{};
- b.size.z = 0.5;
- b.offset.z = -0.25;
- return b;
- }
- else if (rotation == 2)
- {
- BlockCollider b{};
- b.size.z = 0.5;
- b.offset.z = 0.25;
- return b;
- }
- else if (rotation == 1)
- {
- BlockCollider b{};
- b.size.x = 0.5;
- b.offset.x = -0.25;
- return b;
- }
- else if (rotation == 3)
- {
- BlockCollider b{};
- b.size.x = 0.5;
- b.offset.x = 0.25;
- return b;
- }
- }
- else if (isFenceMesh())
- {
- BlockCollider b{};
- b.size.x = 1.f * (4.f / 16.f);
- b.size.z = 1.f * (4.f / 16.f);
- return b;
- }
- auto type = getType();
- auto sizeInPixels = [&](float pixels)
- {
- return (pixels / 16.f);
- };
- if (type == BlockTypes::trainingDummy)
- {
- BlockCollider b{};
- b.size.x = sizeInPixels(14);
- b.size.z = b.size.x;
- b.size.y = sizeInPixels(1);
- return b;
- }
- return BlockCollider{};
- }
- BlockCollider getSecondCollider()
- {
- if (isStairsMesh())
- {
- int rotation = getRotationFor365RotationTypeBlocks();
- if (rotation == 0)
- {
- BlockCollider b{};
- b.size.z = 0.5;
- b.offset.z = -0.25;
- return b;
- }
- else if (rotation == 2)
- {
- BlockCollider b{};
- b.size.z = 0.5;
- b.offset.z = 0.25;
- return b;
- }
- else if (rotation == 1)
- {
- BlockCollider b{};
- b.size.x = 0.5;
- b.offset.x = -0.25;
- return b;
- }
- else if (rotation == 3)
- {
- BlockCollider b{};
- b.size.x = 0.5;
- b.offset.x = 0.25;
- return b;
- }
- }
- BlockCollider b;
- b.size = {};
- return b;
- }
- //rename is animated leaves
- bool isAnimatedBlock()
- {
- auto type = getType();
- return
- type == BlockTypes::leaves || type == BlockTypes::jungle_leaves
- || type == BlockTypes::palm_leaves || type == BlockTypes::birch_leaves
- || type == BlockTypes::spruce_leaves || type == BlockTypes::spruce_leaves_red;
- }
- bool isTransparentGeometry()
- {
- return ::isTransparentGeometry(getType());
- }
- bool isStairsMesh()
- {
- return ::isStairsMesh(getType());
- }
- bool isChairMesh()
- {
- return ::isChairMesh(getType());
- }
- bool isGobletMesh()
- {
- return ::isGobletMesh(getType());
- }
- bool isWallMesh()
- {
- return ::isWallMesh(getType());
- }
- bool isSlabMesh()
- {
- return ::isSlabMesh(getType());
- }
- bool isGrassMesh()
- {
- return ::isGrassMesh(getType());
- }
- bool isLightEmitor()
- {
- return ::isLightEmitor(getType());
- }
- unsigned char getSkyLight()
- {
- return (lightLevel >> 4);
- }
- unsigned char getLight()
- {
- return lightLevel & 0b1111;
- }
- void setSkyLevel(unsigned char s)
- {
- s = s & 0b1111;
- s <<= 4;
- lightLevel &= 0b0000'1111;
- lightLevel |= s;
- }
- void setLightLevel(unsigned char l)
- {
- l = l & 0b1111;
- lightLevel &= 0b1111'0000;
- lightLevel |= l;
- }
- bool canWallMountedBlocksBePlacedOn()
- {
- return ::canWallMountedBlocksBePlacedOn(getType());
- }
- bool isBlockMesh()
- {
- return ::isBlockMesh(getType());
- }
- //todo, investigate where it this used and implement it corectly, and remove the grass mesh component if so
- bool isCrossMesh()
- {
- return ::isCrossMesh(getType());
- }
- bool isColidable()
- {
- return ::isColidable(getType());
- }
- bool stopsGrassFromGrowingIfOnTop()
- {
- return isColidable() && !isAnyLeaves(getType())
- && !isWallMesh() && !(isSlabMesh() && getTopPartForSlabs())
- && !isDecorativeFurniture()
- ;
- }
- float getFriction();
- };
- namespace InteractionTypes
- {
- enum
- {
- none = 0,
- craftingTable,
- furnace,
- cookingPot,
- anvil,
- goblinStitchingPost, //add other work stations here v...
- structureBaseBlock,
- chestInteraction,
- };
- };
- float getBlockBaseMineDuration(BlockType type);
|