Patch with diff file created by Sebi (implemented some stuff like lava physics, drops are deleted when in lava, water is now slower, lava gives actual damage etc.). Pistons now work mostly as they should. They do not yet show the motion animation and do not emit sound. They do extend, push, and retract as they should though. Right now the only way to activate a piston is to light redstone wire adjacent to it with a redstone torch.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@67 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
admin@omencraft.com 2011-11-06 09:23:20 +00:00
parent 6df50b40ee
commit 36f7084e3f
15 changed files with 540 additions and 276 deletions

View File

@ -244,6 +244,7 @@
<ClCompile Include="..\Source\cGroupManager.cpp" /> <ClCompile Include="..\Source\cGroupManager.cpp" />
<ClCompile Include="..\Source\cHeartBeat.cpp" /> <ClCompile Include="..\Source\cHeartBeat.cpp" />
<ClCompile Include="..\source\cItem.cpp" /> <ClCompile Include="..\source\cItem.cpp" />
<ClCompile Include="..\source\cLavaSimulator.cpp" />
<ClCompile Include="..\Source\cLuaCommandBinder.cpp" /> <ClCompile Include="..\Source\cLuaCommandBinder.cpp" />
<ClCompile Include="..\source\cMakeDir.cpp" /> <ClCompile Include="..\source\cMakeDir.cpp" />
<ClCompile Include="..\source\cMCLogger.cpp" /> <ClCompile Include="..\source\cMCLogger.cpp" />
@ -373,6 +374,7 @@
<ClInclude Include="..\Source\cGroupManager.h" /> <ClInclude Include="..\Source\cGroupManager.h" />
<ClInclude Include="..\Source\cHeartBeat.h" /> <ClInclude Include="..\Source\cHeartBeat.h" />
<ClInclude Include="..\Source\cLadder.h" /> <ClInclude Include="..\Source\cLadder.h" />
<ClInclude Include="..\source\cLavaSimulator.h" />
<ClInclude Include="..\Source\cLuaCommandBinder.h" /> <ClInclude Include="..\Source\cLuaCommandBinder.h" />
<ClInclude Include="..\source\cMakeDir.h" /> <ClInclude Include="..\source\cMakeDir.h" />
<ClInclude Include="..\source\cMCLogger.h" /> <ClInclude Include="..\source\cMCLogger.h" />

View File

@ -382,6 +382,9 @@
<Filter Include="cPiston"> <Filter Include="cPiston">
<UniqueIdentifier>{4f551776-009b-4f05-8ab8-748b82279a67}</UniqueIdentifier> <UniqueIdentifier>{4f551776-009b-4f05-8ab8-748b82279a67}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="cLavaSimulator">
<UniqueIdentifier>{b0401fd9-4021-4ab7-bf61-c8de112b4196}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\source\cServer.cpp"> <ClCompile Include="..\source\cServer.cpp">
@ -766,6 +769,9 @@
<ClCompile Include="..\source\cPiston.cpp"> <ClCompile Include="..\source\cPiston.cpp">
<Filter>cPiston</Filter> <Filter>cPiston</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\source\cLavaSimulator.cpp">
<Filter>cLavaSimulator</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\source\cServer.h"> <ClInclude Include="..\source\cServer.h">
@ -1185,6 +1191,9 @@
<ClInclude Include="..\source\cPiston.h"> <ClInclude Include="..\source\cPiston.h">
<Filter>cPiston</Filter> <Filter>cPiston</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\source\cLavaSimulator.h">
<Filter>cLavaSimulator</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\source\AllToLua.pkg"> <None Include="..\source\AllToLua.pkg">

View File

@ -223,6 +223,7 @@ MCServer : \
build/iniFile.o\ build/iniFile.o\
build/cSocket.o\ build/cSocket.o\
build/cWaterSimulator.o\ build/cWaterSimulator.o\
build/cLavaSimulator.o\
build/cFileFormatUpdater.o\ build/cFileFormatUpdater.o\
build/cItem.o build/cItem.o
$(CC) $(LNK_OPTIONS) \ $(CC) $(LNK_OPTIONS) \
@ -410,6 +411,7 @@ MCServer : \
build/iniFile.o\ build/iniFile.o\
build/cSocket.o\ build/cSocket.o\
build/cWaterSimulator.o\ build/cWaterSimulator.o\
build/cLavaSimulator.o\
build/cFileFormatUpdater.o\ build/cFileFormatUpdater.o\
build/cItem.o\ build/cItem.o\
-o MCServer -o MCServer
@ -600,6 +602,7 @@ clean :
build/iniFile.o\ build/iniFile.o\
build/cSocket.o\ build/cSocket.o\
build/cWaterSimulator.o\ build/cWaterSimulator.o\
build/cLavaSimulator.o\
build/cFileFormatUpdater.o\ build/cFileFormatUpdater.o\
build/cItem.o\ build/cItem.o\
MCServer MCServer
@ -1380,6 +1383,9 @@ build/cSocket.o : source/cSocket.cpp
build/cWaterSimulator.o : source/cWaterSimulator.cpp build/cWaterSimulator.o : source/cWaterSimulator.cpp
$(CC) $(CC_OPTIONS) source/cWaterSimulator.cpp -c $(INCLUDE) -o build/cWaterSimulator.o $(CC) $(CC_OPTIONS) source/cWaterSimulator.cpp -c $(INCLUDE) -o build/cWaterSimulator.o
build/cLavaSimulator.o : source/cLavaSimulator.cpp
$(CC) $(CC_OPTIONS) source/cLavaSimulator.cpp -c $(INCLUDE) -o build/cLavaSimulator.o
build/cFileFormatUpdater.o : source/cFileFormatUpdater.cpp build/cFileFormatUpdater.o : source/cFileFormatUpdater.cpp
$(CC) $(CC_OPTIONS) source/cFileFormatUpdater.cpp -c $(INCLUDE) -o build/cFileFormatUpdater.o $(CC) $(CC_OPTIONS) source/cFileFormatUpdater.cpp -c $(INCLUDE) -o build/cFileFormatUpdater.o

View File

@ -22,7 +22,7 @@ protected:
public: public:
virtual ~cBlockEntity() {}; virtual ~cBlockEntity() {};
virtual void Destroy() {}; virtual void Destroy() {};
int GetPosX() { return m_PosX; } int GetPosX() { return m_PosX; }
int GetPosY() { return m_PosY; } int GetPosY() { return m_PosY; }
int GetPosZ() { return m_PosZ; } int GetPosZ() { return m_PosZ; }

View File

@ -337,7 +337,7 @@ void cChunk::Tick(float a_Dt)
case E_BLOCK_GRASS: case E_BLOCK_GRASS:
{ {
char AboveBlock = GetBlock( Index+1 ); char AboveBlock = GetBlock( Index+1 );
if (!( (AboveBlock == 0) || (g_BlockOneHitDig[AboveBlock]) ) ) //changed to not allow grass if any one hit object is on top if (!( (AboveBlock == 0) || (g_BlockOneHitDig[AboveBlock]) || (g_BlockTransparent[AboveBlock]) ) ) //changed to not allow grass if any one hit object is on top
{ {
FastSetBlock( m_BlockTickX, m_BlockTickY, m_BlockTickZ, E_BLOCK_DIRT, GetLight( m_BlockMeta, Index ) ); FastSetBlock( m_BlockTickX, m_BlockTickY, m_BlockTickZ, E_BLOCK_DIRT, GetLight( m_BlockMeta, Index ) );
} }
@ -687,13 +687,13 @@ void cChunk::SpreadLight(char* a_LightBuffer)
float GetNoise( float x, float y, cNoise & a_Noise ) float GetNoise( float x, float y, cNoise & a_Noise )
{ {
float oct1 = a_Noise.SSE_CubicNoise2D( x*cGenSettings::HeightFreq1, y*cGenSettings::HeightFreq1 )*cGenSettings::HeightAmp1; float oct1 = a_Noise.CubicNoise2D( x*cGenSettings::HeightFreq1, y*cGenSettings::HeightFreq1 )*cGenSettings::HeightAmp1;
float oct2 = a_Noise.SSE_CubicNoise2D( x*cGenSettings::HeightFreq2, y*cGenSettings::HeightFreq2 )*cGenSettings::HeightAmp2; float oct2 = a_Noise.CubicNoise2D( x*cGenSettings::HeightFreq2, y*cGenSettings::HeightFreq2 )*cGenSettings::HeightAmp2;
float oct3 = a_Noise.SSE_CubicNoise2D( x*cGenSettings::HeightFreq3, y*cGenSettings::HeightFreq3 )*cGenSettings::HeightAmp3; float oct3 = a_Noise.CubicNoise2D( x*cGenSettings::HeightFreq3, y*cGenSettings::HeightFreq3 )*cGenSettings::HeightAmp3;
float height = a_Noise.SSE_CubicNoise2D( x*0.1f, y*0.1f )*2; float height = a_Noise.CubicNoise2D( x*0.1f, y*0.1f )*2;
float flatness = ((a_Noise.SSE_CubicNoise2D( x*0.5f, y*0.5f ) + 1.f ) * 0.5f) * 1.1f; // 0 ... 1.5 float flatness = ((a_Noise.CubicNoise2D( x*0.5f, y*0.5f ) + 1.f ) * 0.5f) * 1.1f; // 0 ... 1.5
flatness *= flatness * flatness; flatness *= flatness * flatness;
return (oct1 + oct2 + oct3) * flatness + height; return (oct1 + oct2 + oct3) * flatness + height;
@ -845,8 +845,8 @@ void cChunk::GenerateTerrain()
// int yy = TopY; // int yy = TopY;
int zz = z + m_PosZ*16; int zz = z + m_PosZ*16;
float val1 = m_Noise.SSE_CubicNoise2D( xx*0.1f, zz*0.1f ); float val1 = m_Noise.CubicNoise2D( xx*0.1f, zz*0.1f );
float val2 = m_Noise.SSE_CubicNoise2D( xx*0.01f, zz*0.01f ); float val2 = m_Noise.CubicNoise2D( xx*0.01f, zz*0.01f );
if( m_BlockType[index] == SandID ) if( m_BlockType[index] == SandID )
{ {
if( (val1 + val2 > 0.f) && (rand()%128) > 124 && m_BlockType[index] == E_BLOCK_SAND ) if( (val1 + val2 > 0.f) && (rand()%128) > 124 && m_BlockType[index] == E_BLOCK_SAND )
@ -861,8 +861,8 @@ void cChunk::GenerateTerrain()
} }
else if( m_BlockType[index] == GrassID ) else if( m_BlockType[index] == GrassID )
{ {
float val3 = m_Noise.SSE_CubicNoise2D( xx*0.01f+10, zz*0.01f+10 ); float val3 = m_Noise.CubicNoise2D( xx*0.01f+10, zz*0.01f+10 );
float val4 = m_Noise.SSE_CubicNoise2D( xx*0.05f+20, zz*0.05f+20 ); float val4 = m_Noise.CubicNoise2D( xx*0.05f+20, zz*0.05f+20 );
if( val1 + val2 > 0.2f && (rand()%128) > 124 ) if( val1 + val2 > 0.2f && (rand()%128) > 124 )
m_World->GrowTree( xx, TopY, zz ); m_World->GrowTree( xx, TopY, zz );
else if( val3 > 0.2f && (rand()%128) > 124 ) else if( val3 > 0.2f && (rand()%128) > 124 )

View File

@ -523,7 +523,6 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
{ {
if( World->DigBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, PickupItem ) ) if( World->DigBlock( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, PickupItem ) )
{ {
printf("OldBlock,E_BLOCK_REDSTONE_TORCH_ON: %i,%i\n", OldBlock, E_BLOCK_REDSTONE_TORCH_ON );
if (OldBlock == E_BLOCK_REDSTONE_TORCH_ON) { if (OldBlock == E_BLOCK_REDSTONE_TORCH_ON) {
cRedstone Redstone(World); cRedstone Redstone(World);
Redstone.cRedstone::ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false ); Redstone.cRedstone::ChangeRedstoneTorch( PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, false );
@ -767,9 +766,9 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
//if( GetBlock( X, Y+1, Z ) == E_BLOCK_AIR ) //if( GetBlock( X, Y+1, Z ) == E_BLOCK_AIR )
if( g_BlockTransparent[ (int)m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY+2, PacketData->m_PosZ ) ] == true ) {//if block above is transparent if( g_BlockTransparent[ (int)m_Player->GetWorld()->GetBlock( PacketData->m_PosX, PacketData->m_PosY+2, PacketData->m_PosZ ) ] == true ) {//if block above is transparent
printf("transparent above me\n"); //printf("transparent above me\n");
} else { } else {
printf("transparent not above me\n"); //printf("transparent not above me\n");
} }
cRedstone Redstone(m_Player->GetWorld()); cRedstone Redstone(m_Player->GetWorld());
@ -1051,11 +1050,10 @@ void cClientHandle::Tick(float a_Dt)
// Send health // Send health
Send( cPacket_UpdateHealth( (short)m_Player->GetHealth() ) ); Send( cPacket_UpdateHealth( (short)m_Player->GetHealth() ) );
//quick bugfix to prevent players from spawning in ground
//m_Player->TeleportTo( m_Player->GetPosX(), m_Player->GetPosY()+1, m_Player->GetPosZ() );
World->UnlockEntities(); World->UnlockEntities();
m_Player->TeleportTo( m_Player->GetPosX(), m_Player->GetPosY()+1, m_Player->GetPosZ() );
//quick bugfix to prevent players from spawning in ground
m_Player->TeleportTo( m_Player->GetPosX(), m_Player->GetPosY()+2, m_Player->GetPosZ() );
} }
} }

216
source/cLavaSimulator.cpp Normal file
View File

@ -0,0 +1,216 @@
#include "cLavaSimulator.h"
#include "cWorld.h"
#include "Vector3i.h"
#include "BlockID.h"
#include <vector>
class cLavaSimulator::LavaData
{
public:
LavaData( cWorld* a_World )
: m_ActiveLava( new std::vector< Vector3i >() )
, m_Buffer( new std::vector< Vector3i >() )
, m_World( a_World )
{}
std::vector< Vector3i > GetLowestPoints( int a_X, int a_Y, int a_Z )
{
std::vector< Vector3i > Points;
if( m_World->GetBlock(a_X, a_Y-1, a_Z) == E_BLOCK_AIR )
{
Points.push_back( Vector3i( a_X, a_Y-1, a_Z ) );
return Points;
}
Vector3i LowerPoints [] = {
Vector3i( a_X-1, a_Y-1, a_Z ),
Vector3i( a_X+1, a_Y-1, a_Z ),
Vector3i( a_X, a_Y-1, a_Z-1 ),
Vector3i( a_X, a_Y-1, a_Z+1 ),
};
bool bLavaFound = false;
for( int i = 0; i < 4; ++i )
{
char Block1 = m_World->GetBlock( LowerPoints[i].x, LowerPoints[i].y, LowerPoints[i].z );
char Block2 = m_World->GetBlock( LowerPoints[i].x, a_Y, LowerPoints[i].z );
if( Block1 == E_BLOCK_AIR && Block2 == E_BLOCK_AIR )
{
Points.push_back( LowerPoints[i] );
LowerPoints[i].y = a_Y;
Points.push_back( LowerPoints[i] );
}
else if( (Block2 == E_BLOCK_LAVA || Block2 == E_BLOCK_STATIONARY_LAVA ) && ( Block1 == E_BLOCK_AIR || Block1 == E_BLOCK_LAVA || Block1 == E_BLOCK_STATIONARY_LAVA ) )
{
bLavaFound = true;
}
}
if( Points.size() == 0 && !bLavaFound )
{
Vector3i LevelPoints [] = {
Vector3i( a_X-1, a_Y, a_Z ),
Vector3i( a_X+1, a_Y, a_Z ),
Vector3i( a_X, a_Y, a_Z-1 ),
Vector3i( a_X, a_Y, a_Z+1 ),
};
for( int i = 0; i < 4; ++i )
{
char Block = m_World->GetBlock( LevelPoints[i].x, a_Y, LevelPoints[i].z );
if( Block == E_BLOCK_AIR || Block == E_BLOCK_LAVA || Block == E_BLOCK_STATIONARY_LAVA )
Points.push_back( LevelPoints[i] );
}
}
return Points;
}
std::vector< Vector3i >* m_ActiveLava;
std::vector< Vector3i >* m_Buffer;
cWorld* m_World;
};
cLavaSimulator::cLavaSimulator( cWorld* a_World )
: m_World( a_World )
, m_Data( new LavaData( a_World ) )
{
}
cLavaSimulator::~cLavaSimulator()
{
}
void cLavaSimulator::WakeUp( int a_X, int a_Y, int a_Z )
{
AddBlock( a_X, a_Y, a_Z );
AddBlock( a_X-1, a_Y, a_Z );
AddBlock( a_X+1, a_Y, a_Z );
AddBlock( a_X, a_Y-1, a_Z );
AddBlock( a_X, a_Y+1, a_Z );
AddBlock( a_X, a_Y, a_Z-1 );
AddBlock( a_X, a_Y, a_Z+1 );
}
void cLavaSimulator::AddBlock( int a_X, int a_Y, int a_Z )
{
// Check for duplicates
std::vector< Vector3i > & ActiveLava = *m_Data->m_ActiveLava;
for( std::vector< Vector3i >::iterator itr = ActiveLava.begin(); itr != ActiveLava.end(); ++itr )
{
Vector3i & pos = *itr;
if( pos.x == a_X && pos.y == a_Y && pos.z == a_Z )
return;
}
ActiveLava.push_back( Vector3i( a_X, a_Y, a_Z ) );
}
char cLavaSimulator::GetHighestLevelAround( int a_X, int a_Y, int a_Z )
{
char Max = 8;
#define __HIGHLEVEL_CHECK__( x, y, z ) \
if( IsLavaBlock( m_World->GetBlock( x, y, z ) ) ) \
{ \
char Meta; \
if( (Meta = m_World->GetBlockMeta( x, y, z ) ) < Max ) Max = Meta; \
else if( Meta == 8 ) Max = 0; \
if( Max == 0 ) return 0; \
}
__HIGHLEVEL_CHECK__( a_X-1, a_Y, a_Z );
__HIGHLEVEL_CHECK__( a_X+1, a_Y, a_Z );
__HIGHLEVEL_CHECK__( a_X, a_Y, a_Z-1 );
__HIGHLEVEL_CHECK__( a_X, a_Y, a_Z+1 );
return Max;
}
void cLavaSimulator::Simulate( float a_Dt )
{
m_Timer += a_Dt;
std::swap( m_Data->m_ActiveLava, m_Data->m_Buffer ); // Swap so blocks can be added to empty ActiveLava array
m_Data->m_ActiveLava->clear();
std::vector< Vector3i > & LavaBlocks = *m_Data->m_Buffer;
for( std::vector< Vector3i >::iterator itr = LavaBlocks.begin(); itr != LavaBlocks.end(); ++itr )
{
Vector3i & pos = *itr;
char BlockID = m_World->GetBlock( pos.x, pos.y, pos.z );
if( IsLavaBlock( BlockID ) ) // only care about lava
{
bool bIsFed = false;
char Meta = m_World->GetBlockMeta( pos.x, pos.y, pos.z );
char Feed = Meta;
if( Meta == 8 ) // Falling lava
{
if( IsLavaBlock( m_World->GetBlock(pos.x, pos.y+1, pos.z) ) ) // Block above is lava
{
bIsFed = true;
Meta = 0; // Make it a full block
}
}
else if( Meta <= 2 )
{
bIsFed = true;
}
else
{
if( (Feed = GetHighestLevelAround( pos.x, pos.y, pos.z )) < Meta )
bIsFed = true;
}
if( bIsFed )
{
char DownID = m_World->GetBlock( pos.x, pos.y-1, pos.z );
if( DownID == E_BLOCK_AIR || IsLavaBlock( DownID ) ) // free for Lava
{
m_World->FastSetBlock( pos.x, pos.y-1, pos.z, E_BLOCK_LAVA, 8 ); // falling
AddBlock( pos.x, pos.y-1, pos.z );
}
else // Not falling Lava
{
if( Feed+2 < Meta )
{
m_World->FastSetBlock( pos.x, pos.y, pos.z, E_BLOCK_LAVA, Feed+2 );
AddBlock( pos.x, pos.y, pos.z );
}
else if( Meta < 6 ) // 7 is only 1 unit high, so it cannot spread, lower than 7 can though.
{
std::vector< Vector3i > Points = m_Data->GetLowestPoints( pos.x, pos.y, pos.z );
for( std::vector< Vector3i >::iterator itr = Points.begin(); itr != Points.end(); ++itr )
{
Vector3i & p = *itr;
char BlockID = m_World->GetBlock( p.x, p.y, p.z );
if( !IsLavaBlock( BlockID ) )
{
if( p.y == pos.y )
m_World->FastSetBlock(p.x, p.y, p.z, E_BLOCK_LAVA, Meta+2);
else
m_World->FastSetBlock(p.x, p.y, p.z, E_BLOCK_LAVA, 8);
AddBlock( p.x, p.y, p.z );
}
else // it's Lava
{
char PointMeta = m_World->GetBlockMeta( p.x, p.y, p.z );
if( PointMeta > Meta+2 )
{
AddBlock( p.x, p.y, p.z );
}
}
}
}
}
}
else // not fed
{
m_World->FastSetBlock( pos.x, pos.y, pos.z, E_BLOCK_AIR, 0 );
WakeUp( pos.x, pos.y, pos.z );
}
}
}
}
bool cLavaSimulator::IsLavaBlock( char a_BlockID )
{
return a_BlockID == E_BLOCK_LAVA || a_BlockID == E_BLOCK_STATIONARY_LAVA;
}

25
source/cLavaSimulator.h Normal file
View File

@ -0,0 +1,25 @@
#pragma once
class Vector3i;
class cWorld;
class cLavaSimulator
{
public:
cLavaSimulator( cWorld* a_World );
~cLavaSimulator();
void Simulate( float a_Dt );
void WakeUp( int a_X, int a_Y, int a_Z );
private:
void AddBlock( int a_X, int a_Y, int a_Z);
char GetHighestLevelAround( int a_X, int a_Y, int a_Z );
bool IsLavaBlock( char a_BlockID );
float m_Timer;
cWorld* m_World;
class LavaData;
LavaData* m_Data;
};

View File

@ -474,22 +474,22 @@ void cMonster::InStateIdle(float a_Dt) {
void cMonster::InStateBurning(float a_Dt) { void cMonster::InStateBurning(float a_Dt) {
m_FireDamageInterval += a_Dt; m_FireDamageInterval += a_Dt;
char block = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z ); char block = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z );
char bblock = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y -1, (int)m_Pos->z ); char bblock = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y +1, (int)m_Pos->z );
if(m_FireDamageInterval > 1) { if(m_FireDamageInterval > 1) {
m_FireDamageInterval = 0; m_FireDamageInterval = 0;
int rem = rand()%3 + 1; //Burn most of the time TakeDamage(1, this);
if(rem >= 2) {
//printf("OUCH burning!!!\n");
TakeDamage(1, this);
}
m_BurnPeriod++; m_BurnPeriod++;
if(block == E_BLOCK_LAVA || block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_FIRE if(block == E_BLOCK_LAVA || block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_FIRE
|| bblock == E_BLOCK_LAVA || bblock == E_BLOCK_STATIONARY_LAVA || bblock == E_BLOCK_FIRE) || bblock == E_BLOCK_LAVA || bblock == E_BLOCK_STATIONARY_LAVA || bblock == E_BLOCK_FIRE) {
m_BurnPeriod = 0; m_BurnPeriod = 0;
TakeDamage(6, this);
}else{
TakeDamage(1, this);
}
if(m_BurnPeriod > 5) { if(m_BurnPeriod > 8) {
cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ );
m_EMMetaState = NORMAL; m_EMMetaState = NORMAL;
cPacket_Metadata md(NORMAL, GetUniqueID()); cPacket_Metadata md(NORMAL, GetUniqueID());

View File

@ -125,7 +125,8 @@ void cPickup::Tick(float a_Dt)
return; return;
} }
HandlePhysics( a_Dt ); if(!m_bCollected)
HandlePhysics( a_Dt );
if( !m_bReplicated || m_bDirtyPosition ) if( !m_bReplicated || m_bDirtyPosition )
{ {
@ -148,14 +149,18 @@ void cPickup::HandlePhysics(float a_Dt)
if( m_bOnGround ) // check if it's still on the ground if( m_bOnGround ) // check if it's still on the ground
{ {
cWorld* World = GetWorld(); cWorld* World = GetWorld();
int BlockX = (int)m_Pos->x; int BlockX = (m_Pos->x)<0 ? (int)m_Pos->x-1 : (int)m_Pos->x;
if( m_Pos->x < 0 ) BlockX--; int BlockZ = (m_Pos->z)<0 ? (int)m_Pos->z-1 : (int)m_Pos->z;
int BlockZ = (int)m_Pos->z;
if( m_Pos->z < 0 ) BlockZ--;
if( World->GetBlock( BlockX, (int)m_Pos->y -1, BlockZ ) == E_BLOCK_AIR ) if( World->GetBlock( BlockX, (int)m_Pos->y -1, BlockZ ) == E_BLOCK_AIR )
{ {
m_bOnGround = false; m_bOnGround = false;
} }
char block = World->GetBlock( BlockX, (int)m_Pos->y - (int)m_bOnGround, BlockZ );
if( block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_LAVA ) {
m_bCollected = true;
m_Timer = 0;
return;
}
if( World->GetBlock( BlockX, (int)m_Pos->y, BlockZ ) != E_BLOCK_AIR ) // If in ground itself, push it out if( World->GetBlock( BlockX, (int)m_Pos->y, BlockZ ) != E_BLOCK_AIR ) // If in ground itself, push it out
{ {
m_bOnGround = true; m_bOnGround = true;
@ -211,7 +216,7 @@ void cPickup::HandlePhysics(float a_Dt)
bool cPickup::CollectedBy( cPlayer* a_Dest ) bool cPickup::CollectedBy( cPlayer* a_Dest )
{ {
if(m_bCollected) return false; // It's already collected! if(m_bCollected) return false; // It's already collected!
if(m_Timer < 1000.f) return false; // Not old enough if(m_Timer < 800.f) return false; // Not old enough
if( cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_COLLECT_ITEM, 2, this, a_Dest ) ) return false; if( cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_COLLECT_ITEM, 2, this, a_Dest ) ) return false;

View File

@ -14,76 +14,67 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz )
//cWorld* World = cRoot::Get()->GetWorld(); //cWorld* World = cRoot::Get()->GetWorld();
char metadata = 0; char metadata = 0;
char extmetadata = 0; char extmetadata = 0;
int FirstFluidBlock = 0; int FirstFluidBlock = 0;
char piston; char piston;
piston = m_World->GetBlock( pistx, pisty, pistz ); piston = m_World->GetBlock( pistx, pisty, pistz );
printf("psPiston1\n");
if ( piston == E_BLOCK_STICKY_PISTON ) { if ( piston == E_BLOCK_STICKY_PISTON ) {
printf("psPiston2\n");
extmetadata = 8; extmetadata = 8;
}//if sticky piston than top nibble bit is set to 1; }//if sticky piston than top nibble's bit is set to 1;
if ( ( piston == E_BLOCK_STICKY_PISTON ) || ( piston == E_BLOCK_PISTON ) ) { if ( ( piston == E_BLOCK_STICKY_PISTON ) || ( piston == E_BLOCK_PISTON ) ) {
metadata = m_World->GetBlockMeta( pistx, pisty, pistz); metadata = m_World->GetBlockMeta( pistx, pisty, pistz);
printf("psPiston3\n");
printf("metadata %c\n",metadata);
if (metadata < 5) { //piston not extended if ((int)metadata < 6) { //piston not extended
switch ((int)metadata) {
printf("metadata %c\n",metadata);
metadata -= 8; //removing 8 from retracts it
switch (metadata) {
case 0: case 0:
FirstFluidBlock = FindFluidBlock ( pistx, pisty, pistz, pistx, pisty-16, pistz ); FirstFluidBlock = FindFluidBlock ( pistx, pisty-1, pistz, pistx, pisty-16, pistz );
if (FirstFluidBlock > 0) { if (FirstFluidBlock > 0) {
ChainMove ( pistx, pisty, pistz, pistx, pisty-FirstFluidBlock, pistz ); ChainMove ( pistx, pisty, pistz, pistx, pisty-FirstFluidBlock, pistz );
} }
m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 ); m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 );
m_World->FastSetBlock( pistx, pisty-1, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata ); m_World->SetBlock( pistx, pisty-1, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata );
break; break;
case 1: case 1:
FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz, pistx, pisty+16, pistz); FirstFluidBlock = FindFluidBlock (pistx, pisty+1, pistz, pistx, pisty+16, pistz);
if (FirstFluidBlock > 0) { if (FirstFluidBlock > 0) {
ChainMove ( pistx, pisty, pistz, pistx, pisty+FirstFluidBlock, pistz ); ChainMove ( pistx, pisty, pistz, pistx, pisty+FirstFluidBlock, pistz );
} }
m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 ); m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 );
m_World->FastSetBlock( pistx, pisty+1, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata+1 ); m_World->SetBlock( pistx, pisty+1, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata+1 );
break; break;
case 2: case 2:
FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz, pistx, pisty, pistz-16); FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz-1, pistx, pisty, pistz-16);
if (FirstFluidBlock > 0) { if (FirstFluidBlock > 0) {
ChainMove ( pistx, pisty, pistz, pistx, pisty, pistz-FirstFluidBlock ); ChainMove ( pistx, pisty, pistz, pistx, pisty, pistz-FirstFluidBlock );
} }
m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 ); m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 );
m_World->FastSetBlock( pistx, pisty, pistz-1, E_BLOCK_PISTON_EXTENSION, extmetadata+2 ); m_World->SetBlock( pistx, pisty, pistz-1, E_BLOCK_PISTON_EXTENSION, extmetadata+2 );
break; break;
case 3: case 3:
FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz, pistx, pisty, pistz+16); FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz+1, pistx, pisty, pistz+16);
if (FirstFluidBlock > 0) { if (FirstFluidBlock > 0) {
ChainMove ( pistx, pisty, pistz, pistx, pisty, pistz+FirstFluidBlock ); ChainMove ( pistx, pisty, pistz, pistx, pisty, pistz+FirstFluidBlock );
} }
m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 ); m_World->FastSetBlock( pistx, pisty, pistz, piston, (char)metadata + 8 );
m_World->FastSetBlock( pistx, pisty, pistz+1, E_BLOCK_PISTON_EXTENSION, extmetadata+3 ); m_World->SetBlock( pistx, pisty, pistz+1, E_BLOCK_PISTON_EXTENSION, extmetadata+3 );
break; break;
case 4: case 4:
FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz, pistx-16, pisty, pistz); FirstFluidBlock = FindFluidBlock (pistx-1, pisty, pistz, pistx-16, pisty, pistz);
if (FirstFluidBlock > 0) { if (FirstFluidBlock > 0) {
ChainMove ( pistx, pisty, pistz, pistx-FirstFluidBlock, pisty, pistz ); ChainMove ( pistx, pisty, pistz, pistx-FirstFluidBlock, pisty, pistz );
} }
m_World->FastSetBlock( pistx, pisty, pistz, piston, metadata + 8 ); m_World->FastSetBlock( pistx, pisty, pistz, piston, metadata + 8 );
m_World->FastSetBlock( pistx, pisty+1, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata+4 ); m_World->SetBlock( pistx-1, pisty, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata+4 );
break; break;
case 5: case 5:
FirstFluidBlock = FindFluidBlock (pistx, pisty, pistz, pistx+16, pisty, pistz); FirstFluidBlock = FindFluidBlock (pistx+1, pisty, pistz, pistx+16, pisty, pistz);
if (FirstFluidBlock > 0) { if (FirstFluidBlock > 0) {
ChainMove ( pistx, pisty, pistz, pistx+FirstFluidBlock, pisty, pistz ); ChainMove ( pistx, pisty, pistz, pistx+FirstFluidBlock, pisty, pistz );
} }
m_World->FastSetBlock( pistx, pisty, pistz, piston, metadata + 8 ); m_World->FastSetBlock( pistx, pisty, pistz, piston, metadata + 8 );
m_World->FastSetBlock( pistx, pisty+1, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata+5 ); m_World->SetBlock( pistx+1, pisty, pistz, E_BLOCK_PISTON_EXTENSION, extmetadata+5 );
break; break;
} }
} }
@ -93,9 +84,11 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz )
void cPiston::RetractPiston( int pistx, int pisty, int pistz ) void cPiston::RetractPiston( int pistx, int pisty, int pistz )
{ {
char metadata = m_World->GetBlockMeta( pistx, pisty, pistz); char metadata = m_World->GetBlockMeta( pistx, pisty, pistz);
char tempmeta;
char tempblock;
if ( (int)m_World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON ) { if ( (int)m_World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON ) {
if (metadata > 5) { //piston retracted if (metadata > 5) { //piston retracted
metadata -= 8;//set the piston to retracted state. metadata -= 8;//set the piston to retracted state.
m_World->FastSetBlock( pistx, pisty, pistz, m_World->GetBlock( pistx, pisty, pistz ), metadata ); m_World->FastSetBlock( pistx, pisty, pistz, m_World->GetBlock( pistx, pisty, pistz ), metadata );
@ -108,90 +101,102 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz )
case 1: case 1:
if ( m_World->GetBlock( pistx, pisty+1, pistz ) == E_BLOCK_PISTON_EXTENSION ) { if ( m_World->GetBlock( pistx, pisty+1, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
m_World->SetBlock( pistx, pisty+1, pistz, 0, 0 ); m_World->SetBlock( pistx, pisty+1, pistz, 0, 0 );
} }
break; break;
case 2: case 2:
if ( m_World->GetBlock( pistx, pisty, pistz-1 ) == E_BLOCK_PISTON_EXTENSION ) { if ( m_World->GetBlock( pistx, pisty, pistz-1 ) == E_BLOCK_PISTON_EXTENSION ) {
m_World->SetBlock( pistx, pisty, pistz-1, 0, 0 ); m_World->SetBlock( pistx, pisty, pistz-1, 0, 0 );
} }
break; break;
case 3: case 3:
if ( m_World->GetBlock( pistx, pisty, pistz+1 ) == E_BLOCK_PISTON_EXTENSION ) { if ( m_World->GetBlock( pistx, pisty, pistz+1 ) == E_BLOCK_PISTON_EXTENSION ) {
m_World->SetBlock( pistx, pisty, pistz+1, 0, 0 ); m_World->SetBlock( pistx, pisty, pistz+1, 0, 0 );
} }
break; break;
case 4: case 4:
if ( m_World->GetBlock( pistx-1, pisty, pistz ) == E_BLOCK_PISTON_EXTENSION ) { if ( m_World->GetBlock( pistx-1, pisty, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
m_World->SetBlock( pistx-1, pisty, pistz, 0, 0 ); m_World->SetBlock( pistx-1, pisty, pistz, 0, 0 );
} }
break; break;
case 5: case 5:
if ( m_World->GetBlock( pistx+1, pisty, pistz ) == E_BLOCK_PISTON_EXTENSION ) { if ( m_World->GetBlock( pistx+1, pisty, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
m_World->SetBlock( pistx+1, pisty, pistz, 0, 0 ); m_World->SetBlock( pistx+1, pisty, pistz, 0, 0 );
} }
break; break;
} }
} }
} }
if ( (int)m_World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_PISTON ) { if ( (int)m_World->GetBlock( pistx, pisty, pistz ) == E_BLOCK_STICKY_PISTON ) {
if (metadata > 5) { //piston retracted if (metadata > 5) { //piston retracted
metadata -= 8;//set the piston to retracted state. metadata -= 8;//set the piston to retracted state.
m_World->FastSetBlock( pistx, pisty, pistz, m_World->GetBlock( pistx, pisty, pistz ), metadata );
switch (metadata) {
case 0:
if ( m_World->GetBlock( pistx, pisty-1, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
tempblock = m_World->GetBlock( pistx, pisty-2, pistz );
tempmeta = m_World->GetBlockMeta( pistx, pisty-2, pistz );
m_World->SetBlock( pistx, pisty-1, pistz, 0, 0 );
m_World->SetBlock( pistx, pisty-1, pistz, tempblock, tempmeta );
m_World->SetBlock( pistx, pisty-2, pistz, 0, 0 );
}
break;
m_World->FastSetBlock( pistx, pisty, pistz, m_World->GetBlock( pistx, pisty, pistz ), metadata ); case 1:
switch (metadata) { if ( m_World->GetBlock( pistx, pisty+1, pistz ) == E_BLOCK_PISTON_EXTENSION ) {
case 0: tempblock = m_World->GetBlock( pistx, pisty+2, pistz );
if ( m_World->GetBlock( pistx, pisty-1, pistz ) == E_BLOCK_PISTON_EXTENSION ) { tempmeta = m_World->GetBlockMeta( pistx, pisty+2, pistz );
m_World->SetBlock( pistx, pisty-1, pistz, m_World->GetBlock( pistx, pisty-2, pistz ), m_World->GetBlockMeta( pistx, pisty-2, pistz ) ); m_World->SetBlock( pistx, pisty+1, pistz, 0, 0 );
m_World->SetBlock( pistx, pisty-2, pistz, 0, 0 ); m_World->SetBlock( pistx, pisty+1, pistz, tempblock , tempmeta );
} m_World->SetBlock( pistx, pisty+2, pistz, 0, 0 );
break; }
break;
case 1: case 2:
if ( m_World->GetBlock( pistx, pisty+1, pistz ) == E_BLOCK_PISTON_EXTENSION ) { if ( m_World->GetBlock( pistx, pisty, pistz-1) == E_BLOCK_PISTON_EXTENSION ) {
m_World->SetBlock( pistx, pisty-1, pistz, m_World->GetBlock( pistx, pisty-2, pistz ), m_World->GetBlockMeta( pistx, pisty-2, pistz ) ); tempblock = m_World->GetBlock( pistx, pisty, pistz-2 );
m_World->SetBlock( pistx, pisty-2, pistz, 0, 0 ); tempmeta = m_World->GetBlockMeta( pistx, pisty, pistz-2 );
} m_World->SetBlock( pistx, pisty, pistz-1, 0, 0 );
break; m_World->SetBlock( pistx, pisty, pistz-1, tempblock, tempmeta );
m_World->SetBlock( pistx, pisty, pistz-2, 0, 0 );
case 2: }
if ( m_World->GetBlock( pistx, pisty, pistz-1) == E_BLOCK_PISTON_EXTENSION ) { break;
m_World->SetBlock( pistx, pisty, pistz-1, m_World->GetBlock( pistx, pisty, pistz-2 ), m_World->GetBlockMeta( pistx, pisty, pistz-2 ) ); case 3:
m_World->SetBlock( pistx, pisty, pistz-2, 0, 0 ); if ( m_World->GetBlock( pistx, pisty, pistz+1) == E_BLOCK_PISTON_EXTENSION ) {
} tempblock = m_World->GetBlock( pistx, pisty, pistz+2 );
break; tempmeta = m_World->GetBlockMeta( pistx, pisty, pistz+2 );
m_World->SetBlock( pistx, pisty, pistz+1, 0, 0 );
case 3: m_World->SetBlock( pistx, pisty, pistz+1, tempblock, tempmeta );
if ( m_World->GetBlock( pistx, pisty, pistz+1) == E_BLOCK_PISTON_EXTENSION ) { m_World->SetBlock( pistx, pisty, pistz+2, 0, 0 );
m_World->SetBlock( pistx, pisty, pistz+1, m_World->GetBlock( pistx, pisty, pistz+2 ), m_World->GetBlockMeta( pistx, pisty, pistz+2 ) ); }
m_World->SetBlock( pistx, pisty, pistz+2, 0, 0 ); break;
} case 4:
break; if ( m_World->GetBlock( pistx-1, pisty, pistz) == E_BLOCK_PISTON_EXTENSION ) {
tempblock = m_World->GetBlock( pistx-2, pisty, pistz );
case 4: tempmeta = m_World->GetBlockMeta( pistx-2, pisty, pistz );
if ( m_World->GetBlock( pistx-1, pisty, pistz) == E_BLOCK_PISTON_EXTENSION ) { m_World->SetBlock( pistx-1, pisty, pistz, 0, 0 );
m_World->SetBlock( pistx-1, pisty, pistz, m_World->GetBlock( pistx-2, pisty, pistz ), m_World->GetBlockMeta( pistx-2, pisty, pistz ) ); m_World->SetBlock( pistx-1, pisty, pistz, tempblock, tempmeta );
m_World->SetBlock( pistx-2, pisty, pistz, 0, 0 ); m_World->SetBlock( pistx-2, pisty, pistz, 0, 0 );
} }
break; break;
case 5:
case 5: if ( m_World->GetBlock( pistx+1, pisty, pistz) == E_BLOCK_PISTON_EXTENSION ) {
if ( m_World->GetBlock( pistx+1, pisty, pistz) == E_BLOCK_PISTON_EXTENSION ) { tempblock = m_World->GetBlock( pistx+2, pisty, pistz );
m_World->SetBlock( pistx+1, pisty, pistz, m_World->GetBlock( pistx+2, pisty, pistz ), m_World->GetBlockMeta( pistx+2, pisty, pistz ) ); tempmeta = m_World->GetBlockMeta( pistx+2, pisty, pistz );
m_World->SetBlock( pistx+2, pisty, pistz, 0, 0 ); m_World->SetBlock( pistx+1, pisty, pistz, 0, 0 );
} m_World->SetBlock( pistx+1, pisty, pistz, tempblock, tempmeta );
break; m_World->SetBlock( pistx+2, pisty, pistz, 0, 0 );
}
} break;
} }
} }
}
} }
void cPiston::ChainMove ( int ax, int ay, int az, int bx, int by, int bz ) void cPiston::ChainMove ( int ax, int ay, int az, int bx, int by, int bz )
@ -202,27 +207,23 @@ char lastblock;
if ( ( ax != bx ) && ( ay == by ) && ( az == bz ) ) { //move x if ( ( ax != bx ) && ( ay == by ) && ( az == bz ) ) { //move x
if ( ax < bx ) { if ( ax > bx ) {
while ( ax > bx ) { while ( ax > bx ) {
lastmeta = m_World->GetBlockMeta( bx, by, bz);
lastmeta = m_World->GetBlockMeta( bx+1, by, bz); lastblock = m_World->GetBlock( bx, by, bz);
lastblock = m_World->GetBlockMeta( bx+1, by, bz); m_World->SetBlock( bx+1, by, bz, lastblock, lastmeta );
m_World->SetBlock( bx, by, bz, lastblock, lastmeta ); bx += 1;
bx+1;
} }
} else { } else {
while ( ax < bx ) { while ( ax < bx ) {
lastmeta = m_World->GetBlockMeta( bx, by, bz);
lastmeta = m_World->GetBlockMeta( bx-1, by, bz); lastblock = m_World->GetBlock( bx, by, bz);
lastblock = m_World->GetBlockMeta( bx-1, by, bz); m_World->SetBlock( bx+1, by, bz, lastblock, lastmeta );
m_World->SetBlock( bx, by, bz, lastblock, lastmeta ); bx -= 1;
bx-1; }
}
} }
@ -230,57 +231,49 @@ char lastblock;
} else if ( ( ax == bx ) && ( ay != by ) && ( az == bz ) ) { //move y } else if ( ( ax == bx ) && ( ay != by ) && ( az == bz ) ) { //move y
if ( ay < by ) { if ( ay > by ) {
while ( ay > by ) { while ( ay > by ) {
lastmeta = m_World->GetBlockMeta( bx, by, bz);
lastblock = m_World->GetBlock( bx, by, bz);
m_World->SetBlock( bx, by-1, bz, lastblock, lastmeta );
by += 1 ;
}
lastmeta = m_World->GetBlockMeta( bx, by+1, bz); } else {
lastblock = m_World->GetBlockMeta( bx, by+1, bz);
m_World->SetBlock( bx, by, bz, lastblock, lastmeta );
by+1;
} while ( ay < by ) {
lastmeta = m_World->GetBlockMeta( bx, by, bz);
lastblock = m_World->GetBlock( bx, by, bz);
m_World->SetBlock( bx, by+1, bz, lastblock, lastmeta );
by -= 1;
}
} else { }
while ( ay < by ) {
lastmeta = m_World->GetBlockMeta( bx, by-1, bz);
lastblock = m_World->GetBlockMeta( bx, by-1, bz);
m_World->SetBlock( bx, by, bz, lastblock, lastmeta );
by-1;
}
}
m_World->SetBlock( ax, ay, az, 0, 0 ); m_World->SetBlock( ax, ay, az, 0, 0 );
} else if ( ( ax == bx ) && ( ay == by ) && ( az != bz ) ) { //move z } else if ( ( ax == bx ) && ( ay == by ) && ( az != bz ) ) { //move z
if ( az < bz ) { if ( az > bz ) {
while ( az > bz ) { while ( az > bz ) {
lastmeta = m_World->GetBlockMeta( bx, by, bz );
lastblock = m_World->GetBlock( bx, by, bz );
m_World->SetBlock( bx, by, bz-1, lastblock, lastmeta );
bz += 1;
}
lastmeta = m_World->GetBlockMeta( bx, by, bz+1 ); } else {
lastblock = m_World->GetBlockMeta( bx, by, bz+1 );
m_World->SetBlock( bx, by, bz, lastblock, lastmeta );
bz+1;
} while ( az < bz ) {
lastmeta = m_World->GetBlockMeta( bx, by, bz );
lastblock = m_World->GetBlock( bx, by, bz );
m_World->SetBlock( bx, by, bz+1, lastblock, lastmeta );
bz -= 1;
}
} else { }
while ( az < bz ) {
lastmeta = m_World->GetBlockMeta( bx, by, bz-1 );
lastblock = m_World->GetBlockMeta( bx, by, bz-1 );
m_World->SetBlock( bx, by, bz, lastblock, lastmeta );
bz-1;
}
}
m_World->SetBlock( ax, ay, az, 0, 0 ); m_World->SetBlock( ax, ay, az, 0, 0 );
@ -299,104 +292,92 @@ int cPiston::FindFluidBlock ( int ax, int ay, int az, int bx, int by, int bz )
char thisblock; char thisblock;
int cnt = 0; int cnt = 0;
if ( ( ax != bx ) && ( ay == by ) && ( az == bz ) ) { //check x if ( ( ax != bx ) && ( ay == by ) && ( az == bz ) ) { //check x
if ( ax < bx ) { if ( ax < bx ) {
while ( ax < bx ) {
while ( ax < bx ) { thisblock = m_World->GetBlock( ax, ay, az);
if ( ((int)thisblock == 0) || ((int)thisblock == E_BLOCK_STATIONARY_WATER) || ((int)thisblock == E_BLOCK_WATER) || ((int)thisblock == E_BLOCK_STATIONARY_LAVA) || ((int)thisblock == E_BLOCK_LAVA) ) {
thisblock = m_World->GetBlock( ax, ay, az); return cnt;
if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
return cnt;
} }
cnt++; cnt++;
ax+1; ax += 1;
} }
} else { } else {
while ( ax > bx ) { while ( ax > bx ) {
thisblock = m_World->GetBlock( ax, ay, az);
thisblock = m_World->GetBlock( ax, ay, az); if ( ((int)thisblock == 0) || ((int)thisblock == E_BLOCK_STATIONARY_WATER) || ((int)thisblock == E_BLOCK_WATER) || ((int)thisblock == E_BLOCK_STATIONARY_LAVA) || ((int)thisblock == E_BLOCK_LAVA) ) {
if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) { return cnt;
return cnt;
} }
cnt++; cnt++;
ax-1; ax -= 1;
}
} }
} return cnt;
m_World->SetBlock( ax, ay, az, 0, 0 ); } else if ( ( ax == bx ) && ( ay != by ) && ( az == bz ) ) { //check y
} else if ( ( ax == bx ) && ( ay != by ) && ( az == bz ) ) { //check y if ( ay < by ) {
if ( ay < by ) { while ( ay < by ) {
thisblock = m_World->GetBlock( ax, ay, az);
while ( ay < by ) { if ( ((int)thisblock == 0) || ((int)thisblock == E_BLOCK_STATIONARY_WATER) || ((int)thisblock == E_BLOCK_WATER) || ((int)thisblock == E_BLOCK_STATIONARY_LAVA) || ((int)thisblock == E_BLOCK_LAVA) ) {
return cnt;
thisblock = m_World->GetBlock( bx, by, bz);
if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
return cnt;
} }
cnt++; cnt++;
ay+1; ay += 1;
}
} } else {
} else { while ( ay > by ) {
thisblock = m_World->GetBlock( ax, ay, az);
while ( ay > by ) { if ( ((int)thisblock == 0) || ((int)thisblock == E_BLOCK_STATIONARY_WATER) || ((int)thisblock == E_BLOCK_WATER) || ((int)thisblock == E_BLOCK_STATIONARY_LAVA) || ((int)thisblock == E_BLOCK_LAVA) ) {
return cnt;
thisblock = m_World->GetBlock( bx, by, bz);
if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
return cnt;
} }
cnt++; cnt++;
ay-1; ay -= 1;
}
} }
} return cnt;
m_World->SetBlock( ax, ay, az, 0, 0 ); } else if ( ( ax == bx ) && ( ay == by ) && ( az != bz ) ) { //check z
} else if ( ( ax == bx ) && ( ay == by ) && ( az != bz ) ) { //check z if ( az < bz ) {
if ( az < bz ) { while ( az < bz ) {
thisblock = m_World->GetBlock( ax, ay, az);
while ( az < bz ) { if ( ((int)thisblock == 0) || ((int)thisblock == E_BLOCK_STATIONARY_WATER) || ((int)thisblock == E_BLOCK_WATER) || ((int)thisblock == E_BLOCK_STATIONARY_LAVA) || ((int)thisblock == E_BLOCK_LAVA) ) {
return cnt;
thisblock = m_World->GetBlock( ax, ay, az);
if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
return cnt;
} }
cnt++; cnt++;
az+1; az += 1;
}
} } else {
} else { while ( az > bz ) {
thisblock = m_World->GetBlock( ax, ay, az);
while ( az > bz ) { if ( ((int)thisblock == 0) || ((int)thisblock == E_BLOCK_STATIONARY_WATER) || ((int)thisblock == E_BLOCK_WATER) || ((int)thisblock == E_BLOCK_STATIONARY_LAVA) || ((int)thisblock == E_BLOCK_LAVA) ) {
return cnt;
thisblock = m_World->GetBlock( ax, ay, az);
if ( (thisblock == 0) || (thisblock == E_BLOCK_STATIONARY_WATER) || (thisblock == E_BLOCK_WATER) || (thisblock == E_BLOCK_STATIONARY_LAVA) || (thisblock == E_BLOCK_LAVA) ) {
return cnt;
} }
cnt++; cnt++;
az-1; az -= 1;
}
} }
} return cnt;
} else { } else {
return cnt;
}
return cnt;
}
} }

View File

@ -40,7 +40,7 @@
#include <sys/types.h> #include <sys/types.h>
#define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__ ) #define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__ )
#endif #endif
#define float2int(x) ((x)<0 ? ((int)(x))-1 : (int)(x))
extern std::vector< std::string > StringSplit( std::string str, std::string delim); extern std::vector< std::string > StringSplit( std::string str, std::string delim);
CLASS_DEFINITION( cPlayer, cPawn ); CLASS_DEFINITION( cPlayer, cPawn );
@ -81,7 +81,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName)
m_TimeLastTeleportPacket = cWorld::GetTime(); m_TimeLastTeleportPacket = cWorld::GetTime();
m_TimeLastPickupCheck = cWorld::GetTime(); m_TimeLastPickupCheck = cWorld::GetTime();
m_pState->PlayerName = a_PlayerName; m_pState->PlayerName = a_PlayerName;
m_bDirtyPosition = true; // So chunks are streamed to player at spawn m_bDirtyPosition = true; // So chunks are streamed to player at spawn
@ -104,6 +104,7 @@ cPlayer::~cPlayer(void)
{ {
SaveToDisk(); SaveToDisk();
m_ClientHandle = 0; m_ClientHandle = 0;
CloseWindow(); CloseWindow();
if( m_Inventory ) if( m_Inventory )
{ {
@ -149,6 +150,7 @@ void cPlayer::Tick(float a_Dt)
InChunk->Broadcast( EntityLook, m_ClientHandle ); InChunk->Broadcast( EntityLook, m_ClientHandle );
m_bDirtyOrientation = false; m_bDirtyOrientation = false;
} }
if(m_bDirtyPosition ) if(m_bDirtyPosition )
{ {
cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_PLAYER_MOVE, 1, this ); cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_PLAYER_MOVE, 1, this );
@ -229,22 +231,21 @@ void cPlayer::Tick(float a_Dt)
void cPlayer::InStateBurning(float a_Dt) { void cPlayer::InStateBurning(float a_Dt) {
m_FireDamageInterval += a_Dt; m_FireDamageInterval += a_Dt;
char block = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z ); char block = GetWorld()->GetBlock( float2int(m_Pos->x), float2int(m_Pos->y), float2int(m_Pos->z) );
char bblock = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y -1, (int)m_Pos->z ); char bblock = GetWorld()->GetBlock( float2int(m_Pos->x), float2int(m_Pos->y)+1, float2int(m_Pos->z) );
if(m_FireDamageInterval > 1000) { if(m_FireDamageInterval > 800) {
m_FireDamageInterval = 0; m_FireDamageInterval = 0;
int rem = rand()%3 + 1; //Burn most of the time
if(rem >= 2) {
//printf("OUCH burning!!!\n");
TakeDamage(1, this);
}
m_BurnPeriod++; m_BurnPeriod++;
if(block == E_BLOCK_LAVA || block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_FIRE if(block == E_BLOCK_LAVA || block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_FIRE
|| bblock == E_BLOCK_LAVA || bblock == E_BLOCK_STATIONARY_LAVA || bblock == E_BLOCK_FIRE) || bblock == E_BLOCK_LAVA || bblock == E_BLOCK_STATIONARY_LAVA || bblock == E_BLOCK_FIRE) {
m_BurnPeriod = 0; m_BurnPeriod = 0;
TakeDamage(6, this);
if(m_BurnPeriod > 5) { }else{
TakeDamage(1, this);
}
if(m_BurnPeriod > 7) {
cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ );
e_EPMetaState = NORMAL; e_EPMetaState = NORMAL;
@ -261,14 +262,22 @@ void cPlayer::InStateBurning(float a_Dt) {
//----Change Entity MetaData //----Change Entity MetaData
void cPlayer::CheckMetaDataBurn() { void cPlayer::CheckMetaDataBurn() {
char block = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z ); char block = GetWorld()->GetBlock( float2int(m_Pos->x), float2int(m_Pos->y), float2int(m_Pos->z) );
char bblock = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y -1, (int)m_Pos->z ); char bblock = GetWorld()->GetBlock( float2int(m_Pos->x), float2int(m_Pos->y)+1, float2int(m_Pos->z) );
if(m_bBurnable && e_EPMetaState != BURNING && (block == E_BLOCK_LAVA || block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_FIRE if(e_EPMetaState == BURNING && (block == E_BLOCK_WATER || block == E_BLOCK_STATIONARY_WATER
|| bblock == E_BLOCK_WATER || bblock == E_BLOCK_STATIONARY_WATER)) {
cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ );
if(!InChunk)
return;
e_EPMetaState = NORMAL;
cPacket_Metadata md(NORMAL,GetUniqueID());
InChunk->Broadcast(md);
}else if(m_bBurnable && e_EPMetaState != BURNING && (block == E_BLOCK_LAVA || block == E_BLOCK_STATIONARY_LAVA || block == E_BLOCK_FIRE
|| bblock == E_BLOCK_LAVA || bblock == E_BLOCK_STATIONARY_LAVA || bblock == E_BLOCK_FIRE)) { || bblock == E_BLOCK_LAVA || bblock == E_BLOCK_STATIONARY_LAVA || bblock == E_BLOCK_FIRE)) {
cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ );
if(!InChunk) if(!InChunk)
return; return;
printf("I should burn"); printf("I should burn\n");
e_EPMetaState = BURNING; e_EPMetaState = BURNING;
cPacket_Metadata md(BURNING,GetUniqueID()); cPacket_Metadata md(BURNING,GetUniqueID());
InChunk->Broadcast(md); InChunk->Broadcast(md);
@ -282,7 +291,7 @@ void cPlayer::SetTouchGround( bool a_bTouchGround )
if( !m_bTouchGround ) if( !m_bTouchGround )
{ {
cWorld* World = GetWorld(); cWorld* World = GetWorld();
char BlockID = World->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z ); char BlockID = World->GetBlock( float2int(m_Pos->x), float2int(m_Pos->y), float2int(m_Pos->z) );
if( BlockID != E_BLOCK_AIR ) if( BlockID != E_BLOCK_AIR )
{ {
m_bTouchGround = true; m_bTouchGround = true;
@ -371,6 +380,7 @@ void cPlayer::Respawn()
//Packet.m_CreativeMode = (char)GetWorld()->GetGameMode(); //Packet.m_CreativeMode = (char)GetWorld()->GetGameMode();
Packet.m_CreativeMode = (char)m_GameMode; //Set GameMode packet based on Player's GameMode; Packet.m_CreativeMode = (char)m_GameMode; //Set GameMode packet based on Player's GameMode;
//Send Packet //Send Packet
e_EPMetaState = NORMAL;
m_ClientHandle->Send( Packet ); m_ClientHandle->Send( Packet );
TeleportTo( GetWorld()->GetSpawnX(), GetWorld()->GetSpawnY(), GetWorld()->GetSpawnZ() ); TeleportTo( GetWorld()->GetSpawnX(), GetWorld()->GetSpawnY(), GetWorld()->GetSpawnZ() );
SetVisible( true ); SetVisible( true );

View File

@ -64,13 +64,10 @@ void cRedstone::ChangeRedstoneTorch( int fillx, int filly, int fillz, bool added
void cRedstone::LightRedstone( int fillx, int filly, int fillz, char metadata) void cRedstone::LightRedstone( int fillx, int filly, int fillz, char metadata)
{ {
if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STICKY_PISTON ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_PISTON ) ) { if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_STICKY_PISTON ) || ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_PISTON ) ) {
printf("rsPiston 1\n");
cPiston Piston(m_World); cPiston Piston(m_World);
if (metadata > 0) { if (metadata > 0) {
printf("rsPiston 2\n");
Piston.ExtendPiston(fillx, filly, fillz); Piston.ExtendPiston(fillx, filly, fillz);
} else { } else {
printf("rsPiston 3\n");
Piston.RetractPiston(fillx, filly, fillz); Piston.RetractPiston(fillx, filly, fillz);
} }
} else if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz) != metadata ) ) { } else if ( ( (int)m_World->GetBlock( fillx, filly, fillz ) == E_BLOCK_REDSTONE_WIRE) && ( (int)m_World->GetBlockMeta( fillx, filly, fillz) != metadata ) ) {

View File

@ -13,6 +13,7 @@
#include "../iniFile/iniFile.h" #include "../iniFile/iniFile.h"
#include "cChunkMap.h" #include "cChunkMap.h"
#include "cWaterSimulator.h" #include "cWaterSimulator.h"
#include "cLavaSimulator.h"
#include "cChicken.h" #include "cChicken.h"
#include "cSpider.h" #include "cSpider.h"
#include "cCow.h" //cow #include "cCow.h" //cow
@ -47,6 +48,8 @@
#include <sys/types.h> #include <sys/types.h>
#endif #endif
float cWorld::m_Time = 0.f; float cWorld::m_Time = 0.f;
char g_BlockLightValue[128]; char g_BlockLightValue[128];
@ -94,6 +97,7 @@ cWorld::~cWorld()
UnlockEntities(); UnlockEntities();
delete m_WaterSimulator; delete m_WaterSimulator;
delete m_LavaSimulator;
UnloadUnusedChunks(); UnloadUnusedChunks();
delete m_ChunkMap; delete m_ChunkMap;
@ -114,9 +118,9 @@ cWorld::cWorld( const char* a_WorldName )
cMakeDir::MakeDir(m_pState->WorldName.c_str()); cMakeDir::MakeDir(m_pState->WorldName.c_str());
srand( (unsigned int) time(0) ); srand( (unsigned int) time(0) );
m_SpawnX = (double)((rand()%10000)-5000); m_SpawnX = (double)((rand()%1000)-500);
m_SpawnY = 128; m_SpawnY = 128;
m_SpawnZ = (double)((rand()%10000)-5000); m_SpawnZ = (double)((rand()%1000)-500);
m_WorldSeed = rand(); m_WorldSeed = rand();
m_GameMode = 0; m_GameMode = 0;
@ -187,6 +191,7 @@ cWorld::cWorld( const char* a_WorldName )
m_ChunksCriticalSection = new cCriticalSection(); m_ChunksCriticalSection = new cCriticalSection();
m_WaterSimulator = new cWaterSimulator( this ); m_WaterSimulator = new cWaterSimulator( this );
m_LavaSimulator = new cLavaSimulator( this );
memset( g_BlockLightValue, 0x0, 128 ); memset( g_BlockLightValue, 0x0, 128 );
memset( g_BlockSpreadLightFalloff, 0xf, 128 ); // 0xf means total falloff memset( g_BlockSpreadLightFalloff, 0xf, 128 ); // 0xf means total falloff
@ -263,6 +268,8 @@ void cWorld::Tick(float a_Dt)
{ {
m_Time+=a_Dt/1000.f; m_Time+=a_Dt/1000.f;
CurrentTick++;
bool bSendTime = false; bool bSendTime = false;
m_WorldTimeFraction+=a_Dt/1000.f; m_WorldTimeFraction+=a_Dt/1000.f;
while( m_WorldTimeFraction > 1.f ) while( m_WorldTimeFraction > 1.f )
@ -302,7 +309,10 @@ void cWorld::Tick(float a_Dt)
} }
m_ChunkMap->Tick(a_Dt); m_ChunkMap->Tick(a_Dt);
m_WaterSimulator->Simulate(a_Dt); if( CurrentTick % 6 == 0 )
m_WaterSimulator->Simulate(a_Dt);
if( CurrentTick % 12 == 0 )
m_LavaSimulator->Simulate(a_Dt);
UnlockChunks(); UnlockChunks();
if( m_Time - m_LastSave > 60*5 ) // Save each 5 minutes if( m_Time - m_LastSave > 60*5 ) // Save each 5 minutes
@ -499,6 +509,7 @@ cChunk* cWorld::GetChunkOfBlock( int a_X, int a_Y, int a_Z )
void cWorld::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ) void cWorld::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta )
{ {
m_WaterSimulator->WakeUp( a_X, a_Y, a_Z ); m_WaterSimulator->WakeUp( a_X, a_Y, a_Z );
m_LavaSimulator->WakeUp( a_X, a_Y, a_Z );
int ChunkX, ChunkY, ChunkZ; int ChunkX, ChunkY, ChunkZ;
AbsoluteToRelative( a_X, a_Y, a_Z, ChunkX, ChunkY, ChunkZ ); AbsoluteToRelative( a_X, a_Y, a_Z, ChunkX, ChunkY, ChunkZ );
@ -556,6 +567,7 @@ bool cWorld::DigBlock( int a_X, int a_Y, int a_Z, cItem & a_PickupItem )
{ {
DestChunk->SetBlock(PosX, PosY, PosZ, 0, 0 ); DestChunk->SetBlock(PosX, PosY, PosZ, 0, 0 );
m_WaterSimulator->WakeUp( a_X, a_Y, a_Z ); m_WaterSimulator->WakeUp( a_X, a_Y, a_Z );
m_LavaSimulator->WakeUp( a_X, a_Y, a_Z );
if( !a_PickupItem.IsEmpty() ) if( !a_PickupItem.IsEmpty() )
{ {

View File

@ -9,6 +9,7 @@ enum ENUM_ITEM_ID;
#include <list> #include <list>
class cWaterSimulator; class cWaterSimulator;
class cLavaSimulator;
class cChunkMap; class cChunkMap;
class cItem; class cItem;
class cCriticalSection; class cCriticalSection;
@ -140,10 +141,12 @@ private:
float m_LastSave; float m_LastSave;
static float m_Time; // Time in seconds static float m_Time; // Time in seconds
long long m_WorldTime; // Time in seconds*20, this is sent to clients (is wrapped) long long m_WorldTime; // Time in seconds*20, this is sent to clients (is wrapped)
unsigned long long CurrentTick;
int m_GameMode; int m_GameMode;
float m_WorldTimeFraction; // When this > 1.f m_WorldTime is incremented by 20 float m_WorldTimeFraction; // When this > 1.f m_WorldTime is incremented by 20
cWaterSimulator* m_WaterSimulator; cWaterSimulator* m_WaterSimulator;
cLavaSimulator* m_LavaSimulator;
cCriticalSection* m_ClientHandleCriticalSection; cCriticalSection* m_ClientHandleCriticalSection;
cCriticalSection* m_EntitiesCriticalSection; cCriticalSection* m_EntitiesCriticalSection;