From df7823280c2ef3096581741a3412b9b721a7e616 Mon Sep 17 00:00:00 2001 From: "admin@omencraft.com" Date: Thu, 10 Nov 2011 02:05:51 +0000 Subject: Added code for doors. Doors now place correctly but opening them is buggy and I need to change the current opening code to use bitwise operators. git-svn-id: http://mc-server.googlecode.com/svn/trunk@85 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 50 ++++++++++++++++++++++++++++++++++++++++-- source/cDoors.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ source/cWorld.cpp | 6 ++--- 3 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 source/cDoors.h (limited to 'source') diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index 7ce7e38c0..e06dc728a 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -14,6 +14,7 @@ #include "cItem.h" #include "cTorch.h" #include "cStairs.h" +#include "cDoors.h" #include "cLadder.h" #include "cSign.h" #include "cRedstone.h" @@ -708,6 +709,29 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) } } break; + case E_BLOCK_WOODEN_DOOR: + { + bPlaceBlock = false; + char OldMetaData = cRoot::Get()->GetWorld()->GetBlockMeta(PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ); + char NewMetaData = cDoors::ChangeStateMetaData ( OldMetaData ); + cRoot::Get()->GetWorld()->FastSetBlock(PacketData->m_PosX, PacketData->m_PosY, PacketData->m_PosZ, E_BLOCK_WOODEN_DOOR, NewMetaData ); + if ( (int)OldMetaData > 7 ) { //top of door + char BottomBlock = cRoot::Get()->GetWorld()->GetBlock(PacketData->m_PosX, PacketData->m_PosY-1, PacketData->m_PosZ); + char BottomMeta = cRoot::Get()->GetWorld()->GetBlockMeta(PacketData->m_PosX, PacketData->m_PosY-1, PacketData->m_PosZ); + if ( ( (int)BottomBlock == E_BLOCK_WOODEN_DOOR ) && ( (int)BottomMeta < 8 ) ) { + char NewBottomMeta = cDoors::ChangeStateMetaData ( BottomMeta ); + cRoot::Get()->GetWorld()->FastSetBlock(PacketData->m_PosX, PacketData->m_PosY-1, PacketData->m_PosZ, E_BLOCK_WOODEN_DOOR, NewBottomMeta ); + } + } else if ( (int)OldMetaData < 8 ) { //bottom of door + char TopBlock = cRoot::Get()->GetWorld()->GetBlock(PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ); + char TopMeta = cRoot::Get()->GetWorld()->GetBlockMeta(PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ); + if ( ( (int)TopBlock == E_BLOCK_WOODEN_DOOR ) && ( (int)TopMeta > 7 ) ) { + char NewTopMeta = cDoors::ChangeStateMetaData ( TopMeta ); + cRoot::Get()->GetWorld()->FastSetBlock(PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ, E_BLOCK_WOODEN_DOOR, NewTopMeta ); + } + } + } + break; default: break; }; @@ -722,6 +746,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) LOG("PacketData->m_ItemType: %i", (int)PacketData->m_ItemType); // Hacked in edible items go!~ bool bEat = false; + bool isDoor = false; switch( Item.m_ItemID ) { case E_ITEM_APPLE: @@ -817,6 +842,20 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) UpdateRedstone = true; AddedCurrent = false; break; + case E_ITEM_IRON_DOOR: + { + PacketData->m_ItemType = E_BLOCK_IRON_DOOR; + MetaData = cDoors::RotationToMetaData( m_Player->GetRotation() ); + isDoor = true; + } + break; + case E_ITEM_WOODEN_DOOR: + { + PacketData->m_ItemType = E_BLOCK_WOODEN_DOOR; + MetaData = cDoors::RotationToMetaData( m_Player->GetRotation() ); + isDoor = true; + } + break; case E_BLOCK_COBBLESTONE_STAIRS: case E_BLOCK_BRICK_STAIRS: case E_BLOCK_STONE_BRICK_STAIRS: @@ -857,8 +896,15 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) if( (m_Player->GetGameMode() == 1) || (m_Player->GetInventory().RemoveItem( Item )) ) { - - m_Player->GetWorld()->SetBlock( X, Y, Z, (char)PacketData->m_ItemType, MetaData ); + if (isDoor) { + if ( ( m_Player->GetWorld()->GetBlock( X, Y+1, Z ) == E_BLOCK_AIR ) || ( m_Player->GetWorld()->GetBlock( X, Y+1, Z ) == E_BLOCK_AIR ) ) { + m_Player->GetWorld()->SetBlock( X, Y+1, Z, (char)PacketData->m_ItemType, MetaData + 8 ); + + m_Player->GetWorld()->SetBlock( X, Y, Z, (char)PacketData->m_ItemType, MetaData ); + } + } else { + m_Player->GetWorld()->SetBlock( X, Y, Z, (char)PacketData->m_ItemType, MetaData ); + } if (UpdateRedstone) { cRedstone Redstone(m_Player->GetWorld()); Redstone.ChangeRedstone( PacketData->m_PosX, PacketData->m_PosY+1, PacketData->m_PosZ, AddedCurrent ); diff --git a/source/cDoors.h b/source/cDoors.h new file mode 100644 index 000000000..a05bdd06e --- /dev/null +++ b/source/cDoors.h @@ -0,0 +1,57 @@ +#pragma once + +class cDoors //tolua_export +{ //tolua_export +public: + static char RotationToMetaData( float a_Rotation ) //tolua_export + { //tolua_export + a_Rotation += 90 + 45; // So its not aligned with axis + if( a_Rotation > 360.f ) a_Rotation -= 360.f; + if( a_Rotation >= 0.f && a_Rotation < 90.f ) + return 0x0; + else if( a_Rotation >= 180 && a_Rotation < 270 ) + return 0x2; + else if( a_Rotation >= 90 && a_Rotation < 180 ) + return 0x1; + else + return 0x3; + } //tolua_export + + static char ChangeStateMetaData( char MetaData ) //tolua_export + { //tolua_export + if ( (int)MetaData == 0 ) { //todo, condense this code. lol + return 0x4; + } else if ( (int)MetaData == 1 ) { + return 0x5; + } else if ( (int)MetaData == 2 ) { + return 0x6; + } else if ( (int)MetaData == 3 ) { + return 0x7; + } else if ( (int)MetaData == 4 ) { + return 0x0; + } else if ( (int)MetaData == 5 ) { + return 0x1; + } else if ( (int)MetaData == 6 ) { + return 0x2; + } else if ( (int)MetaData == 7 ) { + return 0x3; + } else if ( (int)MetaData == 8 ) { + return 0x12; + } else if ( (int)MetaData == 9 ) { + return 0x13; + } else if ( (int)MetaData == 10 ) { + return 0x14; + } else if ( (int)MetaData == 11 ) { + return 0x15; + } else if ( (int)MetaData == 12 ) { + return 0x8; + } else if ( (int)MetaData == 13 ) { + return 0x9; + } else if ( (int)MetaData == 14 ) { + return 0x10; + } else if ( (int)MetaData == 15 ) { + return 0x11; + } + } //tolua_export + +}; //tolua_export \ No newline at end of file diff --git a/source/cWorld.cpp b/source/cWorld.cpp index d914cf05d..65c35535b 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -394,7 +394,7 @@ void cWorld::Tick(float a_Dt) ////////////////Weather/////////////////////// if ( GetWeather() == 0 ) { //if sunny if( CurrentTick % 19 == 0 ) { //every 20 ticks random weather - randWeather = (rand() %1000); + randWeather = (rand() %10000); if (randWeather == 0) { LOG("Starting Rainstorm!"); SetWeather ( 1 ); @@ -407,11 +407,11 @@ void cWorld::Tick(float a_Dt) if ( GetWeather() != 0 ) { //if raining or thunderstorm if( CurrentTick % 19 == 0 ) { //every 20 ticks random weather - randWeather = (rand() %499); + randWeather = (rand() %4999); if (randWeather == 0) { //2% chance per second LOG("Back to sunny!"); SetWeather ( 0 ); - } else if ( (randWeather > 400) && (GetWeather() != 2) ) { //random chance for rainstorm to turn into thunderstorm. + } else if ( (randWeather > 4000) && (GetWeather() != 2) ) { //random chance for rainstorm to turn into thunderstorm. LOG("Starting Thunderstorm!"); SetWeather ( 2 ); } -- cgit v1.2.3