summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--source/BlockID.h4
-rw-r--r--source/cChunk.cpp25
-rw-r--r--source/cClientHandle.cpp49
-rw-r--r--source/cPiston.cpp130
-rw-r--r--source/cRedstone.cpp147
-rw-r--r--source/cRedstone.h4
6 files changed, 238 insertions, 121 deletions
diff --git a/source/BlockID.h b/source/BlockID.h
index 3bdc65cac..8122e63b9 100644
--- a/source/BlockID.h
+++ b/source/BlockID.h
@@ -78,8 +78,8 @@ enum ENUM_BLOCK_ID
E_BLOCK_WOODEN_PRESSURE_PLATE = 72,
E_BLOCK_REDSTONE_ORE = 73,
E_BLOCK_REDSTONE_ORE_GLOWING = 74,
- E_BLOCK_REDSTONE_TORCH_ON = 75,
- E_BLOCK_REDSTONE_TORCH_OFF = 76,
+ E_BLOCK_REDSTONE_TORCH_OFF = 75,
+ E_BLOCK_REDSTONE_TORCH_ON = 76,
E_BLOCK_STONE_BUTTON = 77,
E_BLOCK_SNOW = 78,
E_BLOCK_ICE = 79,
diff --git a/source/cChunk.cpp b/source/cChunk.cpp
index a8a579e96..ac4f69f93 100644
--- a/source/cChunk.cpp
+++ b/source/cChunk.cpp
@@ -19,10 +19,12 @@
#include "cTorch.h"
#include "cLadder.h"
#include "cPickup.h"
+#include "cRedstone.h"
#include "cItem.h"
#include "cNoise.h"
#include "cRoot.h"
#include "cCriticalSection.h"
+#include "cBlockToPickup.h"
#include "cGenSettings.h"
@@ -215,6 +217,7 @@ void cChunk::Tick(float a_Dt)
unsigned int NumTickBlocks = ToTickBlocks.size();
if( NumTickBlocks > 0 ) LOG("To tick: %i", NumTickBlocks );
m_pState->m_ToTickBlocks.clear();
+ bool isRedstone = false;
for( std::map< unsigned int, int>::iterator itr = ToTickBlocks.begin(); itr != ToTickBlocks.end(); ++itr )
{
if( (*itr).second < 0 ) continue;
@@ -226,6 +229,12 @@ void cChunk::Tick(float a_Dt)
char BlockID = GetBlock( index );
switch( BlockID )
{
+ case E_BLOCK_REDSTONE_REPEATER_OFF:
+ case E_BLOCK_REDSTONE_REPEATER_ON:
+ case E_BLOCK_REDSTONE_WIRE:
+ {
+ isRedstone = true;
+ }
case E_BLOCK_REEDS:
case E_BLOCK_WOODEN_PRESSURE_PLATE:
case E_BLOCK_STONE_PRESSURE_PLATE:
@@ -236,19 +245,23 @@ void cChunk::Tick(float a_Dt)
case E_BLOCK_YELLOW_FLOWER:
case E_BLOCK_RED_ROSE:
case E_BLOCK_RED_MUSHROOM:
- case E_BLOCK_BROWN_MUSHROOM:
- case E_BLOCK_REDSTONE_WIRE: // Stuff that drops when block below is destroyed
+ case E_BLOCK_BROWN_MUSHROOM: // Stuff that drops when block below is destroyed
{
if( GetBlock( X, Y-1, Z ) == E_BLOCK_AIR )
{
SetBlock( X, Y, Z, 0, 0 );
- cPickup* Pickup = new cPickup( (X+m_PosX*16) * 32 + 16, (Y+m_PosY*128) * 32 + 16, (Z+m_PosZ*16) * 32 + 16, cItem( (ENUM_ITEM_ID)BlockID, 1 ) );
+ if (isRedstone) {
+ cRedstone Redstone(m_World);
+ Redstone.ChangeRedstone( X, Y, Z, false );
+ }
+ cPickup* Pickup = new cPickup( (X+m_PosX*16) * 32 + 16, (Y+m_PosY*128) * 32 + 16, (Z+m_PosZ*16) * 32 + 16, cItem( cBlockToPickup::ToPickup( (ENUM_ITEM_ID)BlockID, E_ITEM_EMPTY) , 1 ) );
Pickup->Initialize( m_World );
}
}
break;
case E_BLOCK_REDSTONE_TORCH_OFF:
case E_BLOCK_REDSTONE_TORCH_ON:
+ isRedstone = true;
case E_BLOCK_TORCH:
{
char Dir = cTorch::MetaDataToDirection( GetLight( m_BlockMeta, X, Y, Z ) );
@@ -260,7 +273,11 @@ void cChunk::Tick(float a_Dt)
if( m_World->GetBlock( XX, YY, ZZ ) == E_BLOCK_AIR )
{
SetBlock( X, Y, Z, 0, 0 );
- cPickup* Pickup = new cPickup( (X+m_PosX*16) * 32 + 16, (Y+m_PosY*128) * 32 + 16, (Z+m_PosZ*16) * 32 + 16, cItem( (ENUM_ITEM_ID)BlockID, 1 ) );
+ if (isRedstone) {
+ cRedstone Redstone(m_World);
+ Redstone.ChangeRedstone( X, Y, Z, false );
+ }
+ cPickup* Pickup = new cPickup( (X+m_PosX*16) * 32 + 16, (Y+m_PosY*128) * 32 + 16, (Z+m_PosZ*16) * 32 + 16, cItem( cBlockToPickup::ToPickup( (ENUM_ITEM_ID)BlockID, E_ITEM_EMPTY) , 1 ) );
Pickup->Initialize( m_World );
}
}
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index b428910d3..79488f0c4 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -71,6 +71,10 @@
#define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__ )
#endif
+#define AddPistonDir( x, y, z, dir, amount ) switch(dir) { case 0: (y)-=(amount); break; case 1: (y)+=(amount); break;\
+ case 2: (z)-=(amount); break; case 3: (z)+=(amount); break;\
+ case 4: (x)-=(amount); break; case 5: (x)+=(amount); break; }
+
#define MAX_SEMAPHORES (2000)
typedef std::list<cPacket*> PacketList;
@@ -535,15 +539,24 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
{
if (OldBlock == E_BLOCK_REDSTONE_TORCH_ON) {
cRedstone Redstone(World);
- Redstone.ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false );
+ Redstone.ChangeRedstone( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false );
}
if (OldBlock == E_BLOCK_REDSTONE_TORCH_OFF) {
cRedstone Redstone(World);
- Redstone.ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false );
+ Redstone.ChangeRedstone( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false );
}
if (OldBlock == E_BLOCK_REDSTONE_WIRE) {
cRedstone Redstone(World);
- Redstone.ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false );
+ Redstone.ChangeRedstone( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false );
+ }
+ if (( OldBlock == E_BLOCK_PISTON) || (OldBlock == E_BLOCK_STICKY_PISTON) ) {
+ int newX = PacketData->m_PosX;
+ int newY = PacketData->m_PosY;
+ int newZ = PacketData->m_PosZ;
+ AddPistonDir( newX, newY, newZ, MetaData & ~(8), 1 )
+ if (World->GetBlock(newX, newY, newZ) == E_BLOCK_PISTON_EXTENSION) {
+ World->SetBlock( newX, newY, newZ, E_BLOCK_AIR, 0 );
+ }
}
int helditem = m_Player->GetInventory().GetEquippedItem().m_ItemID;
@@ -629,6 +642,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
break;
case E_BLOCK_PLACE:
{
+
//LOG("TimeP: %f", m_Player->GetLastBlockActionTime() );
//LOG("TimeN: %f", cRoot::Get()->GetWorld()->GetTime() );
if ( cRoot::Get()->GetWorld()->GetTime() - m_Player->GetLastBlockActionTime() < 0.1 ) { //only allow block interactions every 0.1 seconds
@@ -640,9 +654,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
cPacket_BlockPlace* PacketData = reinterpret_cast<cPacket_BlockPlace*>(a_Packet);
cItem & Equipped = m_Player->GetInventory().GetEquippedItem();
//if( (Equipped.m_ItemID != PacketData->m_ItemType) ) // Not valid
- if ( ( m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ ) != E_BLOCK_AIR ) && (m_Player->GetGameMode() != 1) ) { //tried to place a block *into* another?
- break; //happens when you place a block aiming at side of block like torch or stem
- }
+
if( (Equipped.m_ItemID != PacketData->m_ItemType) && (m_Player->GetGameMode() != 1) ) // Not valid
{
LOGWARN("Player %s tried to place a block that was not selected! (could indicate bot)", GetUsername() );
@@ -776,6 +788,9 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
char MetaData = (char)Equipped.m_ItemHealth;
switch( PacketData->m_ItemType ) // Special handling for special items
{
+ case E_BLOCK_WHITE_CLOTH:
+ MetaData = (char)PacketData->m_Uses;
+ break;
case E_BLOCK_TORCH:
MetaData = cTorch::DirectionToMetaData( PacketData->m_Direction );
break;
@@ -790,14 +805,14 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
//printf("transparent not above me\n");
}
UpdateRedstone = true;
- AddedCurrent = true;
+ AddedCurrent = false;
break;
}
case E_BLOCK_REDSTONE_TORCH_ON:
{
MetaData = cTorch::DirectionToMetaData( PacketData->m_Direction );
UpdateRedstone = true;
- AddedCurrent = false;
+ AddedCurrent = true;
break;
}
case E_ITEM_REDSTONE_DUST:
@@ -848,17 +863,21 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
};
if( IsValidBlock( PacketData->m_ItemType) )
{
- if( (m_Player->GetInventory().RemoveItem( Item )) || (m_Player->GetGameMode() == 1) )
+ int X = PacketData->m_PosX;
+ char Y = PacketData->m_PosY;
+ int Z = PacketData->m_PosZ;
+ AddDirection( X, Y, Z, PacketData->m_Direction );
+ if( m_Player->GetWorld()->GetBlock( X, Y, Z ) != E_BLOCK_AIR ) { //tried to place a block *into* another?
+ break; //happens when you place a block aiming at side of block like torch or stem
+ }
+
+ if( (m_Player->GetGameMode() == 1) || (m_Player->GetInventory().RemoveItem( Item )) )
{
- int X = PacketData->m_PosX;
- char Y = PacketData->m_PosY;
- int Z = PacketData->m_PosZ;
- AddDirection( X, Y, Z, PacketData->m_Direction );
-
+
m_Player->GetWorld()->SetBlock( X, Y, Z, (char)PacketData->m_ItemType, MetaData );
if (UpdateRedstone) {
cRedstone Redstone(m_Player->GetWorld());
- Redstone.ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ, AddedCurrent );
+ Redstone.ChangeRedstone( PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ, AddedCurrent );
}
}
}
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
diff --git a/source/cRedstone.cpp b/source/cRedstone.cpp
index 6a0b1473a..178fdc7be 100644
--- a/source/cRedstone.cpp
+++ b/source/cRedstone.cpp
@@ -11,7 +11,7 @@ cRedstone::cRedstone( cWorld* a_World )
}
-void cRedstone::ChangeRedstoneTorch( int fillx, int filly, int fillz, bool added )
+void cRedstone::ChangeRedstone( int fillx, int filly, int fillz, bool added )
{
if (added) {
m_Metadata = 15;
@@ -19,90 +19,157 @@ void cRedstone::ChangeRedstoneTorch( int fillx, int filly, int fillz, bool added
m_Metadata = 0;
}
- LightRedstone( fillx, filly, fillz );
+ CalculatetRedstone( fillx, filly, fillz );
- if ( (int)m_World->GetBlock( fillx, filly, fillz ) == 0 ) { //we removed an item
+ if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_AIR ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_PISTON_EXTENSION ) ) {
- LightRedstone( fillx+1, filly, fillz );
m_Metadata = 0;
- LightRedstone( fillx-1, filly, fillz );
+ CalculatetRedstone( fillx+1, filly, fillz );
m_Metadata = 0;
- LightRedstone( fillx, filly, fillz+1 );
+ CalculatetRedstone( fillx-1, filly, fillz );
m_Metadata = 0;
- LightRedstone( fillx, filly, fillz-1 );
+ CalculatetRedstone( fillx, filly, fillz+1 );
m_Metadata = 0;
-
+ CalculatetRedstone( fillx, filly, fillz-1 );
+ m_Metadata = 0;
+
+ CalculatetRedstone( fillx+1, filly+1, fillz );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx-1, filly+1, fillz );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx, filly+1, fillz+1 );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx, filly+1, fillz-1 );
+ m_Metadata = 0;
+
+ CalculatetRedstone( fillx+1, filly-1, fillz );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx-1, filly-1, fillz );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx, filly-1, fillz+1 );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx, filly-1, fillz-1 );
+ m_Metadata = 0;
+
}
if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE ) { //we added dust
- LightRedstone( fillx+1, filly, fillz );
- LightRedstone( fillx-1, filly, fillz );
- LightRedstone( fillx, filly, fillz+1 );
- LightRedstone( fillx, filly, fillz-1 );
+ CalculatetRedstone( fillx+1, filly, fillz );
+ CalculatetRedstone( fillx-1, filly, fillz );
+ CalculatetRedstone( fillx, filly, fillz+1 );
+ CalculatetRedstone( fillx, filly, fillz-1 );
+
+ CalculatetRedstone( fillx+1, filly+1, fillz );
+ CalculatetRedstone( fillx-1, filly+1, fillz );
+ CalculatetRedstone( fillx, filly+1, fillz+1 );
+ CalculatetRedstone( fillx, filly+1, fillz-1 );
+
+ CalculatetRedstone( fillx+1, filly-1, fillz );
+ CalculatetRedstone( fillx-1, filly-1, fillz );
+ CalculatetRedstone( fillx, filly-1, fillz+1 );
+ CalculatetRedstone( fillx, filly-1, fillz-1 );
+
+ }
+
+ if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_PISTON ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STICKY_PISTON ) ) { //we added a piston
+
+ m_Metadata = 0;
+ CalculatetRedstone( fillx+1, filly, fillz );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx-1, filly, fillz );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx, filly, fillz+1 );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx, filly, fillz-1 );
+ m_Metadata = 0;
+
+ CalculatetRedstone( fillx+1, filly+1, fillz );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx-1, filly+1, fillz );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx, filly+1, fillz+1 );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx, filly+1, fillz-1 );
+ m_Metadata = 0;
+
+ CalculatetRedstone( fillx+1, filly-1, fillz );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx-1, filly-1, fillz );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx, filly-1, fillz+1 );
+ m_Metadata = 0;
+ CalculatetRedstone( fillx, filly-1, fillz-1 );
+ m_Metadata = 0;
}
}
-void cRedstone::LightRedstone( int fillx, int filly, int fillz)
+void cRedstone::CalculatetRedstone( int fillx, int filly, int fillz)
{
if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STICKY_PISTON ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_PISTON ) ) {
- cPiston Piston(m_World);
+ char pistonMeta = m_World->GetBlockMeta( fillx, filly, fillz );
if (m_Metadata > 0) {
- Piston.ExtendPiston(fillx, filly, fillz);
+ if (pistonMeta < 6) { // only extend if piston is not already extended
+ cPiston Piston(m_World);
+ Piston.ExtendPiston(fillx, filly, fillz);
+ }
} else {
- Piston.RetractPiston(fillx, filly, fillz);
+ if (pistonMeta > 6) { // only retract if piston is not already retracted
+ cPiston Piston(m_World);
+ Piston.RetractPiston(fillx, filly, fillz);
+ }
}
}
- if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF ) { //I don't think notch knows on from off. >.>
+ if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON ) { //If torch is on
m_Metadata = 15;
if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) {
- LightRedstone(fillx-1,filly,fillz);
+ CalculatetRedstone(fillx-1,filly,fillz);
}
if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) {
- LightRedstone(fillx+1,filly,fillz);
+ CalculatetRedstone(fillx+1,filly,fillz);
}
if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) {
- LightRedstone(fillx,filly,fillz-1);
+ CalculatetRedstone(fillx,filly,fillz-1);
}
if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) {
- LightRedstone(fillx,filly,fillz+1);
+ CalculatetRedstone(fillx,filly,fillz+1);
}
- } else if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_ON ) { //if the torch is off
+ } else if ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_TORCH_OFF ) { //if the torch is off
if ( ( (int)m_World->GetBlock( fillx-1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx-1, filly, fillz) != m_Metadata ) ) {
- LightRedstone(fillx-1,filly,fillz);
+ CalculatetRedstone(fillx-1,filly,fillz);
}
if ( ( (int)m_World->GetBlock( fillx+1, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx+1, filly, fillz) != m_Metadata ) ) {
- LightRedstone(fillx+1,filly,fillz);
+ CalculatetRedstone(fillx+1,filly,fillz);
}
if ( ( (int)m_World->GetBlock( fillx, filly, fillz-1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz-1) != m_Metadata ) ) {
- LightRedstone(fillx,filly,fillz-1);
+ CalculatetRedstone(fillx,filly,fillz-1);
}
if ( ( (int)m_World->GetBlock( fillx, filly, fillz+1 ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz+1) != m_Metadata ) ) {
- LightRedstone(fillx,filly,fillz+1);
+ CalculatetRedstone(fillx,filly,fillz+1);
}
}
if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz) != m_Metadata ) ) {
m_World->FastSetBlock( fillx, filly, fillz, (char)E_BLOCK_REDSTONE_WIRE, m_Metadata );
- LightRedstone(fillx-1,filly,fillz);
- LightRedstone(fillx+1,filly,fillz);
- LightRedstone(fillx,filly,fillz-1);
- LightRedstone(fillx,filly,fillz+1);
-
- LightRedstone(fillx-1,filly-1,fillz);
- LightRedstone(fillx+1,filly-1,fillz);
- LightRedstone(fillx,filly-1,fillz-1);
- LightRedstone(fillx,filly-1,fillz+1);
-
- LightRedstone(fillx-1,filly+1,fillz);
- LightRedstone(fillx+1,filly+1,fillz);
- LightRedstone(fillx,filly+1,fillz-1);
- LightRedstone(fillx,filly+1,fillz+1);
+ CalculatetRedstone(fillx-1,filly,fillz);
+ CalculatetRedstone(fillx+1,filly,fillz);
+ CalculatetRedstone(fillx,filly,fillz-1);
+ CalculatetRedstone(fillx,filly,fillz+1);
+
+ CalculatetRedstone(fillx-1,filly-1,fillz);
+ CalculatetRedstone(fillx+1,filly-1,fillz);
+ CalculatetRedstone(fillx,filly-1,fillz-1);
+ CalculatetRedstone(fillx,filly-1,fillz+1);
+
+ CalculatetRedstone(fillx-1,filly+1,fillz);
+ CalculatetRedstone(fillx+1,filly+1,fillz);
+ CalculatetRedstone(fillx,filly+1,fillz-1);
+ CalculatetRedstone(fillx,filly+1,fillz+1);
}
} \ No newline at end of file
diff --git a/source/cRedstone.h b/source/cRedstone.h
index 5735fb298..fae353818 100644
--- a/source/cRedstone.h
+++ b/source/cRedstone.h
@@ -22,8 +22,8 @@ static char RepeaterRotationToMetaData( float a_Rotation )
}
-void LightRedstone( int, int, int );
-void ChangeRedstoneTorch( int, int, int, bool );
+void CalculatetRedstone( int, int, int );
+void ChangeRedstone( int, int, int, bool );
cWorld* m_World;