Skip to content
This repository was archived by the owner on Feb 1, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Example servers running Turanic
- [ ] More thread/worker
- [ ] Basic ChunkLoader System
- [ ] Fast NBT Writer/reader
- [ ] Basic Redstone system (without lag) (Progress: %80)
- [ ] Basic Redstone system (without lag) (Progress: %10)
- [ ] Update languages
<br />***More to do...***

Expand Down
39 changes: 28 additions & 11 deletions src/pocketmine/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public function getFuelTime() : int{
*/
public function getSide($side, $step = 1){
if($this->isValid()){
return $this->getLevel()->getBlock(Vector3::getSide($side, $step));
return $this->getLevel()->getBlockAt(...Vector3::getSide($side, $step)->toArray());
}

return BlockFactory::get(Block::AIR, 0, Position::fromObject(Vector3::getSide($side, $step)));
Expand Down Expand Up @@ -738,24 +738,41 @@ public function canNeighborBurn(){
public function isPlaceable(){
return $this->canBePlaced();
}

public function getMaxStackSize() : int{
return 64;
public function getMaxStackSize() : int{
return 64;
}

public function isNormal(){
return !$this->isTransparent() && $this->isSolid() && !$this->isRedstoneSource();
/**
* Kızıltaş kaynağı kontrolü
*
* @return bool
*/
public function isRedstoneSource() : bool{
return false;
}

public function isRedstoneSource(){
return false;
/**
* Kızıltaş güç seviyesi
* NOT: Güç seviyesi isRedstoneSource fonksiyonundan bağımsız çalışır
*
* @return int
*/
public function getRedstonePower() : int{
return 0;
}

public function getWeakPower(int $side) : int{
return 0;
/**
* Kızıltaş ile güncellenebilir mi ?
*
* @return bool
*/
public function canUpdateWithRedstone() : bool{
return false;
}

public function activate(){ // TODO : remove
// TODO : remove

public function activate(){
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pocketmine/block/BlockFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static function init(bool $force = false){
self::registerBlock(new EndStone());
self::registerBlock(new DragonEgg());
self::registerBlock(new RedstoneLamp());
self::registerBlock(new LitRedstoneLamp());
self::registerBlock(new RedstoneLampLit());
self::registerBlock(new Dropper());
self::registerBlock(new ActivatorRail());
self::registerBlock(new CocoaBlock());
Expand Down
41 changes: 40 additions & 1 deletion src/pocketmine/block/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@

namespace pocketmine\block;

use pocketmine\block\utils\RedstoneUtils;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\Player;

abstract class Button extends Flowable {
Expand All @@ -51,7 +55,42 @@ public function place(Item $item, Block $blockReplace, Block $blockClicked, int
}

public function onActivate(Item $item, Player $player = null): bool{
// TODO : Add Redstone System
if(!$this->isRedstoneSource()){
$this->meta ^= 0x08;
$this->level->setBlock($this, $this, true, false);
$this->level->scheduleDelayedBlockUpdate($this, 30);
$this->level->broadcastLevelEvent($this, LevelEventPacket::EVENT_REDSTONE_TRIGGER);
RedstoneUtils::updateRedstone($this, null, true);
RedstoneUtils::updateRedstone($this->getOppositeSidePosition(), null, true, $this->asPosition());
}
return true;
}

public function onUpdate(int $type){
switch($type){
case Level::BLOCK_UPDATE_SCHEDULED:
if($this->isRedstoneSource()){
$this->meta ^= 0x08;
$this->level->setBlock($this, $this, true, false);
$this->level->broadcastLevelEvent($this, LevelEventPacket::EVENT_REDSTONE_TRIGGER);
RedstoneUtils::updateRedstone($this, null, true);
RedstoneUtils::updateRedstone($this->getOppositeSidePosition(), null, true, $this->asPosition());
}
break;
}
}

public function isRedstoneSource(): bool{
return (($this->meta & 0x08) === 0x08);
}


public function getRedstonePower(): int{
return 15;
}

public function getOppositeSidePosition(){
$side = self::getOppositeSide($this->isRedstoneSource() ? $this->meta ^ 0x08 : $this->meta);
return Position::fromObject($this->asVector3()->getSide($side), $this->level);
}
}
4 changes: 0 additions & 4 deletions src/pocketmine/block/DaylightDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ public function getFuelTime(): int{
return 300;
}

public function isRedstoneSource(){
return true;
}

public function getWeakPower(int $side): int{
return $this->getTile()->getLightByTime();
}
Expand Down
4 changes: 0 additions & 4 deletions src/pocketmine/block/DaylightDetectorInverted.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public function onActivate(Item $item, Player $player = null) : bool{
return true;
}

public function isRedstoneSource(){
return false;
}

public function getWeakPower(int $side): int{
return 0;
}
Expand Down
19 changes: 18 additions & 1 deletion src/pocketmine/block/Lever.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@

namespace pocketmine\block;

use pocketmine\block\utils\RedstoneUtils;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\level\sound\ButtonClickSound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\Player;

class Lever extends Flowable {
Expand Down Expand Up @@ -96,4 +97,20 @@ public function place(Item $item, Block $blockReplace, Block $blockClicked, int

return $this->level->setBlock($blockReplace, $this, true, true);
}

public function onActivate(Item $item, Player $player = null) : bool{
$this->meta ^= 0x08;
$this->level->setBlock($this, $this, false, true);
$this->level->broadcastLevelEvent($this, LevelEventPacket::EVENT_REDSTONE_TRIGGER);
RedstoneUtils::updateRedstone($this);
return true;
}

public function isRedstoneSource(): bool{
return ($this->meta & 0x08) > 0;
}

public function getRedstonePower(): int{
return 15;
}
}
4 changes: 0 additions & 4 deletions src/pocketmine/block/PressurePlate.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ protected function recalculateCollisionBoxes(): array{
return [new AxisAlignedBB($this->x + 0.125, $this->y, $this->z + 0.125, $this->x + 0.875, $this->y + 0.25, $this->z + 0.875)];
}

public function isRedstoneSource(){
return true;
}

public function hasEntityCollision() : bool{
return true;
}
Expand Down
76 changes: 24 additions & 52 deletions src/pocketmine/block/Redstone.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,81 +26,53 @@

namespace pocketmine\block;

use pocketmine\block\utils\RedstoneUtils;
use pocketmine\item\TieredTool;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\level\Level;

class Redstone extends Solid {

protected $id = self::REDSTONE_BLOCK;

public function isActivated(Block $from = null){
return true;
public function __construct(int $meta = 0){
$this->meta = $meta;
}

public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
$kontrol = false;
foreach ([self::SIDE_NORTH, self::SIDE_SOUTH, self::SIDE_WEST, self::SIDE_EAST] as $side) {
/** @var RedstoneWire $wire */
$wire = $this->getSide($side);
if($wire->getId() == $this->id){
if($wire->isActivated()){
$kontrol = true; // found redstone wire
break;
}
}
}
if(!$kontrol)
$this->level->updateAroundRedstone($this);
return true;
}

public function __construct(int $meta = 0){
$this->meta = $meta;
}

public function getBlastResistance() : float{
return 10;
public function getName() : string{
return "Block of Redstone";
}

public function getHardness() : float{
return 5;
}

public function isRedstoneSource(){
return true;
}

public function getWeakPower(int $side): int{
return 15;
public function getBlastResistance() : float{
return 30;
}

/**
* @return \pocketmine\math\AxisAlignedBB
*/
public function getBoundingBox(){
return Block::getBoundingBox();
}

public function canBeFlowedInto() : bool{
public function canBeFlowedInto() : bool{
return false;
}

public function isSolid() : bool{
return true;
}

public function getToolType() : int{
public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}

public function getToolHarvestLevel(): int{
public function getToolHarvestLevel(): int{
return TieredTool::TIER_WOODEN;
}

public function getName() : string{
return "Block of Redstone";
}
public function isRedstoneSource() : bool{
return true;
}

public function getRedstonePower(): int{
return 15;
}

public function onUpdate(int $type){
if($type == Level::BLOCK_UPDATE_NORMAL){
RedstoneUtils::updateRedstone($this);
}
}
}
4 changes: 0 additions & 4 deletions src/pocketmine/block/RedstoneDiode.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public function __construct($meta = 0){
parent::__construct($meta);
}

public function isRedstoneSource(){
return true;
}

abstract function getFacing() : int;

public function onBreak(Item $item, Player $player = null) : bool{
Expand Down
23 changes: 10 additions & 13 deletions src/pocketmine/block/RedstoneLamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace pocketmine\block;

use pocketmine\block\utils\RedstoneUtils;
use pocketmine\level\Level;

class RedstoneLamp extends Solid {
Expand All @@ -33,27 +34,23 @@ public function __construct(int $meta = 0){
$this->meta = $meta;
}

public function getLightLevel() : int{
return 0;
}
public function getName() : string{
return "Redstone Lamp";
}

public function getHardness() : float{
return 0.3;
}

public function getToolType() : int{
return BlockToolType::TYPE_PICKAXE;
}

public function getName() : string{
return "Redstone Lamp";
}

public function onUpdate(int $type){
if($type == Level::BLOCK_UPDATE_NORMAL || $type == Level::BLOCK_UPDATE_REDSTONE){
if($this->level->isBlockPowered($this) or $this->level->isBlockPowered($this->getSide(self::SIDE_UP))){
$this->level->setBlock($this, new LitRedstoneLamp(), false, false);
if(RedstoneUtils::isRedstonePowered($this->asPosition())){
$this->level->setBlock($this, Block::get(Block::LIT_REDSTONE_LAMP));
}
}
}

public function canUpdateWithRedstone(): bool{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@

namespace pocketmine\block;

use pocketmine\block\utils\RedstoneUtils;
use pocketmine\level\Level;

class LitRedstoneLamp extends RedstoneLamp implements ElectricalAppliance, SolidLight{
class RedstoneLampLit extends RedstoneLamp implements SolidLight{

protected $id = self::LIT_REDSTONE_LAMP;
/** @var bool */
private $delayed = false;

public function getName() : string{
return "Lit Redstone Lamp";
Expand All @@ -42,12 +45,13 @@ public function onUpdate(int $type){
switch($type){
case Level::BLOCK_UPDATE_NORMAL:
case Level::BLOCK_UPDATE_REDSTONE:
if (!$this->level->isBlockPowered($this))
if (!RedstoneUtils::isRedstonePowered($this))
$this->delayed = true;
$this->level->scheduleDelayedBlockUpdate($this, 4);
break;
case Level::BLOCK_UPDATE_SCHEDULED:
if (!$this->level->isBlockPowered($this))
$this->level->setBlock($this, new RedstoneLamp(), false, false);
if($this->delayed or !RedstoneUtils::isRedstonePowered($this))
$this->level->setBlock($this, Block::get(Block::REDSTONE_LAMP), false, false);
break;
}
}
Expand Down
Loading