summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-29 15:41:47 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-29 15:41:47 +0200
commitfe61687b97d55c92bb29bf6aae1288433229353d (patch)
tree3701e23efd1969ebc7a32b51bcabfc08fafa72a4 /source
parentAnvilStats: Overall statistics and mobspawner statistics. (diff)
downloadcuberite-fe61687b97d55c92bb29bf6aae1288433229353d.tar
cuberite-fe61687b97d55c92bb29bf6aae1288433229353d.tar.gz
cuberite-fe61687b97d55c92bb29bf6aae1288433229353d.tar.bz2
cuberite-fe61687b97d55c92bb29bf6aae1288433229353d.tar.lz
cuberite-fe61687b97d55c92bb29bf6aae1288433229353d.tar.xz
cuberite-fe61687b97d55c92bb29bf6aae1288433229353d.tar.zst
cuberite-fe61687b97d55c92bb29bf6aae1288433229353d.zip
Diffstat (limited to 'source')
-rw-r--r--source/ClientHandle.h6
-rw-r--r--source/World.h3
-rw-r--r--source/blocks/BlockBed.h123
-rw-r--r--source/blocks/BlockHandler.cpp5
-rw-r--r--source/items/ItemBed.h25
-rw-r--r--source/items/ItemHandler.cpp4
6 files changed, 163 insertions, 3 deletions
diff --git a/source/ClientHandle.h b/source/ClientHandle.h
index 1e627a017..e5625eb20 100644
--- a/source/ClientHandle.h
+++ b/source/ClientHandle.h
@@ -46,7 +46,11 @@ public:
static const int MAXBLOCKCHANGEINTERACTIONS = 20; // 5 didn't help, 10 still doesn't work in Creative, 20 seems to have done the trick
- static const int DEFAULT_VIEW_DISTANCE = 9; // The default ViewDistance (used when no value is set in Settings.ini)
+#if defined(ANDROID_NDK)
+ static const int DEFAULT_VIEW_DISTANCE = 4; // The default ViewDistance (used when no value is set in Settings.ini)
+#else
+ static const int DEFAULT_VIEW_DISTANCE = 9;
+#endif
static const int MAX_VIEW_DISTANCE = 10;
static const int MIN_VIEW_DISTANCE = 4;
diff --git a/source/World.h b/source/World.h
index f688efebf..08ccc4226 100644
--- a/source/World.h
+++ b/source/World.h
@@ -238,8 +238,9 @@ public:
/// Calls the callback for each chunk in the coords specified (all cords are inclusive). Returns true if all chunks have been processed successfully
bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback);
- void SetBlock (int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ); //tolua_export
+ void SetBlock (int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ); //tolua_export
void FastSetBlock (int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ); //tolua_export
+ void FastSetBlock (const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) { FastSetBlock( a_Pos.x, a_Pos.y, a_Pos.z, a_BlockType, a_BlockMeta ); } // tolua_export
BLOCKTYPE GetBlock(int a_X, int a_Y, int a_Z ); //tolua_export
BLOCKTYPE GetBlock(const Vector3i & a_Pos ) { return GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); } //tolua_export
NIBBLETYPE GetBlockMeta(int a_X, int a_Y, int a_Z ); //tolua_export
diff --git a/source/blocks/BlockBed.h b/source/blocks/BlockBed.h
new file mode 100644
index 000000000..cbef5bb4d
--- /dev/null
+++ b/source/blocks/BlockBed.h
@@ -0,0 +1,123 @@
+#pragma once
+#include "BlockHandler.h"
+#include "../World.h"
+#include "../Sign.h"
+#include "../Player.h"
+
+class cBlockBedHandler : public cBlockHandler
+{
+public:
+ cBlockBedHandler(BLOCKTYPE a_BlockID)
+ : cBlockHandler(a_BlockID)
+ {
+
+ }
+
+
+
+
+
+ virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
+ {
+ if( a_Dir != 1 ) // Can only be placed on the floor
+ return;
+
+ NIBBLETYPE Meta = RotationToMetaData( a_Player->GetRotation() );
+ Vector3i Direction = MetaDataToDirection( Meta );
+
+ if (a_World->GetBlock(a_X+Direction.x, a_Y, a_Z+Direction.z) != E_BLOCK_AIR)
+ {
+ return;
+ }
+
+ a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_BED, Meta);
+ a_World->SetBlock(a_X + Direction.x, a_Y, a_Z + Direction.z, E_BLOCK_BED, Meta | 0x8);
+
+ OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
+ }
+
+
+
+
+
+ virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+ {
+ char OldMeta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
+
+ Vector3i ThisPos( a_X, a_Y, a_Z );
+ Vector3i Direction = MetaDataToDirection( OldMeta & 0x7 );
+ if (OldMeta & 0x8)
+ {
+ // Was pillow
+ if (a_World->GetBlock(ThisPos - Direction) == E_BLOCK_BED)
+ {
+ a_World->FastSetBlock(ThisPos - Direction, E_BLOCK_AIR, 0);
+ }
+ }
+ else
+ {
+ // Was foot end
+ if (a_World->GetBlock(ThisPos + Direction) == E_BLOCK_BED)
+ {
+ a_World->FastSetBlock(ThisPos + Direction, E_BLOCK_AIR, 0);
+ }
+ }
+ }
+
+
+
+
+
+ virtual int GetDropID() override
+ {
+ return E_ITEM_BED;
+ }
+
+ virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
+ {
+ return 0;
+ }
+
+
+
+
+
+ virtual bool AllowBlockOnTop() override
+ {
+ return false;
+ }
+
+
+
+
+
+ static NIBBLETYPE RotationToMetaData( float a_Rotation )
+ {
+ a_Rotation += 180 + (180/4); // So its not aligned with axis
+ if( a_Rotation > 360.f ) a_Rotation -= 360.f;
+
+ a_Rotation = (a_Rotation/360) * 4;
+
+ return ((char)a_Rotation+2) % 4;
+ }
+
+
+
+
+
+ static Vector3i MetaDataToDirection( NIBBLETYPE a_MetaData )
+ {
+ switch( a_MetaData )
+ {
+ case 0: // south +z
+ return Vector3i(0, 0, 1);
+ case 1: // west -x
+ return Vector3i(-1, 0, 0);
+ case 2: // north -z
+ return Vector3i(0, 0, -1);
+ case 3: // east +x
+ return Vector3i(1, 0, 0);
+ };
+ return Vector3i();
+ }
+};
diff --git a/source/blocks/BlockHandler.cpp b/source/blocks/BlockHandler.cpp
index f45f40f9e..e6b384a23 100644
--- a/source/blocks/BlockHandler.cpp
+++ b/source/blocks/BlockHandler.cpp
@@ -41,6 +41,7 @@
#include "BlockIce.h"
#include "BlockOre.h"
#include "BlockNote.h"
+#include "BlockBed.h"
@@ -91,7 +92,7 @@ cBlockHandler *cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockID)
return new cBlockRedstoneTorchHandler(a_BlockID);
case E_BLOCK_REDSTONE_WIRE:
return new cBlockRedstoneHandler(a_BlockID);
- case E_BLOCK_PISTON:
+ case E_BLOCK_PISTON:
case E_BLOCK_STICKY_PISTON:
return new cBlockPistonHandler(a_BlockID);
case E_BLOCK_REDSTONE_REPEATER_ON:
@@ -182,6 +183,8 @@ cBlockHandler *cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockID)
return new cBlockMelonHandler(a_BlockID);
case E_BLOCK_NOTE_BLOCK:
return new cBlockNoteHandler(a_BlockID);
+ case E_BLOCK_BED:
+ return new cBlockBedHandler(a_BlockID);
default:
return new cBlockHandler(a_BlockID);
break;
diff --git a/source/items/ItemBed.h b/source/items/ItemBed.h
new file mode 100644
index 000000000..b49df65a3
--- /dev/null
+++ b/source/items/ItemBed.h
@@ -0,0 +1,25 @@
+
+#pragma once
+
+#include "ItemHandler.h"
+#include "../World.h"
+
+class cItemBedHandler : public cItemHandler
+{
+public:
+ cItemBedHandler(int a_ItemID)
+ : cItemHandler(a_ItemID)
+ {
+
+ }
+
+ virtual bool IsPlaceable() override
+ {
+ return true;
+ }
+
+ virtual BLOCKTYPE GetBlockType() override
+ {
+ return E_BLOCK_BED;
+ }
+}; \ No newline at end of file
diff --git a/source/items/ItemHandler.cpp b/source/items/ItemHandler.cpp
index 44f6438e1..63d4f4258 100644
--- a/source/items/ItemHandler.cpp
+++ b/source/items/ItemHandler.cpp
@@ -26,6 +26,7 @@
#include "ItemDoor.h"
#include "ItemFood.h"
#include "ItemSign.h"
+#include "ItemBed.h"
#include "../blocks/BlockHandler.h"
@@ -166,6 +167,9 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemID)
case E_ITEM_SIGN:
return new cItemSignHandler(a_ItemID);
+
+ case E_ITEM_BED:
+ return new cItemBedHandler(a_ItemID);
}
}