Implemented redstone comparators
They can be placed and toggled, but stills needs proper redstone support
This commit is contained in:
parent
480991d1ac
commit
846f1223f4
@ -2027,6 +2027,14 @@
|
||||
RelativePath="..\source\Blocks\BlockCobWeb.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\Blocks\BlockComparator.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\Blocks\BlockComparator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\blocks\BlockCrops.h"
|
||||
>
|
||||
@ -2283,6 +2291,10 @@
|
||||
RelativePath="..\source\items\ItemCloth.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\Items\ItemComparator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\items\ItemDoor.h"
|
||||
>
|
||||
|
@ -630,11 +630,13 @@ public:
|
||||
// TODO: Any other transparent blocks?
|
||||
|
||||
// One hit break blocks
|
||||
g_BlockOneHitDig[E_BLOCK_ACTIVE_COMPARATOR] = true;
|
||||
g_BlockOneHitDig[E_BLOCK_BROWN_MUSHROOM] = true;
|
||||
g_BlockOneHitDig[E_BLOCK_CARROTS] = true;
|
||||
g_BlockOneHitDig[E_BLOCK_CROPS] = true;
|
||||
g_BlockOneHitDig[E_BLOCK_FIRE] = true;
|
||||
g_BlockOneHitDig[E_BLOCK_FLOWER_POT] = true;
|
||||
g_BlockOneHitDig[E_BLOCK_INACTIVE_COMPARATOR] = true;
|
||||
g_BlockOneHitDig[E_BLOCK_LOCKED_CHEST] = true;
|
||||
g_BlockOneHitDig[E_BLOCK_MELON_STEM] = true;
|
||||
g_BlockOneHitDig[E_BLOCK_POTATOES] = true;
|
||||
@ -655,6 +657,7 @@ public:
|
||||
g_BlockOneHitDig[E_BLOCK_YELLOW_FLOWER] = true;
|
||||
|
||||
// Blocks that breaks when pushed by piston
|
||||
g_BlockPistonBreakable[E_BLOCK_ACTIVE_COMPARATOR] = true;
|
||||
g_BlockPistonBreakable[E_BLOCK_AIR] = true;
|
||||
g_BlockPistonBreakable[E_BLOCK_BED] = true;
|
||||
g_BlockPistonBreakable[E_BLOCK_BROWN_MUSHROOM] = true;
|
||||
@ -662,6 +665,7 @@ public:
|
||||
g_BlockPistonBreakable[E_BLOCK_CROPS] = true;
|
||||
g_BlockPistonBreakable[E_BLOCK_DEAD_BUSH] = true;
|
||||
g_BlockPistonBreakable[E_BLOCK_FIRE] = true;
|
||||
g_BlockPistonBreakable[E_BLOCK_INACTIVE_COMPARATOR] = true;
|
||||
g_BlockPistonBreakable[E_BLOCK_IRON_DOOR] = true;
|
||||
g_BlockPistonBreakable[E_BLOCK_JACK_O_LANTERN] = true;
|
||||
g_BlockPistonBreakable[E_BLOCK_LADDER] = true;
|
||||
@ -694,6 +698,7 @@ public:
|
||||
|
||||
|
||||
// Blocks that can be snowed over:
|
||||
g_BlockIsSnowable[E_BLOCK_ACTIVE_COMPARATOR] = false;
|
||||
g_BlockIsSnowable[E_BLOCK_AIR] = false;
|
||||
g_BlockIsSnowable[E_BLOCK_BROWN_MUSHROOM] = false;
|
||||
g_BlockIsSnowable[E_BLOCK_CACTUS] = false;
|
||||
@ -702,6 +707,7 @@ public:
|
||||
g_BlockIsSnowable[E_BLOCK_FIRE] = false;
|
||||
g_BlockIsSnowable[E_BLOCK_GLASS] = false;
|
||||
g_BlockIsSnowable[E_BLOCK_ICE] = false;
|
||||
g_BlockIsSnowable[E_BLOCK_INACTIVE_COMPARATOR] = false;
|
||||
g_BlockIsSnowable[E_BLOCK_LAVA] = false;
|
||||
g_BlockIsSnowable[E_BLOCK_LILY_PAD] = false;
|
||||
g_BlockIsSnowable[E_BLOCK_LOCKED_CHEST] = false;
|
||||
|
64
source/Blocks/BlockComparator.cpp
Normal file
64
source/Blocks/BlockComparator.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
#include "Globals.h"
|
||||
#include "BlockComparator.h"
|
||||
#include "../Item.h"
|
||||
#include "../World.h"
|
||||
#include "../Simulator/RedstoneSimulator.h"
|
||||
#include "../Entities/Player.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cBlockComparatorHandler::cBlockComparatorHandler(BLOCKTYPE a_BlockType)
|
||||
: cBlockHandler(a_BlockType)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cBlockComparatorHandler::OnDestroyed(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ)
|
||||
{
|
||||
// Nothing needed yet
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cBlockComparatorHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
|
||||
{
|
||||
NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
|
||||
Meta ^= 0x04; // Toggle 3rd (addition/subtraction) bit with XOR
|
||||
a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cBlockComparatorHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
|
||||
{
|
||||
OnUse(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NONE, 8, 8, 8);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool cBlockComparatorHandler::GetPlacementBlockTypeMeta(
|
||||
cWorld * a_World, cPlayer * a_Player,
|
||||
int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
|
||||
int a_CursorX, int a_CursorY, int a_CursorZ,
|
||||
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
||||
)
|
||||
{
|
||||
a_BlockType = m_BlockType;
|
||||
a_BlockMeta = cRedstoneSimulator::RepeaterRotationToMetaData(a_Player->GetRotation());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
57
source/Blocks/BlockComparator.h
Normal file
57
source/Blocks/BlockComparator.h
Normal file
@ -0,0 +1,57 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BlockHandler.h"
|
||||
#include "../World.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cBlockComparatorHandler :
|
||||
public cBlockHandler
|
||||
{
|
||||
public:
|
||||
cBlockComparatorHandler(BLOCKTYPE a_BlockType);
|
||||
virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override;
|
||||
|
||||
virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override;
|
||||
virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override;
|
||||
|
||||
|
||||
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
||||
{
|
||||
// Reset meta to 0
|
||||
a_Pickups.push_back(cItem(E_ITEM_COMPARATOR, 1, 0));
|
||||
}
|
||||
|
||||
|
||||
virtual bool IsUseable(void) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
||||
{
|
||||
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR));
|
||||
}
|
||||
|
||||
|
||||
virtual bool GetPlacementBlockTypeMeta(
|
||||
cWorld * a_World, cPlayer * a_Player,
|
||||
int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
|
||||
int a_CursorX, int a_CursorY, int a_CursorZ,
|
||||
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
||||
) override;
|
||||
|
||||
|
||||
virtual const char * GetStepSound(void) override
|
||||
{
|
||||
return "step.wood";
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "BlockChest.h"
|
||||
#include "BlockCloth.h"
|
||||
#include "BlockCobWeb.h"
|
||||
#include "BlockComparator.h"
|
||||
#include "BlockCrops.h"
|
||||
#include "BlockDeadBush.h"
|
||||
#include "BlockDirt.h"
|
||||
@ -110,6 +111,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
|
||||
case E_BLOCK_CAULDRON: return new cBlockCauldronHandler (a_BlockType);
|
||||
case E_BLOCK_CHEST: return new cBlockChestHandler (a_BlockType);
|
||||
case E_BLOCK_COAL_ORE: return new cBlockOreHandler (a_BlockType);
|
||||
case E_BLOCK_ACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType);
|
||||
case E_BLOCK_COBBLESTONE: return new cBlockStoneHandler (a_BlockType);
|
||||
case E_BLOCK_COBBLESTONE_STAIRS: return new cBlockStairsHandler (a_BlockType);
|
||||
case E_BLOCK_COBWEB: return new cBlockCobWebHandler (a_BlockType);
|
||||
@ -124,7 +126,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
|
||||
case E_BLOCK_DROPPER: return new cBlockDropSpenserHandler (a_BlockType);
|
||||
case E_BLOCK_EMERALD_ORE: return new cBlockOreHandler (a_BlockType);
|
||||
case E_BLOCK_ENDER_CHEST: return new cBlockEnderchestHandler (a_BlockType);
|
||||
case E_BLOCK_FARMLAND: return new cBlockFarmlandHandler;
|
||||
case E_BLOCK_FARMLAND: return new cBlockFarmlandHandler ( );
|
||||
case E_BLOCK_FENCE_GATE: return new cBlockFenceGateHandler (a_BlockType);
|
||||
case E_BLOCK_FIRE: return new cBlockFireHandler (a_BlockType);
|
||||
case E_BLOCK_FLOWER_POT: return new cBlockFlowerPotHandler (a_BlockType);
|
||||
@ -136,6 +138,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
|
||||
case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType);
|
||||
case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType);
|
||||
case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType);
|
||||
case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType);
|
||||
case E_BLOCK_IRON_DOOR: return new cBlockDoorHandler (a_BlockType);
|
||||
case E_BLOCK_IRON_ORE: return new cBlockOreHandler (a_BlockType);
|
||||
case E_BLOCK_JUKEBOX: return new cBlockEntityHandler (a_BlockType);
|
||||
@ -153,7 +156,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
|
||||
case E_BLOCK_NETHER_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType);
|
||||
case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (a_BlockType);
|
||||
case E_BLOCK_PISTON: return new cBlockPistonHandler (a_BlockType);
|
||||
case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler ();
|
||||
case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler ( );
|
||||
case E_BLOCK_PLANKS: return new cBlockPlanksHandler (a_BlockType);
|
||||
case E_BLOCK_PUMPKIN: return new cBlockPumpkinHandler (a_BlockType);
|
||||
case E_BLOCK_JACK_O_LANTERN: return new cBlockPumpkinHandler (a_BlockType);
|
||||
|
40
source/Items/ItemComparator.h
Normal file
40
source/Items/ItemComparator.h
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ItemHandler.h"
|
||||
#include "../Simulator/RedstoneSimulator.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cItemComparatorHandler :
|
||||
public cItemHandler
|
||||
{
|
||||
public:
|
||||
cItemComparatorHandler(int a_ItemType) :
|
||||
cItemHandler(a_ItemType)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool GetPlacementBlockTypeMeta(
|
||||
cWorld * a_World, cPlayer * a_Player,
|
||||
int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
|
||||
int a_CursorX, int a_CursorY, int a_CursorZ,
|
||||
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
||||
) override
|
||||
{
|
||||
a_BlockType = E_BLOCK_INACTIVE_COMPARATOR;
|
||||
a_BlockMeta = cRedstoneSimulator::RepeaterRotationToMetaData(a_Player->GetRotation());
|
||||
return true;
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "ItemBucket.h"
|
||||
#include "ItemCauldron.h"
|
||||
#include "ItemCloth.h"
|
||||
#include "ItemComparator.h"
|
||||
#include "ItemDoor.h"
|
||||
#include "ItemDye.h"
|
||||
#include "ItemFlowerPot.h"
|
||||
@ -92,6 +93,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
|
||||
case E_ITEM_BOW: return new cItemBowHandler;
|
||||
case E_ITEM_BREWING_STAND: return new cItemBrewingStandHandler(a_ItemType);
|
||||
case E_ITEM_CAULDRON: return new cItemCauldronHandler(a_ItemType);
|
||||
case E_ITEM_COMPARATOR: return new cItemComparatorHandler(a_ItemType);
|
||||
case E_ITEM_DYE: return new cItemDyeHandler(a_ItemType);
|
||||
case E_ITEM_EGG: return new cItemEggHandler();
|
||||
case E_ITEM_ENDER_PEARL: return new cItemEnderPearlHandler();
|
||||
|
Loading…
Reference in New Issue
Block a user