Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new 1.21 copper blocks #6366

Merged
merged 11 commits into from
Sep 25, 2024
7 changes: 6 additions & 1 deletion src/block/BlockTypeIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,13 @@ private function __construct(){
public const PITCHER_PLANT = 10715;
public const PITCHER_CROP = 10716;
public const DOUBLE_PITCHER_CROP = 10717;
public const COPPER_BULB = 10718;
public const COPPER_DOOR = 10719;
public const COPPER_TRAPDOOR = 10720;
public const CHISELED_COPPER = 10721;
public const COPPER_GRATE = 10722;

public const FIRST_UNUSED_BLOCK_ID = 10718;
public const FIRST_UNUSED_BLOCK_ID = 10723;

private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID;

Expand Down
68 changes: 68 additions & 0 deletions src/block/CopperBulb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/

declare(strict_types=1);

namespace pocketmine\block;

use pocketmine\block\utils\CopperOxidation;
use pocketmine\block\utils\CopperTrait;
use pocketmine\block\utils\LightableTrait;
use pocketmine\block\utils\PoweredByRedstoneTrait;
use pocketmine\data\runtime\RuntimeDataDescriber;

class CopperBulb extends Opaque{
use CopperTrait;
use PoweredByRedstoneTrait;
use LightableTrait{
describeBlockOnlyState as encodeLitState;
}

protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
$this->encodeLitState($w);
$w->bool($this->powered);
}

/** @return $this */
public function togglePowered(bool $powered) : self{
if($powered === $this->powered){
return $this;
}
if ($powered) {
$this->setLit(!$this->lit);
}
$this->setPowered($powered);
return $this;
ShockedPlot7560 marked this conversation as resolved.
Show resolved Hide resolved
}

public function getLightLevel() : int{
if ($this->lit) {
return match($this->oxidation){
CopperOxidation::NONE => 15,
CopperOxidation::EXPOSED => 12,
CopperOxidation::WEATHERED => 8,
CopperOxidation::OXIDIZED => 4,
};
}

return 0;
}
}
63 changes: 63 additions & 0 deletions src/block/CopperDoor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/

declare(strict_types=1);

namespace pocketmine\block;

use pocketmine\block\utils\CopperTrait;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;

class CopperDoor extends Door{
use CopperTrait{
onInteract as onInteractCopper;
}

public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if ($player !== null && !$player->isSneaking()) {
return parent::onInteract($item, $face, $clickVector, $player, $returnedItems);
}

if ($this->onInteractCopper($item, $face, $clickVector, $player, $returnedItems)) {
//copy copper properties to other half
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
$world = $this->position->getWorld();
if ($other instanceof CopperDoor) {
$other->setOxidation($this->oxidation);
$other->setWaxed($this->waxed);
$world->setBlock($other->position, $other);
}
return true;
}

return false;
IvanCraft623 marked this conversation as resolved.
Show resolved Hide resolved
}

protected function isCompatibleForHinge(Block $other) : bool{
return parent::isCompatibleForHinge($other) &&
$other instanceof CopperDoor &&
$this->getOxidation() === $other->getOxidation() &&
$this->isWaxed() === $other->isWaxed();
}
}
32 changes: 32 additions & 0 deletions src/block/CopperGrate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/

declare(strict_types=1);

namespace pocketmine\block;

use pocketmine\block\utils\CopperTrait;

class CopperGrate extends Transparent{
use CopperTrait;

//TODO: waterlogging!
}
43 changes: 43 additions & 0 deletions src/block/CopperTrapdoor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/

declare(strict_types=1);

namespace pocketmine\block;

use pocketmine\block\utils\CopperTrait;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\player\Player;

class CopperTrapdoor extends Trapdoor{
use CopperTrait{
onInteract as onInteractCopper;
}

public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if ($player !== null && !$player->isSneaking()) {
return parent::onInteract($item, $face, $clickVector, $player, $returnedItems);
}

return $this->onInteractCopper($item, $face, $clickVector, $player, $returnedItems);
IvanCraft623 marked this conversation as resolved.
Show resolved Hide resolved
}
}
6 changes: 5 additions & 1 deletion src/block/Door.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo
$next = $this->getSide(Facing::rotateY($this->facing, false));
$next2 = $this->getSide(Facing::rotateY($this->facing, true));

if($next->hasSameTypeId($this) || (!$next2->isTransparent() && $next->isTransparent())){ //Door hinge
if($this->isCompatibleForHinge($next) || (!$next2->isTransparent() && $next->isTransparent())){ //Door hinge
$this->hingeRight = true;
}

Expand Down Expand Up @@ -176,4 +176,8 @@ public function getAffectedBlocks() : array{
private function canBeSupportedAt(Block $block) : bool{
return $block->getAdjacentSupportType(Facing::DOWN)->hasEdgeSupport();
}

protected function isCompatibleForHinge(Block $other) : bool{
return $other->hasSameTypeId($this);
}
}
12 changes: 12 additions & 0 deletions src/block/VanillaBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
* @method static Wood CHERRY_WOOD()
* @method static Chest CHEST()
* @method static ChiseledBookshelf CHISELED_BOOKSHELF()
* @method static Copper CHISELED_COPPER()
* @method static Opaque CHISELED_DEEPSLATE()
* @method static Opaque CHISELED_NETHER_BRICKS()
* @method static Opaque CHISELED_POLISHED_BLACKSTONE()
Expand All @@ -205,7 +206,11 @@
* @method static Concrete CONCRETE()
* @method static ConcretePowder CONCRETE_POWDER()
* @method static Copper COPPER()
* @method static CopperBulb COPPER_BULB()
* @method static CopperDoor COPPER_DOOR()
* @method static CopperGrate COPPER_GRATE()
* @method static CopperOre COPPER_ORE()
* @method static CopperTrapdoor COPPER_TRAPDOOR()
* @method static Coral CORAL()
* @method static CoralBlock CORAL_BLOCK()
* @method static FloorCoralFan CORAL_FAN()
Expand Down Expand Up @@ -1621,9 +1626,16 @@ public function isAffectedBySilkTouch() : bool{
self::register("lightning_rod", new LightningRod(new BID(Ids::LIGHTNING_ROD), "Lightning Rod", $copperBreakInfo));

self::register("copper", new Copper(new BID(Ids::COPPER), "Copper Block", $copperBreakInfo));
self::register("chiseled_copper", new Copper(new BID(Ids::CHISELED_COPPER), "Chiseled Copper", $copperBreakInfo));
self::register("copper_grate", new CopperGrate(new BID(Ids::COPPER_GRATE), "Copper Grate", $copperBreakInfo));
self::register("cut_copper", new Copper(new BID(Ids::CUT_COPPER), "Cut Copper Block", $copperBreakInfo));
self::register("cut_copper_slab", new CopperSlab(new BID(Ids::CUT_COPPER_SLAB), "Cut Copper Slab", $copperBreakInfo));
self::register("cut_copper_stairs", new CopperStairs(new BID(Ids::CUT_COPPER_STAIRS), "Cut Copper Stairs", $copperBreakInfo));
self::register("copper_bulb", new CopperBulb(new BID(Ids::COPPER_BULB), "Copper Bulb", $copperBreakInfo));

$copperDoorBreakInfo = new Info(BreakInfo::pickaxe(3.0, ToolTier::STONE, 30.0));
self::register("copper_door", new CopperDoor(new BID(Ids::COPPER_DOOR), "Copper Door", $copperDoorBreakInfo));
self::register("copper_trapdoor", new CopperTrapdoor(new BID(Ids::COPPER_TRAPDOOR), "Copper Trapdoor", $copperDoorBreakInfo));

$candleBreakInfo = new Info(new BreakInfo(0.1));
self::register("candle", new Candle(new BID(Ids::CANDLE), "Candle", $candleBreakInfo));
Expand Down
Loading