summaryrefslogtreecommitdiffstats
path: root/source/cPiston.cpp
diff options
context:
space:
mode:
authoradmin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-07 23:59:29 +0100
committeradmin@omencraft.com <admin@omencraft.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-07 23:59:29 +0100
commita9e02cf8fa3afbdbe853e52f030e9a8c7efe46c1 (patch)
tree62167f9ff48fb895c7542e44ef5b5520172a79f4 /source/cPiston.cpp
parentMore updates to cPiston.cpp. Piston action will now only be broadcasted to players who have the chunk with the moving piston loaded. (diff)
downloadcuberite-a9e02cf8fa3afbdbe853e52f030e9a8c7efe46c1.tar
cuberite-a9e02cf8fa3afbdbe853e52f030e9a8c7efe46c1.tar.gz
cuberite-a9e02cf8fa3afbdbe853e52f030e9a8c7efe46c1.tar.bz2
cuberite-a9e02cf8fa3afbdbe853e52f030e9a8c7efe46c1.tar.lz
cuberite-a9e02cf8fa3afbdbe853e52f030e9a8c7efe46c1.tar.xz
cuberite-a9e02cf8fa3afbdbe853e52f030e9a8c7efe46c1.tar.zst
cuberite-a9e02cf8fa3afbdbe853e52f030e9a8c7efe46c1.zip
Diffstat (limited to '')
-rw-r--r--source/cPiston.cpp130
1 files changed, 72 insertions, 58 deletions
diff --git a/source/cPiston.cpp b/source/cPiston.cpp
index 8d05be87f..928d7c04b 100644
--- a/source/cPiston.cpp
+++ b/source/cPiston.cpp
@@ -1,4 +1,5 @@
#include "cPiston.h"
+#include "cRedstone.h"
#include "cChunk.h"
#include "cPickup.h"
#include "cBlockToPickup.h"
@@ -44,74 +45,87 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) {
char pistonBlock = m_World->GetBlock( pistx, pisty, pistz );
char pistonMeta = m_World->GetBlockMeta( pistx, pisty, pistz );
char isSticky = (char)(pistonBlock == E_BLOCK_STICKY_PISTON) * 8;
- unsigned short dist = FirstPassthroughBlock(pistx, pisty, pistz, pistonMeta);
- if(dist>9000) return; // too many blocks
+ bool recalc = false;
+ if (pistonMeta < 6) {// only extend if piston is not already extended
+ unsigned short dist = FirstPassthroughBlock(pistx, pisty, pistz, pistonMeta);
+ if(dist>9000) return; // too many blocks
+
+ AddDir( pistx, pisty, pistz, pistonMeta & 7, dist+1 )
+ char currBlock = m_World->GetBlock( pistx, pisty, pistz );
+ if( currBlock != E_BLOCK_AIR ) {
+ cItem PickupItem;
+ PickupItem.m_ItemID = cBlockToPickup::ToPickup( (ENUM_BLOCK_ID) currBlock, E_ITEM_EMPTY );
+ PickupItem.m_ItemCount = 1;
+ cPickup* Pickup = new cPickup( pistx*32 + 16, pisty*32 + 16, pistz*32 + 16, PickupItem );
+ Pickup->Initialize( m_World );
+ recalc = true;
+ }
+ int oldx = pistx, oldy = pisty, oldz = pistz;
+ char currBlockMeta;
+ for( int i = dist+1; i>0; i-- ) {
+ AddDir( pistx, pisty, pistz, pistonMeta & 7, -1 )
+ currBlock = m_World->GetBlock( pistx, pisty, pistz );
+ currBlockMeta = m_World->GetBlockMeta( pistx, pisty, pistz );
+ m_World->SetBlock( oldx, oldy, oldz, currBlock, currBlockMeta );
+ oldx = pistx;
+ oldy = pisty;
+ oldz = pistz;
+ }
+ cPacket_BlockAction Action;
+ Action.m_PosX = (int)pistx;
+ Action.m_PosY = (short)pisty;
+ Action.m_PosZ = (int)pistz;
+ Action.m_Byte1 = 0;
+ Action.m_Byte2 = pistonMeta;
+ cChunk* Chunk = m_World->GetChunk( FAST_FLOOR(pistx/16), FAST_FLOOR(pisty/16), FAST_FLOOR(pistz/16) );
+ Chunk->Broadcast( Action );
+ m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta | 8 );
- AddDir( pistx, pisty, pistz, pistonMeta & 7, dist+1 )
- char currBlock = m_World->GetBlock( pistx, pisty, pistz );
- if( currBlock != E_BLOCK_AIR ) {
- cItem PickupItem;
- PickupItem.m_ItemID = cBlockToPickup::ToPickup( (ENUM_BLOCK_ID) currBlock, E_ITEM_EMPTY );
- PickupItem.m_ItemCount = 1;
- cPickup* Pickup = new cPickup( pistx*32 + 16, pisty*32 + 16, pistz*32 + 16, PickupItem );
- Pickup->Initialize( m_World );
- }
- int oldx = pistx, oldy = pisty, oldz = pistz;
- char currBlockMeta;
- for( int i = dist+1; i>0; i-- ) {
- AddDir( pistx, pisty, pistz, pistonMeta & 7, -1 )
- currBlock = m_World->GetBlock( pistx, pisty, pistz );
- currBlockMeta = m_World->GetBlockMeta( pistx, pisty, pistz );
- m_World->SetBlock( oldx, oldy, oldz, currBlock, currBlockMeta );
- oldx = pistx;
- oldy = pisty;
- oldz = pistz;
- }
- cPacket_BlockAction Action;
- Action.m_PosX = (int)pistx;
- Action.m_PosY = (short)pisty;
- Action.m_PosZ = (int)pistz;
- Action.m_Byte1 = 0;
- Action.m_Byte2 = pistonMeta;
- cChunk* Chunk = m_World->GetChunk( FAST_FLOOR(pistx/16), FAST_FLOOR(pisty/16), FAST_FLOOR(pistz/16) );
- Chunk->Broadcast( Action );
- m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta | 8 );
+ int extx = pistx;
+ int exty = pisty;
+ int extz = pistz;
- int extx = pistx;
- int exty = pisty;
- int extz = pistz;
+ AddDir( extx, exty, extz, pistonMeta&7, 1 )
- AddDir( extx, exty, extz, pistonMeta&7, 1 )
+ m_World->SetBlock( extx, exty, extz, E_BLOCK_PISTON_EXTENSION, isSticky+pistonMeta&7 );
+
+ if (recalc) {
+ cRedstone Redstone(m_World);
+ Redstone.ChangeRedstone( extx, exty, extz, false ); //recalculate redstone around current device.
+ Redstone.ChangeRedstone( pistx, pisty, pistz, false ); //recalculate redstone around current device.
+ }
- m_World->SetBlock( extx, exty, extz, E_BLOCK_PISTON_EXTENSION, isSticky+pistonMeta&7 );
+ }
}
void cPiston::RetractPiston( int pistx, int pisty, int pistz ) {
char pistonBlock = m_World->GetBlock( pistx, pisty, pistz );
char pistonMeta = m_World->GetBlockMeta( pistx, pisty, pistz );
- //send blockaction packet
- cPacket_BlockAction Action;
- Action.m_PosX = (int)pistx;
- Action.m_PosY = (short)pisty;
- Action.m_PosZ = (int)pistz;
- Action.m_Byte1 = 1;
- Action.m_Byte1 = pistonMeta & ~(8);
- cChunk* Chunk = m_World->GetChunk( FAST_FLOOR(pistx/16), FAST_FLOOR(pisty/16), FAST_FLOOR(pistz/16) );
- Chunk->Broadcast( Action );
- m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta & ~(8) );
-
- AddDir( pistx, pisty, pistz, pistonMeta & 7, 1 )
- if( m_World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
- if( pistonBlock == E_BLOCK_STICKY_PISTON ) {
- int tempx = pistx, tempy = pisty, tempz = pistz;
- AddDir( tempx, tempy, tempz, pistonMeta&7, 1 )
- char tempblock = m_World->GetBlock( tempx, tempy, tempz );
- if(tempblock == E_BLOCK_OBSIDIAN || tempblock == E_BLOCK_BEDROCK || tempblock == E_BLOCK_PISTON_EXTENSION) {return;}
- m_World->SetBlock( pistx, pisty, pistz, tempblock, m_World->GetBlockMeta( tempx, tempy, tempz ) );
- m_World->SetBlock( tempx, tempy, tempz, E_BLOCK_AIR, 0 );
- }else{
- m_World->SetBlock( pistx, pisty, pistz, E_BLOCK_AIR, 0 );
+ if (pistonMeta > 6) {// only retract if piston is not already retracted
+ //send blockaction packet
+ cPacket_BlockAction Action;
+ Action.m_PosX = (int)pistx;
+ Action.m_PosY = (short)pisty;
+ Action.m_PosZ = (int)pistz;
+ Action.m_Byte1 = 1;
+ Action.m_Byte1 = pistonMeta & ~(8);
+ cChunk* Chunk = m_World->GetChunk( FAST_FLOOR(pistx/16), FAST_FLOOR(pisty/16), FAST_FLOOR(pistz/16) );
+ Chunk->Broadcast( Action );
+ m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta & ~(8) );
+
+ AddDir( pistx, pisty, pistz, pistonMeta & 7, 1 )
+ if( m_World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
+ if( pistonBlock == E_BLOCK_STICKY_PISTON ) {
+ int tempx = pistx, tempy = pisty, tempz = pistz;
+ AddDir( tempx, tempy, tempz, pistonMeta&7, 1 )
+ char tempblock = m_World->GetBlock( tempx, tempy, tempz );
+ if(tempblock == E_BLOCK_OBSIDIAN || tempblock == E_BLOCK_BEDROCK || tempblock == E_BLOCK_PISTON_EXTENSION) {return;}
+ m_World->SetBlock( pistx, pisty, pistz, tempblock, m_World->GetBlockMeta( tempx, tempy, tempz ) );
+ m_World->SetBlock( tempx, tempy, tempz, E_BLOCK_AIR, 0 );
+ }else{
+ m_World->SetBlock( pistx, pisty, pistz, E_BLOCK_AIR, 0 );
+ }
}
}
} \ No newline at end of file