123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #include "LightSources.h"
- LightSourceItem::LightSourceItem(const ItemType* zType, const BlockType* zPlacedBlockType, const char* name)
- : BasicBlockItem(zType, zPlacedBlockType, name),
- color(0XFFFFFFFF)
- {}
- bool LightSourceItem::canBeStackedWith(const Item* zItem) const
- {
- const LightSourceItem* other = dynamic_cast<const LightSourceItem*>(zItem);
- return BasicBlockItem::canBeStackedWith(zItem) && other->color == color;
- }
- LightSourceItemType::LightSourceItemType(int id, const char* name, const ModelInfo model)
- :BasicBlockItemType(id, name, 0, 0, model)
- {}
- void LightSourceItemType::loadSuperItem(Item* zItem, Framework::StreamReader* zReader) const
- {
- LightSourceItem* item = dynamic_cast<LightSourceItem*>(zItem);
- zReader->lese((char*)&item->color, 4);
- BasicBlockItemType::loadSuperItem(zItem, zReader);
- }
- void LightSourceItemType::saveSuperItem(const Item* zItem, Framework::StreamWriter* zWriter) const
- {
- const LightSourceItem* item = dynamic_cast<const LightSourceItem*>(zItem);
- zWriter->schreibe((char*)&item->color, 4);
- BasicBlockItemType::saveSuperItem(zItem, zWriter);
- }
- void LightSourceItemType::initializeItem(LightSourceItem* zItem, int color, bool transparent, bool passable, float hardness, int toolId, float speedModifier) const
- {
- zItem->color = color;
- BasicBlockItemType::initializeItem(zItem, transparent, passable, hardness, toolId, speedModifier);
- }
- BasicLightSource::BasicLightSource(const BlockType* zType, Framework::Vec3<int> pos)
- : Block(zType, 0, pos, 0)
- {}
- void BasicLightSource::setLight(int light)
- {
- lightEmisionColor[0] = (unsigned char)((light >> 16) & 0xFF);
- lightEmisionColor[1] = (unsigned char)((light >> 8) & 0xFF);
- lightEmisionColor[2] = (unsigned char)(light & 0xFF);
- }
- bool BasicLightSource::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
- {
- return 0;
- }
- void BasicLightSource::onPostTick()
- {}
- BasicLightSourceBlockType::BasicLightSourceBlockType(int typeId, int itemTypeId, ModelInfo model)
- : BlockType(typeId, 0, model, 1, 1, 1),
- itemType(itemTypeId),
- transparent(1),
- passable(1),
- hardness(1.f),
- interactable(1)
- {}
- void BasicLightSourceBlockType::createSuperBlock(Block* zBlock, Item* zItem) const
- {
- BasicLightSource* block = dynamic_cast<BasicLightSource*>(zBlock);
- if (!block)
- throw "BasicLightSourceBlockType::createSuperBlock was called with a block witch is not an instance of BasicLightSource";
- block->transparent = transparent;
- block->passable = passable;
- block->hp = (float)getInitialMaxHP();
- block->maxHP = (float)getInitialMaxHP();
- block->hardness = hardness;
- block->zTool = 0;
- block->speedModifier = 1;
- block->interactable = interactable;
- block->setLight(color);
- BlockType::createSuperBlock(zBlock, zItem);
- if (zItem)
- {
- dynamic_cast<BasicLightSource*>(zBlock)->setLight(dynamic_cast<LightSourceItem*>(zItem)->color);
- }
- }
- void BasicLightSourceBlockType::loadSuperBlock(Block* zBlock, Framework::StreamReader* zReader, int dimensionId) const
- {
- BlockType::loadSuperBlock(zBlock, zReader, dimensionId);
- BasicLightSource* block = dynamic_cast<BasicLightSource*>(zBlock);
- if (!block)
- throw "BasicLightSourceBlockType::loadSuperBlock was called with a block witch is not an instance of BasicLightSource";
- zReader->lese((char*)&block->lightEmisionColor, 4);
- }
- void BasicLightSourceBlockType::saveSuperBlock(Block* zBlock, Framework::StreamWriter* zWriter) const
- {
- BlockType::saveSuperBlock(zBlock, zWriter);
- BasicLightSource* block = dynamic_cast<BasicLightSource*>(zBlock);
- if (!block)
- throw "BasicLightSourceBlockType::saveSuperBlock was called with a block witch is not an instance of BasicLightSource";
- zWriter->schreibe((char*)&block->lightEmisionColor, 4);
- }
- Block* BasicLightSourceBlockType::createBlock(Framework::Vec3<int> position) const
- {
- return new BasicLightSource(this, position);
- }
- Item* BasicLightSourceBlockType::createItem() const
- {
- return StaticRegistry<ItemType>::INSTANCE.zElement(itemType)->createItem();
- }
- TorchBlockItemType::TorchBlockItemType()
- : LightSourceItemType(ID, "Torch", ModelInfo("items.m3/stick", "blocks.ltdb/torch.png", 6))
- {}
- Item* TorchBlockItemType::createItem() const
- {
- LightSourceItem* item = new LightSourceItem(this, TorchBlockType::INSTANCE, "Torch");
- initializeItem(item, 0x00F69A54);
- return item;
- }
- TorchBlockType::TorchBlockType()
- : BasicLightSourceBlockType(ID, TorchBlockItemType::ID, ModelInfo("blocks.m3/torch", "blocks.ltdb/torch.png", 6))
- {
- hardness = 0.f;
- color = 0x00F69A54;
- defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
- }
|