]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_mapblock.h
Don't try to craft a non-existent item
[dragonfireclient.git] / src / content_mapblock.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "nodedef.h"
23 #include <IMeshManipulator.h>
24
25 struct MeshMakeData;
26 struct MeshCollector;
27
28 struct LightFrame
29 {
30         f32 lightsA[8];
31         f32 lightsB[8];
32 };
33
34 class MapblockMeshGenerator
35 {
36 public:
37         MeshMakeData *data;
38         MeshCollector *collector;
39
40         INodeDefManager *nodedef;
41         scene::IMeshManipulator *meshmanip;
42
43 // options
44         bool enable_mesh_cache;
45
46 // current node
47         v3s16 blockpos_nodes;
48         v3s16 p;
49         v3f origin;
50         MapNode n;
51         const ContentFeatures *f;
52         u16 light;
53         LightFrame frame;
54         video::SColor color;
55         TileSpec tile;
56         float scale;
57
58 // lighting
59         void getSmoothLightFrame();
60         u16 blendLight(const v3f &vertex_pos);
61         video::SColor blendLightColor(const v3f &vertex_pos);
62         video::SColor blendLightColor(const v3f &vertex_pos, const v3f &vertex_normal);
63
64         void useTile(int index = 0, u8 set_flags = MATERIAL_FLAG_CRACK_OVERLAY,
65                 u8 reset_flags = 0, bool special = false);
66         void getTile(int index, TileSpec *tile);
67         void getTile(v3s16 direction, TileSpec *tile);
68         void getSpecialTile(int index, TileSpec *tile, bool apply_crack = false);
69
70 // face drawing
71         void drawQuad(v3f *vertices, const v3s16 &normal = v3s16(0, 0, 0),
72                 float vertical_tiling = 1.0);
73
74 // cuboid drawing!
75         void drawCuboid(const aabb3f &box, TileSpec *tiles, int tilecount,
76                 const u16 *lights , const f32 *txc);
77         void generateCuboidTextureCoords(aabb3f const &box, f32 *coords);
78         void drawAutoLightedCuboid(aabb3f box, const f32 *txc = NULL,
79                 TileSpec *tiles = NULL, int tile_count = 0);
80
81 // liquid-specific
82         bool top_is_same_liquid;
83         TileSpec tile_liquid;
84         TileSpec tile_liquid_top;
85         content_t c_flowing;
86         content_t c_source;
87         video::SColor color_liquid_top;
88         struct NeighborData {
89                 f32 level;
90                 content_t content;
91                 bool is_same_liquid;
92                 bool top_is_same_liquid;
93         };
94         NeighborData liquid_neighbors[3][3];
95         f32 corner_levels[2][2];
96
97         void prepareLiquidNodeDrawing();
98         void getLiquidNeighborhood();
99         void calculateCornerLevels();
100         f32 getCornerLevel(int i, int k);
101         void drawLiquidSides();
102         void drawLiquidTop();
103
104 // raillike-specific
105         // name of the group that enables connecting to raillike nodes of different kind
106         static const std::string raillike_groupname;
107         int raillike_group;
108         bool isSameRail(v3s16 dir);
109
110 // plantlike-specific
111         PlantlikeStyle draw_style;
112         v3f offset;
113         int rotate_degree;
114         bool random_offset_Y;
115         int face_num;
116         float plant_height;
117
118         void drawPlantlikeQuad(float rotation, float quad_offset = 0,
119                 bool offset_top_only = false);
120         void drawPlantlike();
121
122 // firelike-specific
123         void drawFirelikeQuad(float rotation, float opening_angle,
124                 float offset_h, float offset_v = 0.0);
125
126 // drawtypes
127         void drawLiquidNode();
128         void drawGlasslikeNode();
129         void drawGlasslikeFramedNode();
130         void drawAllfacesNode();
131         void drawTorchlikeNode();
132         void drawSignlikeNode();
133         void drawPlantlikeNode();
134         void drawPlantlikeRootedNode();
135         void drawFirelikeNode();
136         void drawFencelikeNode();
137         void drawRaillikeNode();
138         void drawNodeboxNode();
139         void drawMeshNode();
140
141 // common
142         void errorUnknownDrawtype();
143         void drawNode();
144
145 public:
146         MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
147         void generate();
148 };