1
0
Fork 0

Fixed a few Clang warnings in BlockHandlers.

This commit is contained in:
madmaxoft 2014-03-30 23:13:13 +02:00
parent a5c0600e6c
commit 8288e53c0b
11 changed files with 54 additions and 48 deletions

View File

@ -33,16 +33,16 @@ public:
a_BlockType = m_BlockType;
int Direction = (int)floor(a_Player->GetYaw() * 4.0 / 360.0 + 0.5) & 0x3;
int RawMeta = a_BlockMeta >> 2;
NIBBLETYPE RawMeta = a_BlockMeta >> 2;
Direction++;
Direction %= 4;
switch (Direction)
{
case 0: a_BlockMeta = 0x2 | RawMeta << 2; break;
case 1: a_BlockMeta = 0x3 | RawMeta << 2; break;
case 2: a_BlockMeta = 0x0 | RawMeta << 2; break;
case 3: a_BlockMeta = 0x1 | RawMeta << 2; break;
case 0: a_BlockMeta = 0x2 | (RawMeta << 2); break;
case 1: a_BlockMeta = 0x3 | (RawMeta << 2); break;
case 2: a_BlockMeta = 0x0 | (RawMeta << 2); break;
case 3: a_BlockMeta = 0x1 | (RawMeta << 2); break;
default:
{
return false;

View File

@ -23,7 +23,7 @@ public:
virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
char Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
switch (a_Player->GetEquippedItem().m_ItemType)
{
case E_ITEM_WATER_BUCKET:

View File

@ -2,7 +2,7 @@
#pragma once
#include "BlockHandler.h"
#include "../MersenneTwister.h"
#include "../FastRandom.h"
@ -21,7 +21,7 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_Meta) override
{
MTRand rand;
cFastRandom rand;
if (a_Meta == 0x7)
{
@ -31,18 +31,18 @@ public:
case E_BLOCK_CROPS:
{
a_Pickups.push_back(cItem(E_ITEM_WHEAT, 1, 0));
a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1 + (int)(rand.randInt(2) + rand.randInt(2)) / 2, 0)); // [1 .. 3] with high preference of 2
a_Pickups.push_back(cItem(E_ITEM_SEEDS, (char)(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2
break;
}
case E_BLOCK_CARROTS:
{
a_Pickups.push_back(cItem(E_ITEM_CARROT, 1 + (int)(rand.randInt(2) + rand.randInt(2)) / 2, 0)); // [1 .. 3] with high preference of 2
a_Pickups.push_back(cItem(E_ITEM_CARROT, (char)(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2
break;
}
case E_BLOCK_POTATOES:
{
a_Pickups.push_back(cItem(E_ITEM_POTATO, 1 + (int)(rand.randInt(2) + rand.randInt(2)) / 2, 0)); // [1 .. 3] with high preference of 2
if (rand.randInt(20) == 0)
a_Pickups.push_back(cItem(E_ITEM_POTATO, (char)(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2
if (rand.NextInt(21) == 0)
{
// With a 5% chance, drop a poisonous potato as well
a_Pickups.push_back(cItem(E_ITEM_POISONOUS_POTATO, 1, 0));

View File

@ -2,7 +2,7 @@
#pragma once
#include "BlockHandler.h"
#include "../MersenneTwister.h"
#include "../FastRandom.h"
@ -44,12 +44,12 @@ public:
}
// Grass spreads to adjacent dirt blocks:
MTRand rand; // TODO: Replace with cFastRandom
cFastRandom rand;
for (int i = 0; i < 2; i++) // Pick two blocks to grow to
{
int OfsX = rand.randInt(2) - 1; // [-1 .. 1]
int OfsY = rand.randInt(4) - 3; // [-3 .. 1]
int OfsZ = rand.randInt(2) - 1; // [-1 .. 1]
int OfsX = rand.NextInt(3, a_RelX) - 1; // [-1 .. 1]
int OfsY = rand.NextInt(5, a_RelY) - 3; // [-3 .. 1]
int OfsZ = rand.NextInt(3, a_RelZ) - 1; // [-1 .. 1]
BLOCKTYPE DestBlock;
NIBBLETYPE DestMeta;

View File

@ -17,25 +17,27 @@ public:
}
/// Portal boundary and direction variables
int XZP, XZM, Dir; // For wont of a better name...
// 2014_03_30 _X: What are these used for? Why do we need extra variables?
int XZP, XZM;
NIBBLETYPE Dir;
virtual void OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
{
/*
PORTAL FINDING ALGORITH
=======================
-Get clicked base block
-Trace upwards to find first obsidian block; aborts if anything other than obsidian or air is encountered.
Uses this value as a reference (the 'ceiling')
-For both directions (if one fails, try the other), BASE (clicked) block:
-Go in one direction, only stop if a non obsidian block is encountered (abort) OR a portal border is encountered (FindObsidianCeiling returns -1)
-If a border was encountered, go the other direction and repeat above
-Write borders to XZP and XZM, write direction portal faces to Dir
-Loop through boundary variables, and fill with portal blocks based on Dir with meta from Dir
- Get clicked base block
- Trace upwards to find first obsidian block; aborts if anything other than obsidian or air is encountered.
Uses this value as a reference (the 'ceiling')
- For both directions (if one fails, try the other), BASE (clicked) block:
- Go in one direction, only stop if a non obsidian block is encountered (abort) OR a portal border is encountered (FindObsidianCeiling returns -1)
- If a border was encountered, go the other direction and repeat above
- Write borders to XZP and XZM, write direction portal faces to Dir
- Loop through boundary variables, and fill with portal blocks based on Dir with meta from Dir
*/
a_BlockY--; // Because we want the block below the fire
FindAndSetPortalFrame(a_BlockX, a_BlockY, a_BlockZ, a_ChunkInterface, a_WorldInterface); // Brought to you by Aperture Science
FindAndSetPortalFrame(a_BlockX, a_BlockY, a_BlockZ, a_ChunkInterface, a_WorldInterface);
}
virtual void OnDigging(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override

View File

@ -1,6 +1,6 @@
#pragma once
#include "BlockHandler.h"
#include "../MersenneTwister.h"
#include "../FastRandom.h"
#include "../World.h"
#include "../BlockArea.h"
@ -37,16 +37,18 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
MTRand rand;
cFastRandom rand;
// Only the first 2 bits contain the display information, the others are for growing
if (rand.randInt(5) == 0)
if (rand.NextInt(6) == 0)
{
a_Pickups.push_back(cItem(E_BLOCK_SAPLING, 1, a_BlockMeta & 3));
}
if ((a_BlockMeta & 3) == E_META_SAPLING_APPLE)
// 1 % chance of dropping an apple, if the leaves' type is Apple Leaves
if ((a_BlockMeta & 3) == E_META_LEAVES_APPLE)
{
if (rand.rand(100) == 0)
if (rand.NextInt(101) == 0)
{
a_Pickups.push_back(cItem(E_ITEM_RED_APPLE, 1, 0));
}
@ -58,11 +60,10 @@ public:
{
cBlockHandler::OnDestroyed(a_ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ);
//0.5% chance of dropping an apple
// 0.5% chance of dropping an apple, if the leaves' type is Apple Leaves:
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
//check if Oak (0x1 and 0x2 bit not set)
MTRand rand;
if(!(Meta & 3) && rand.randInt(200) == 100)
cFastRandom rand;
if (((Meta & 3) == E_META_LEAVES_APPLE) && (rand.NextInt(201) == 100))
{
cItems Drops;
Drops.push_back(cItem(E_ITEM_RED_APPLE, 1, 0));

View File

@ -62,8 +62,8 @@ public:
}
public:
cCallback (cPlayer * a_Player, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) :
m_Player(a_Player),
cCallback (cPlayer * a_CBPlayer, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) :
m_Player(a_CBPlayer),
m_OldBlockMeta(a_OldBlockMeta),
m_NewBlockMeta(a_NewBlockMeta)
{}

View File

@ -2,14 +2,13 @@
#pragma once
#include "BlockHandler.h"
#include "../MersenneTwister.h"
#include "../FastRandom.h"
#include "../World.h"
/// Common class that takes care of carrots, potatoes and wheat
class cBlockNetherWartHandler :
public cBlockHandler
{
@ -22,12 +21,12 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_Meta) override
{
MTRand rand;
cFastRandom rand;
if (a_Meta == 0x7)
{
// Is fully grown, drop the entire produce:
a_Pickups.push_back(cItem(E_ITEM_NETHER_WART, 1 + (int)(rand.randInt(2) + rand.randInt(2)) / 2, 0));
// Fully grown, drop the entire produce:
a_Pickups.push_back(cItem(E_ITEM_NETHER_WART, (char)(1 + (rand.NextInt(3) + rand.NextInt(3))) / 2, 0));
}
else
{
@ -35,18 +34,20 @@ public:
}
}
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
NIBBLETYPE Meta = a_Chunk.GetMeta (a_RelX, a_RelY, a_RelZ);
NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
if (Meta < 7)
{
a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_NETHER_WART, ++Meta);
}
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
// Needs to be placed on top of a Soulsand block:
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_SOULSAND));
}
} ;

View File

@ -431,6 +431,7 @@ public:
}
break;
}
default: break;
}
return true;
}

View File

@ -17,9 +17,10 @@ public:
{
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
int ItemType = (m_BlockType == E_BLOCK_MELON_STEM) ? E_ITEM_MELON_SEEDS : E_ITEM_PUMPKIN_SEEDS;
short ItemType = (m_BlockType == E_BLOCK_MELON_STEM) ? E_ITEM_MELON_SEEDS : E_ITEM_PUMPKIN_SEEDS;
a_Pickups.push_back(cItem(ItemType, 1, 0));
}

View File

@ -83,7 +83,7 @@ public:
static const struct
{
int x, z;
int Bit;
NIBBLETYPE Bit;
} Coords[] =
{
{ 0, 1, 1}, // south, ZP
@ -91,7 +91,7 @@ public:
{ 0, -1, 4}, // north, ZM
{ 1, 0, 8}, // east, XP
} ;
int res = 0;
NIBBLETYPE res = 0;
for (size_t i = 0; i < ARRAYCOUNT(Coords); i++)
{
BLOCKTYPE BlockType;