summaryrefslogtreecommitdiffstats
path: root/source/Blocks/BlockFarmland.h
diff options
context:
space:
mode:
authorbearbin <bearbin@gmail.com>2013-07-29 14:55:26 +0200
committerbearbin <bearbin@gmail.com>2013-07-29 14:55:26 +0200
commitfb1044c4e55c726753d094b66756a1cb3bc60ee8 (patch)
treec61e56725da7dff0154d566722651e2c39c9d6c6 /source/Blocks/BlockFarmland.h
parentWebAdmin: Removed the duplicate memory usage querying (diff)
parentChanged everyting to Unix line endings. (diff)
downloadcuberite-fb1044c4e55c726753d094b66756a1cb3bc60ee8.tar
cuberite-fb1044c4e55c726753d094b66756a1cb3bc60ee8.tar.gz
cuberite-fb1044c4e55c726753d094b66756a1cb3bc60ee8.tar.bz2
cuberite-fb1044c4e55c726753d094b66756a1cb3bc60ee8.tar.lz
cuberite-fb1044c4e55c726753d094b66756a1cb3bc60ee8.tar.xz
cuberite-fb1044c4e55c726753d094b66756a1cb3bc60ee8.tar.zst
cuberite-fb1044c4e55c726753d094b66756a1cb3bc60ee8.zip
Diffstat (limited to 'source/Blocks/BlockFarmland.h')
-rw-r--r--source/Blocks/BlockFarmland.h198
1 files changed, 99 insertions, 99 deletions
diff --git a/source/Blocks/BlockFarmland.h b/source/Blocks/BlockFarmland.h
index fb2d91a86..6cab1fa38 100644
--- a/source/Blocks/BlockFarmland.h
+++ b/source/Blocks/BlockFarmland.h
@@ -1,99 +1,99 @@
-
-// BlockFarmland.h
-
-// Declares the cBlcokFarmlandHandler representing the block handler for farmland
-
-
-
-
-
-#pragma once
-
-#include "BlockHandler.h"
-#include "../BlockArea.h"
-
-
-
-
-
-class cBlockFarmlandHandler :
- public cBlockHandler
-{
- typedef cBlockHandler super;
-
-public:
- cBlockFarmlandHandler(void) :
- super(E_BLOCK_FARMLAND)
- {
- }
-
-
- virtual void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
- {
- // TODO: Rain hydrates farmland, too. Check world weather, don't search for water if raining.
- // NOTE: The desert biomes do not get precipitation, so another check needs to be made.
-
- // Search for water in a close proximity:
- // Ref.: http://www.minecraftwiki.net/wiki/Farmland#Hydrated_Farmland_Tiles
- cBlockArea Area;
- if (!Area.Read(a_World, a_BlockX - 4, a_BlockX + 4, a_BlockY, a_BlockY + 1, a_BlockZ - 4, a_BlockZ + 4))
- {
- // Too close to the world edge, cannot check surroudnings; don't tick at all
- return;
- }
- bool Found = false;
- int NumBlocks = Area.GetBlockCount();
- BLOCKTYPE * BlockTypes = Area.GetBlockTypes();
- for (int i = 0; i < NumBlocks; i++)
- {
- if (
- (BlockTypes[i] == E_BLOCK_WATER) ||
- (BlockTypes[i] == E_BLOCK_STATIONARY_WATER)
- )
- {
- Found = true;
- break;
- }
- }
-
- NIBBLETYPE BlockMeta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
-
- if (Found)
- {
- // Water was found, hydrate the block until hydration reaches 7:
- if (BlockMeta < 7)
- {
- a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, ++BlockMeta);
- }
- return;
- }
-
- // Water wasn't found, de-hydrate block:
- if (BlockMeta > 0)
- {
- a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FARMLAND, --BlockMeta);
- return;
- }
-
- // Farmland too dry. If nothing is growing on top, turn back to dirt:
- switch (a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))
- {
- case E_BLOCK_CROPS:
- case E_BLOCK_MELON_STEM:
- case E_BLOCK_PUMPKIN_STEM:
- {
- // Produce on top, don't revert
- break;
- }
- default:
- {
- a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_DIRT, 0);
- break;
- }
- }
- }
-} ;
-
-
-
-
+
+// BlockFarmland.h
+
+// Declares the cBlcokFarmlandHandler representing the block handler for farmland
+
+
+
+
+
+#pragma once
+
+#include "BlockHandler.h"
+#include "../BlockArea.h"
+
+
+
+
+
+class cBlockFarmlandHandler :
+ public cBlockHandler
+{
+ typedef cBlockHandler super;
+
+public:
+ cBlockFarmlandHandler(void) :
+ super(E_BLOCK_FARMLAND)
+ {
+ }
+
+
+ virtual void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ {
+ // TODO: Rain hydrates farmland, too. Check world weather, don't search for water if raining.
+ // NOTE: The desert biomes do not get precipitation, so another check needs to be made.
+
+ // Search for water in a close proximity:
+ // Ref.: http://www.minecraftwiki.net/wiki/Farmland#Hydrated_Farmland_Tiles
+ cBlockArea Area;
+ if (!Area.Read(a_World, a_BlockX - 4, a_BlockX + 4, a_BlockY, a_BlockY + 1, a_BlockZ - 4, a_BlockZ + 4))
+ {
+ // Too close to the world edge, cannot check surroudnings; don't tick at all
+ return;
+ }
+ bool Found = false;
+ int NumBlocks = Area.GetBlockCount();
+ BLOCKTYPE * BlockTypes = Area.GetBlockTypes();
+ for (int i = 0; i < NumBlocks; i++)
+ {
+ if (
+ (BlockTypes[i] == E_BLOCK_WATER) ||
+ (BlockTypes[i] == E_BLOCK_STATIONARY_WATER)
+ )
+ {
+ Found = true;
+ break;
+ }
+ }
+
+ NIBBLETYPE BlockMeta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+
+ if (Found)
+ {
+ // Water was found, hydrate the block until hydration reaches 7:
+ if (BlockMeta < 7)
+ {
+ a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, ++BlockMeta);
+ }
+ return;
+ }
+
+ // Water wasn't found, de-hydrate block:
+ if (BlockMeta > 0)
+ {
+ a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FARMLAND, --BlockMeta);
+ return;
+ }
+
+ // Farmland too dry. If nothing is growing on top, turn back to dirt:
+ switch (a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))
+ {
+ case E_BLOCK_CROPS:
+ case E_BLOCK_MELON_STEM:
+ case E_BLOCK_PUMPKIN_STEM:
+ {
+ // Produce on top, don't revert
+ break;
+ }
+ default:
+ {
+ a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_DIRT, 0);
+ break;
+ }
+ }
+ }
+} ;
+
+
+
+