mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Added conversion between Items <==> Blocks
This commit is contained in:
parent
d5aa898ffe
commit
213cda27aa
@ -56,7 +56,7 @@ class BlockAPI{
|
||||
$id = (int) $id;
|
||||
if(isset(Item::$class[$id])){
|
||||
$classname = Item::$class[$id];
|
||||
$i = new $classname($meta);
|
||||
$i = new $classname($meta, $count);
|
||||
}else{
|
||||
$i = new Item($id, $meta, $count);
|
||||
}
|
||||
|
@ -59,9 +59,9 @@ class Player{
|
||||
$this->timeout = microtime(true) + 20;
|
||||
$this->inventory = array_fill(0, 36, array(AIR, 0, 0));
|
||||
if($this->server->gamemode === 0 or $this->server->gamemode === 2){
|
||||
$this->equipment = new Item(AIR);
|
||||
$this->equipment = BlockAPI::getItem(AIR);
|
||||
}else{
|
||||
$this->equipment = new Item(STONE);
|
||||
$this->equipment = BlockAPI::getItem(STONE);
|
||||
}
|
||||
$this->evid[] = $this->server->event("server.tick", array($this, "onTick"));
|
||||
$this->evid[] = $this->server->event("server.close", array($this, "close"));
|
||||
@ -136,7 +136,7 @@ class Player{
|
||||
while($count > 0){
|
||||
$add = 0;
|
||||
foreach($this->inventory as $s => $data){
|
||||
if($data[0] === 0){
|
||||
if($data[0] === AIR){
|
||||
$add = min(64, $count);
|
||||
$this->inventory[$s] = array($type, $damage, $add);
|
||||
break;
|
||||
@ -180,7 +180,7 @@ class Player{
|
||||
}
|
||||
|
||||
public function hasItem($type, $damage = false){
|
||||
if($type === 0){
|
||||
if($type === AIR){
|
||||
return true;
|
||||
}
|
||||
foreach($this->inventory as $s => $data){
|
||||
@ -552,7 +552,7 @@ class Player{
|
||||
case MC_PLAYER_EQUIPMENT:
|
||||
$data["eid"] = $this->eid;
|
||||
if($this->server->handle("player.equipment.change", $data) !== false){
|
||||
$this->equipment = new Item($data["block"], $data["meta"]);
|
||||
$this->equipment = BlockAPI::getItem($data["block"], $data["meta"]);
|
||||
console("[DEBUG] Player ".$this->username." has now ".$this->equipment->getName()." (".$this->equipment->getID().":".$this->equipment->getMetadata().") in their hands!", true, true, 2);
|
||||
}
|
||||
break;
|
||||
|
@ -237,6 +237,7 @@ define("LEATHER", 334);
|
||||
|
||||
define("BRICK", 336);
|
||||
define("CLAY", 337);
|
||||
define("SUGARCANE", 338);
|
||||
define("SUGAR_CANE", 338);
|
||||
define("SUGAR_CANES", 338);
|
||||
define("PAPER", 339);
|
||||
|
@ -29,8 +29,7 @@ require_once("classes/material/IDs.php");
|
||||
|
||||
class Item{
|
||||
public static $class = array(
|
||||
|
||||
|
||||
SUGARCANE => "SugarcaneItem",
|
||||
);
|
||||
protected $block;
|
||||
protected $id;
|
||||
|
@ -30,4 +30,10 @@ class SugarcaneBlock extends TransparentBlock{
|
||||
parent::__construct(SUGARCANE_BLOCK, 0, "Sugarcane");
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array(SUGARCANE, 0, 1),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
33
src/classes/material/item/generic/Sugarcane.php
Normal file
33
src/classes/material/item/generic/Sugarcane.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
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.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class SugarcaneItem extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = BlockAPI::get(SUGARCANE_BLOCK);
|
||||
parent::__construct(SUGARCANE, 0, $count, "Sugar Cane");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user