]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/itemdef.cpp
Add a callback: minetest.register_on_craft(itemstack, player,
[dragonfireclient.git] / src / itemdef.cpp
index e7498ce55de580dbd4fcb7f95d717c01457284b8..83a70f1d7c368fdc45cb0397732425a2687e1456 100644 (file)
@@ -76,6 +76,7 @@ ItemDefinition& ItemDefinition::operator=(const ItemDefinition &def)
        groups = def.groups;
        node_placement_prediction = def.node_placement_prediction;
        sound_place = def.sound_place;
+       range = def.range;
        return *this;
 }
 
@@ -109,6 +110,7 @@ void ItemDefinition::reset()
        }
        groups.clear();
        sound_place = SimpleSoundSpec();
+       range = -1;
 
        node_placement_prediction = "";
 }
@@ -117,8 +119,10 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
 {
        if(protocol_version <= 17)
                writeU8(os, 1); // version
-       else
+       else if(protocol_version <= 20)
                writeU8(os, 2); // version
+       else
+               writeU8(os, 3); // version
        writeU8(os, type);
        os<<serializeString(name);
        os<<serializeString(description);
@@ -147,6 +151,9 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
                os<<serializeString(sound_place.name);
                writeF1000(os, sound_place.gain);
        }
+       if(protocol_version > 20){
+               writeF1000(os, range);
+       }
 }
 
 void ItemDefinition::deSerialize(std::istream &is)
@@ -156,7 +163,7 @@ void ItemDefinition::deSerialize(std::istream &is)
 
        // Deserialize
        int version = readU8(is);
-       if(version != 1 && version != 2)
+       if(version < 1 || version > 3)
                throw SerializationError("unsupported ItemDefinition version");
        type = (enum ItemType)readU8(is);
        name = deSerializeString(is);
@@ -189,16 +196,18 @@ void ItemDefinition::deSerialize(std::istream &is)
                // Set the old default sound
                sound_place.name = "default_place_node";
                sound_place.gain = 0.5;
-       } else if(version == 2) {
+       } else if(version >= 2) {
                node_placement_prediction = deSerializeString(is);
                //deserializeSimpleSoundSpec(sound_place, is);
                sound_place.name = deSerializeString(is);
                sound_place.gain = readF1000(is);
        }
+       if(version == 3) {
+               range = readF1000(is);
+       }
        // If you add anything here, insert it primarily inside the try-catch
        // block to not need to increase the version.
        try{
-               
        }catch(SerializationError &e) {};
 }