浏览代码

add loose stones lying arround on gravel

Kolja Strohm 1 月之前
父节点
当前提交
39f457b079

+ 64 - 6
FactoryCraft/JsonExpression.cpp

@@ -1244,7 +1244,8 @@ const char* JSpecificBlockBoolExpressionFactory::getTypeToken() const
 
 JFirstBlockAboveBoolExpression::JFirstBlockAboveBoolExpression()
     : JBoolExpression(),
-      filter(0)
+      filter(0),
+      maxDistance(0)
 {}
 
 JFirstBlockAboveBoolExpression::~JFirstBlockAboveBoolExpression()
@@ -1282,18 +1283,44 @@ JFirstBlockAboveBoolExpression::buildAssembly(JExpressionMemory* zMemory)
     // load current chunk into R15
     codeBlock.addLoadValue(
         (__int64*)zMemory->zzCurrentChunk(), Framework::Assembly::R15);
+    if (maxDistance)
+    {
+        // calculate loop end
+        codeBlock.addMoveValue(
+            Framework::Assembly::RBX, Framework::Assembly::R14);
+        codeBlock.addAddition(Framework::Assembly::RBX, maxDistance + 1);
+        codeBlock.addCompare(Framework::Assembly::RBX, WORLD_HEIGHT);
+        codeBlock.addJump(Framework::Assembly::JL, "continue");
+        codeBlock.addMoveValue(Framework::Assembly::RBX, WORLD_HEIGHT);
+        codeBlock.defineJumpTarget("continue");
+    }
     // begin loop to check above blocks
     codeBlock.defineJumpTarget("loop_start");
     // increment height
-    codeBlock.addAddition(Framework::Assembly::R14, (char)1);
-    // check if height is above world height
-    codeBlock.addCompare(Framework::Assembly::R14, WORLD_HEIGHT);
+    codeBlock.addAddition(
+        Framework::Assembly::R14, (char)1, Framework::Assembly::LOWER32);
+    // check if height is above loop end
+    if (maxDistance)
+    {
+        codeBlock.addCompare(Framework::Assembly::R14,
+            Framework::Assembly::RBX,
+            Framework::Assembly::LOWER32);
+    }
+    else
+    {
+        codeBlock.addCompare(Framework::Assembly::R14, WORLD_HEIGHT);
+    }
     codeBlock.addJump(Framework::Assembly::JGE, "end_false");
     // load block type at current position into RAX
     codeBlock.addMoveValue(Framework::Assembly::RCX, Framework::Assembly::R15);
     codeBlock.addMoveValue(Framework::Assembly::RDX, Framework::Assembly::R12);
     codeBlock.addMoveValue(Framework::Assembly::R8, Framework::Assembly::R13);
     codeBlock.addMoveValue(Framework::Assembly::R9, Framework::Assembly::R14);
+    if (maxDistance)
+    { // save loop end in RBX for later comparison
+        codeBlock.addPush(
+            Framework::Assembly::RBX, Framework::Assembly::LOWER32);
+    }
     codeBlock.addMemberCall<int (Chunk::*)(int, int, int) const>(
         &Chunk::getBlockTypeAtWC,
         Framework::Assembly::INT_VALUE,
@@ -1302,6 +1329,12 @@ JFirstBlockAboveBoolExpression::buildAssembly(JExpressionMemory* zMemory)
             Framework::Assembly::R8,
             Framework::Assembly::R9},
         {});
+    if (maxDistance)
+    {
+        // restore loop end from stack
+        codeBlock.addPop(
+            Framework::Assembly::RBX, Framework::Assembly::LOWER32);
+    }
     // check if block type is 0 (NO_BLOCK) or 1 (AIR)
     codeBlock.addCompare(Framework::Assembly::RAX, 1);
     codeBlock.addJump(Framework::Assembly::JLE, "loop_start");
@@ -1349,6 +1382,16 @@ BlockFilter* JFirstBlockAboveBoolExpression::zFilter() const
     return filter;
 }
 
+void JFirstBlockAboveBoolExpression::setMaxDistance(short maxDistance)
+{
+    this->maxDistance = maxDistance;
+}
+
+short JFirstBlockAboveBoolExpression::getMaxDistance() const
+{
+    return maxDistance;
+}
+
 JFirstBlockAboveBoolExpressionFactory::JFirstBlockAboveBoolExpressionFactory()
     : SubTypeFactory()
 {}
@@ -1360,6 +1403,11 @@ JFirstBlockAboveBoolExpression* JFirstBlockAboveBoolExpressionFactory::fromJson(
         = new JFirstBlockAboveBoolExpression();
     result->setFilter(Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(
         zJson->zValue("condition")));
+    if (zJson->hasValue("maxDistance"))
+    {
+        result->setMaxDistance(
+            (short)zJson->zValue("maxDistance")->asNumber()->getNumber());
+    }
     return result;
 }
 
@@ -1370,6 +1418,11 @@ JFirstBlockAboveBoolExpressionFactory::toJsonObject(
     Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
     result->addValue("condition",
         Game::INSTANCE->zTypeRegistry()->toJson(zObject->zFilter()));
+    if (zObject->getMaxDistance())
+    {
+        result->addValue("maxDistance",
+            new Framework::JSON::JSONNumber(zObject->getMaxDistance()));
+    }
     return result;
 }
 
@@ -1377,8 +1430,13 @@ JSONObjectValidationBuilder*
 JFirstBlockAboveBoolExpressionFactory::addToValidator(
     JSONObjectValidationBuilder* builder) const
 {
-    return builder->withRequiredAttribute("condition",
-        Game::INSTANCE->zTypeRegistry()->getValidator<BlockFilter>());
+    return builder
+        ->withRequiredAttribute("condition",
+            Game::INSTANCE->zTypeRegistry()->getValidator<BlockFilter>())
+        ->withOptionalNumber("maxDistance")
+        ->whichIsGreaterThen(0)
+        ->whichIsLessThen(WORLD_HEIGHT)
+        ->finishNumber();
 }
 
 const char* JFirstBlockAboveBoolExpressionFactory::getTypeToken() const

+ 3 - 0
FactoryCraft/JsonExpression.h

@@ -370,6 +370,7 @@ class JFirstBlockAboveBoolExpression : public JBoolExpression
 {
 private:
     BlockFilter* filter;
+    short maxDistance;
 
 public:
     JFirstBlockAboveBoolExpression();
@@ -379,6 +380,8 @@ public:
 
     void setFilter(BlockFilter* filter);
     BlockFilter* zFilter() const;
+    void setMaxDistance(short maxDistance);
+    short getMaxDistance() const;
 };
 
 class JFirstBlockAboveBoolExpressionFactory

+ 0 - 46
Windows Version/data/blocks/blockTypes.json

@@ -223,52 +223,6 @@
     "hardness": 0.75,
     "groupNames": [
       "Shovel"
-    ],
-    "damagableByHand": true,
-    "drops": [
-      {
-        "type": "blockItem",
-        "condition": {
-          "type": "not",
-          "condition": {
-            "type": "noItem"
-          }
-        }
-      },
-      {
-        "type": "specificItem",
-        "condition": {
-          "type": "operator",
-          "operator": "AND",
-          "conditions": [
-            {
-              "type": "noItem"
-            },
-            {
-              "type": "chance",
-              "chance": 0.2
-            }
-          ]
-        },
-        "itemType": "Flint"
-      },
-      {
-        "type": "specificItem",
-        "condition": {
-          "type": "operator",
-          "operator": "AND",
-          "conditions": [
-            {
-              "type": "noItem"
-            },
-            {
-              "type": "chance",
-              "chance": 0.5
-            }
-          ]
-        },
-        "itemType": "Stone"
-      }
     ]
   },
   {

+ 32 - 0
Windows Version/data/blocks/plants.json

@@ -61,6 +61,38 @@
             }
         ]
     },
+    {
+        "type": "basicBlock",
+        "name": "Loose Stones",
+        "itemType": null,
+        "model": {
+            "modelPath": "data/models/blocks.m3/loseStones",
+            "texturePaths": [
+                "data/textures/blocks.ltdb/losestones.png"
+            ]
+        },
+        "transparent": true,
+        "mapColor": "0xA0817C7C",
+        "hardness": 0.1,
+        "damagableByHand": true,
+        "drops": [
+            {
+                "type": "specificItem",
+                "condition": {
+                    "type": "chance",
+                    "chance": 0.33
+                },
+                "itemType": "Flint"
+            },
+            {
+                "type": "specificItem",
+                "condition": {
+                    "type": "allways"
+                },
+                "itemType": "Stone"
+            }
+        ]
+    },
     {
         "type": "growingPlant",
         "name": "WheatSeeds",

+ 57 - 0
Windows Version/data/generator/overworld.json

@@ -513,6 +513,7 @@
                         ],
                         "condition": {
                             "type": "firstBlockAboveMatches",
+                            "maxDistance": 24,
                             "condition": {
                                 "type": "groups",
                                 "groupNames": [
@@ -651,6 +652,62 @@
                                 ]
                             }
                         }
+                    },
+                    {
+                        "plantBlock": "Loose Stones",
+                        "condition": {
+                            "type": "specificBlockMatches",
+                            "condition": {
+                                "type": "types",
+                                "typeNames": [
+                                    "Gravel"
+                                ]
+                            },
+                            "x": {
+                                "type": "variable",
+                                "name": "x"
+                            },
+                            "y": {
+                                "type": "variable",
+                                "name": "y"
+                            },
+                            "z": {
+                                "type": "operator",
+                                "operator": "-",
+                                "values": [
+                                    {
+                                        "type": "variable",
+                                        "name": "z"
+                                    },
+                                    {
+                                        "type": "constant",
+                                        "value": 1
+                                    }
+                                ]
+                            }
+                        },
+                        "locations": [
+                            "SURFACE"
+                        ],
+                        "plantHeight": 1,
+                        "threshold": 0.7,
+                        "noise": {
+                            "type": "random",
+                            "seed": {
+                                "type": "operator",
+                                "operator": "+",
+                                "values": [
+                                    {
+                                        "type": "variable",
+                                        "name": "dimensionSeed"
+                                    },
+                                    {
+                                        "type": "constant",
+                                        "value": 58
+                                    }
+                                ]
+                            }
+                        }
                     }
                 ]
             }

+ 2 - 2
Windows Version/data/quests/quests.json

@@ -100,8 +100,8 @@
             {
                 "questId": "stone",
                 "questName": "Stone",
-                "description": "You can get some stones by searching throu gravel.",
-                "imagePath": "itemType:Gravel",
+                "description": "You can get some stones by picking up loose stones lying arround on gravel.",
+                "imagePath": "itemType:Stone",
                 "requirements": [
                     {
                         "type": "item_in_inventory",