Fixed handling of inventory in creative mode (normal inventory is not trashed anymore...
authorPerttu Ahola <celeron55@gmail.com>
Sat, 30 Jul 2011 20:33:57 +0000 (23:33 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 30 Jul 2011 20:33:57 +0000 (23:33 +0300)
13 files changed:
data/cooked_rat.png [new file with mode: 0644]
data/nc_back.png [new file with mode: 0644]
data/nc_front.png [new file with mode: 0644]
data/nc_rb.png [new file with mode: 0644]
data/nc_side.png [new file with mode: 0644]
data/scorched_stuff.png [new file with mode: 0644]
src/content_mapnode.cpp
src/content_mapnode.h
src/mapgen.cpp
src/mapnode.h
src/player.cpp
src/player.h
src/server.cpp

diff --git a/data/cooked_rat.png b/data/cooked_rat.png
new file mode 100644 (file)
index 0000000..daad3be
Binary files /dev/null and b/data/cooked_rat.png differ
diff --git a/data/nc_back.png b/data/nc_back.png
new file mode 100644 (file)
index 0000000..f09f416
Binary files /dev/null and b/data/nc_back.png differ
diff --git a/data/nc_front.png b/data/nc_front.png
new file mode 100644 (file)
index 0000000..cad9eda
Binary files /dev/null and b/data/nc_front.png differ
diff --git a/data/nc_rb.png b/data/nc_rb.png
new file mode 100644 (file)
index 0000000..7ebc993
Binary files /dev/null and b/data/nc_rb.png differ
diff --git a/data/nc_side.png b/data/nc_side.png
new file mode 100644 (file)
index 0000000..f954045
Binary files /dev/null and b/data/nc_side.png differ
diff --git a/data/scorched_stuff.png b/data/scorched_stuff.png
new file mode 100644 (file)
index 0000000..9ced2fb
Binary files /dev/null and b/data/scorched_stuff.png differ
index db036ebd9a6c9a43e7462a635ee739a66bfd7141..b6b7a6e53a68c2f7fe1d5d8389d10f659870f3f4 100644 (file)
@@ -474,13 +474,30 @@ void content_mapnode_init()
        f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
        setStoneLikeDiggingProperties(f->digging_properties, 5.0);
        
+       i = CONTENT_NC;
+       f = &content_features(i);
+       f->param_type = CPT_FACEDIR_SIMPLE;
+       f->setAllTextures("nc_side.png");
+       f->setTexture(5, "nc_front.png"); // Z-
+       f->setTexture(4, "nc_back.png"); // Z+
+       f->setInventoryTexture("nc_front.png");
+       f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
+       setStoneLikeDiggingProperties(f->digging_properties, 3.0);
+       
+       i = CONTENT_NC_RB;
+       f = &content_features(i);
+       f->setAllTextures("nc_rb.png");
+       f->setInventoryTexture("nc_rb.png");
+       f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
+       setStoneLikeDiggingProperties(f->digging_properties, 3.0);
+       
        // NOTE: Remember to add frequently used stuff to the texture atlas in tile.cpp
        
 
        /*
                Add MesePick to everything
        */
-       for(u16 i=0; i<256; i++)
+       for(u16 i=0; i<=MAX_CONTENT; i++)
        {
                content_features(i).digging_properties.set("MesePick",
                                DiggingProperties(true, 0.0, 65535./1337));
index 5fdbf45f371e58dcc2ba42939b9c711505b23306..7be26518fc21470919c6f7db8c27b42d05fa7169 100644 (file)
@@ -70,6 +70,8 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version);
 #define CONTENT_BOOKSHELF 0x814 //29
 #define CONTENT_JUNGLETREE 0x815
 #define CONTENT_JUNGLEGRASS 0x816
+#define CONTENT_NC 0x817
+#define CONTENT_NC_RB 0x818
 
 
 #endif
index 0ba7f91abadb9d71178f0ed4bab29f84b04e553b..5dec7d843b4dc031c9c1048129f5f23058f79c86 100644 (file)
@@ -976,6 +976,40 @@ static void make_dungeon1(VoxelManipulator &vmanip, PseudoRandom &random)
        }
 }
 
+static void make_nc(VoxelManipulator &vmanip, PseudoRandom &random)
+{
+       v3s16 dir;
+       u8 facedir_i = 0;
+       s32 r = random.range(0, 3);
+       if(r == 0){
+               dir = v3s16( 1, 0, 0);
+               facedir_i = 3;
+       }
+       if(r == 1){
+               dir = v3s16(-1, 0, 0);
+               facedir_i = 1;
+       }
+       if(r == 2){
+               dir = v3s16( 0, 0, 1);
+               facedir_i = 2;
+       }
+       if(r == 3){
+               dir = v3s16( 0, 0,-1);
+               facedir_i = 0;
+       }
+       v3s16 p = vmanip.m_area.MinEdge + v3s16(
+                       16+random.range(0,15),
+                       16+random.range(0,15),
+                       16+random.range(0,15));
+       vmanip.m_data[vmanip.m_area.index(p)] = MapNode(CONTENT_NC, facedir_i);
+       u32 length = random.range(3,15);
+       for(u32 j=0; j<length; j++)
+       {
+               p -= dir;
+               vmanip.m_data[vmanip.m_area.index(p)] = MapNode(CONTENT_NC_RB);
+       }
+}
+
 /*
        Noise functions. Make sure seed is mangled differently in each one.
 */
@@ -1871,6 +1905,17 @@ void make_block(BlockMakeData *data)
                        }
                }
        }
+
+       /*
+               Add NC
+       */
+       {
+               PseudoRandom ncrandom(blockseed+9324342);
+               if(ncrandom.range(0, 1000) == 0 && blockpos.Y <= -3)
+               {
+                       make_nc(vmanip, ncrandom);
+               }
+       }
        
        /*
                Add top and bottom side of water to transforming_liquid queue
index 956de6852d8cbb688c3b4e2ad209e4b91f3a8f03..aeb72c97aca9d7b9ec498947793d6b57d45d9b10 100644 (file)
@@ -391,6 +391,9 @@ inline v3s16 unpackDir(u8 b)
        facedir: CPT_FACEDIR_SIMPLE param1 value
        dir: The face for which stuff is wanted
        return value: The face from which the stuff is actually found
+
+       NOTE: Currently this uses 2 bits for Z-,X-,Z+,X+, should there be Y+
+             and Y- too?
 */
 v3s16 facedir_rotate(u8 facedir, v3s16 dir);
 
index d52d6b88f032937505e4de950e7576739f2c4b2e..c43276ef132db71f8dbc1766953ef674ea8cd585 100644 (file)
@@ -29,6 +29,7 @@ Player::Player():
        in_water(false),
        in_water_stable(false),
        swimming_up(false),
+       inventory_backup(NULL),
        craftresult_is_preview(true),
        hp(20),
        peer_id(PEER_ID_INEXISTENT),
@@ -43,6 +44,7 @@ Player::Player():
 
 Player::~Player()
 {
+       delete inventory_backup;
 }
 
 void Player::resetInventory()
@@ -106,8 +108,13 @@ void Player::serialize(std::ostream &os)
        args.writeLines(os);
 
        os<<"PlayerArgsEnd\n";
-
-       inventory.serialize(os);
+       
+       // If actual inventory is backed up due to creative mode, save it
+       // instead of the dummy creative mode inventory
+       if(inventory_backup)
+               inventory_backup->serialize(os);
+       else
+               inventory.serialize(os);
 }
 
 void Player::deSerialize(std::istream &is)
index a7a2433ce3d52f10f461c7d349f921958d703e46..29460e1e1e7323ad7a554371b8774af97515df46 100644 (file)
@@ -121,6 +121,8 @@ public:
        bool swimming_up;
        
        Inventory inventory;
+       // Actual inventory is backed up here when creative mode is used
+       Inventory *inventory_backup;
 
        bool craftresult_is_preview;
 
index 07f9875c41f911006c825a750ef3d1ec8897a900..503d60b845996bfd76948b585364217a6e90b046 100644 (file)
@@ -4130,6 +4130,11 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
                // Reset inventory to creative if in creative mode
                if(g_settings.getBool("creative_mode"))
                {
+                       // Warning: double code below
+                       // Backup actual inventory
+                       player->inventory_backup = new Inventory();
+                       *(player->inventory_backup) = player->inventory;
+                       // Set creative inventory
                        craft_set_creative_inventory(player);
                }
 
@@ -4183,6 +4188,11 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
                
                if(g_settings.getBool("creative_mode"))
                {
+                       // Warning: double code above
+                       // Backup actual inventory
+                       player->inventory_backup = new Inventory();
+                       *(player->inventory_backup) = player->inventory;
+                       // Set creative inventory
                        craft_set_creative_inventory(player);
                }
                else if(g_settings.getBool("give_initial_stuff"))