Browse Source

fix crash when a growing plant finished growing

Kolja Strohm 1 day ago
parent
commit
5c2d6567cd

+ 16 - 7
FactoryCraft/GrowingPlant.cpp

@@ -111,12 +111,13 @@ TickSourceType GrowingPlantBlock::isTickSource() const
     return TickSourceType::EACH_TICK;
 }
 
-Framework::Text GrowingPlantBlock::getTargetUIML()
+Framework::XML::Element* GrowingPlantBlock::getTargetUIML() const
 {
-    return Framework::Text("<targetInfo><text width=\"auto\" height=\"auto\">")
-         + name + "\n" + "Growth: "
-         + Framework::Text((int)(seblingTicks / (float)seblingTicksMax * 100.f))
-         + "%</text></targetInfo>";
+    return new Framework::XML::Element(
+        Framework::Text("<targetInfo><text width=\"auto\" height=\"auto\">")
+        + name + "\n" + "Growth: "
+        + Framework::Text((int)(seblingTicks / (float)seblingTicksMax * 100.f))
+        + "%</text></targetInfo>");
 }
 
 GrowingPlantBlock* GrowingPlantBlock::addGrowthState(GrowthState* state)
@@ -270,8 +271,16 @@ const Framework::RCArray<GrowthState>& GrowingPlantBlockType::getStates() const
 }
 
 void GrowingPlantBlockType::setBlockTypeNameAfterGrowth(
-    Framework::Text blockTypeIdAfterGrowth)
-{}
+    Framework::Text blockTypeNameAfterGrowth)
+{
+    this->blockTypeNameAfterGrowth = blockTypeNameAfterGrowth;
+}
+
+bool GrowingPlantBlockType::initialize(Game* zGame)
+{
+    blockTypeIdAfterGrowth = zGame->getBlockTypeId(blockTypeNameAfterGrowth);
+    return blockTypeIdAfterGrowth >= 0 && BlockType::initialize(zGame);
+}
 
 ItemType* GrowingPlantBlockType::createItemType() const
 {

+ 2 - 1
FactoryCraft/GrowingPlant.h

@@ -41,7 +41,7 @@ public:
     virtual void onPostTick() override;
     virtual void sendModelInfo(NetworkMessage* zMessage) override;
     virtual TickSourceType isTickSource() const override;
-    virtual Framework::Text getTargetUIML();
+    virtual Framework::XML::Element* getTargetUIML() const override;
     GrowingPlantBlock* addGrowthState(GrowthState* state);
 
     friend GrowingPlantBlockType;
@@ -75,6 +75,7 @@ protected:
         Framework::Vec3<int> position, int dimensionId) const override;
 
 public:
+    virtual bool initialize(Game* zGame) override;
     virtual ItemType* createItemType() const override;
 
     GrowingPlantBlockType* addGrowthState(

+ 1 - 1
FactoryCraft/ItemSlot.cpp

@@ -84,7 +84,7 @@ int ItemSlot::numberOfAddableItems(const Item* zItem, Direction dir) const
 {
     if ((dir | allowedPushSides) == allowedPushSides)
     {
-        if (!items)
+        if (!items || !items->zItem())
         {
             if (allowHigherStackSize)
                 return maxSize;

+ 2 - 2
Windows Version/data/blocks/plants.json

@@ -189,7 +189,7 @@
                     "chance": 0.7
                 },
                 "amount": 1,
-                "itemType": "CottonSeeds"
+                "itemType": "Cotton Seeds"
             },
             {
                 "type": "specificItem",
@@ -198,7 +198,7 @@
                     "chance": 0.4
                 },
                 "amount": 1,
-                "itemType": "CottonSeeds"
+                "itemType": "Cotton Seeds"
             }
         ]
     }

+ 26 - 0
Windows Version/data/items/itemTypes.json

@@ -236,6 +236,32 @@
       }
     }
   },
+  {
+    "type": "placeable",
+    "name": "Cotton Seeds",
+    "model": {
+      "modelPath": "grass",
+      "texturePaths": [
+        "plants.ltdb/cottonseeds.png"
+      ],
+      "transparent": true
+    },
+    "hardness": 0.1,
+    "transparent": true,
+    "passable": true,
+    "speedModifier": 0.5,
+    "blockType": "CottonSeeds",
+    "placeableProof": {
+      "type": "blockFilter",
+      "direction": "bottom",
+      "filter": {
+        "type": "types",
+        "typeNames": [
+          "Farmland"
+        ]
+      }
+    }
+  },
   {
     "type": "basic",
     "name": "Tree bark",