Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Fish items, block of redstone!
Browse files Browse the repository at this point in the history
  • Loading branch information
shoghicp committed Apr 8, 2015
1 parent 3cae81c commit 7676729
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 8 deletions.
21 changes: 18 additions & 3 deletions src/pocketmine/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -2048,9 +2048,17 @@ public function handleDataPacket(DataPacket $packet){
Item::CARROT => 4,
Item::POTATO => 1,
Item::BAKED_POTATO => 6,
//Item::COOKIE => 2,
//Item::COOKED_FISH => 5,
//Item::RAW_FISH => 2,
Item::COOKIE => 2,
Item::COOKED_FISH => [
0 => 5,
1 => 6
],
Item::RAW_FISH => [
0 => 2,
1 => 2,
2 => 1,
3 => 1
],
];
$slot = $this->inventory->getItemInHand();
if($this->getHealth() < 20 and isset($items[$slot->getId()])){
Expand All @@ -2068,13 +2076,20 @@ public function handleDataPacket(DataPacket $packet){
Server::broadcastPacket($this->getViewers(), $pk);

$amount = $items[$slot->getId()];
if(is_array($amount)){
$amount = isset($amount[$slot->getDamage()]) ? $amount[$slot->getDamage()] : 0;
}
$ev = new EntityRegainHealthEvent($this, $amount, EntityRegainHealthEvent::CAUSE_EATING);
$this->heal($ev->getAmount(), $ev);

--$slot->count;
$this->inventory->setItemInHand($slot, $this);
if($slot->getId() === Item::MUSHROOM_STEW or $slot->getId() === Item::BEETROOT_SOUP){
$this->inventory->addItem(Item::get(Item::BOWL, 0, 1));
}elseif($slot->getId() === Item::RAW_FISH and $slot->getDamage() === 3){ //Pufferfish
//$this->addEffect(Effect::getEffect(Effect::HUNGER)->setAmplifier(2)->setDuration(15 * 20));
$this->addEffect(Effect::getEffect(Effect::NAUSEA)->setAmplifier(1)->setDuration(15 * 20));
$this->addEffect(Effect::getEffect(Effect::POISON)->setAmplifier(3)->setDuration(60 * 20));
}
}
break;
Expand Down
9 changes: 9 additions & 0 deletions src/pocketmine/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ class Block extends Position implements Metadatable{
const CARROT_BLOCK = 141;
const POTATO_BLOCK = 142;

const REDSTONE_BLOCK = 152;

const QUARTZ_BLOCK = 155;
const QUARTZ_STAIRS = 156;
const DOUBLE_WOOD_SLAB = 157;
Expand Down Expand Up @@ -351,6 +353,7 @@ class Block extends Position implements Metadatable{
[Item::LAPIS_BLOCK, 0],
[Item::COAL_BLOCK, 0],
[Item::EMERALD_BLOCK, 0],
[Item::REDSTONE_BLOCK, 0],
[Item::SNOW_LAYER, 0],
[Item::GLASS, 0],
[Item::GLOWSTONE_BLOCK, 0],
Expand Down Expand Up @@ -504,6 +507,12 @@ class Block extends Position implements Metadatable{
[Item::POTATO, 0],
[Item::BEETROOT_SEEDS, 0],
[Item::EGG, 0],
[Item::RAW_FISH, 0],
[Item::RAW_FISH, 1],
[Item::RAW_FISH, 2],
[Item::RAW_FISH, 3],
[Item::COOKED_FISH, 0],
[Item::COOKED_FISH, 1],
[Item::DYE, 0],
[Item::DYE, 7],
[Item::DYE, 6],
Expand Down
68 changes: 68 additions & 0 deletions src/pocketmine/block/Redstone.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/
*
*
*/

namespace pocketmine\block;

use pocketmine\item\Item;

class Redstone extends Transparent{

protected $id = self::REDSTONE_BLOCK;

public function __construct(){

}

public function getHardness(){
return 30;
}

public function getName(){
return "Redstone Block";
}

public function getBreakTime(Item $item){
switch($item->isPickaxe()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
case 2:
return 0.65;
case 1:
return 3.75;
default:
return 25;
}
}

public function getDrops(Item $item){
if($item->isPickaxe() >= 1){
return [
[Item::REDSTONE_BLOCK, 0, 1],
];
}else{
return [];
}
}
}
2 changes: 1 addition & 1 deletion src/pocketmine/command/defaults/EffectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function execute(CommandSender $sender, $currentAlias, array $args){
$effect->setDuration($duration)->setAmplifier($amplification);

$player->addEffect($effect);
self::broadcastCommandMessage($sender, "Given ". $effect->getName() ." (ID ". $effect->getId()." ) * ". $effect->getAmplifier()." to ". $player->getDisplayName() ." for ". ($effect->getDuration() / 20) ." seconds");
self::broadcastCommandMessage($sender, "Given ". $effect->getName() ." (ID ". $effect->getId().") * ". $effect->getAmplifier()." to ". $player->getDisplayName() ." for ". ($effect->getDuration() / 20) ." seconds");
}


Expand Down
3 changes: 2 additions & 1 deletion src/pocketmine/inventory/CraftingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ protected function registerFurnace(){
$this->registerRecipe(new FurnaceRecipe(Item::get(Item::NETHER_BRICK, 0, 1), Item::get(Item::NETHERRACK, 0, 1)));
$this->registerRecipe(new FurnaceRecipe(Item::get(Item::COOKED_PORKCHOP, 0, 1), Item::get(Item::RAW_PORKCHOP, 0, 1)));
$this->registerRecipe(new FurnaceRecipe(Item::get(Item::BRICK, 0, 1), Item::get(Item::CLAY, 0, 1)));
//$this->registerRecipe(new FurnaceRecipe(Item::get(Item::COOKED_FISH, 0, 1), Item::get(Item::RAW_FISH, 0, 1)));
$this->registerRecipe(new FurnaceRecipe(Item::get(Item::COOKED_FISH, 0, 1), Item::get(Item::RAW_FISH, 0, 1)));
$this->registerRecipe(new FurnaceRecipe(Item::get(Item::COOKED_FISH, 1, 1), Item::get(Item::RAW_FISH, 1, 1)));
$this->registerRecipe(new FurnaceRecipe(Item::get(Item::DYE, 2, 1), Item::get(Item::CACTUS, 0, 1)));
$this->registerRecipe(new FurnaceRecipe(Item::get(Item::DYE, 1, 1), Item::get(Item::RED_MUSHROOM, 0, 1)));
$this->registerRecipe(new FurnaceRecipe(Item::get(Item::STEAK, 0, 1), Item::get(Item::RAW_BEEF, 0, 1)));
Expand Down
33 changes: 33 additions & 0 deletions src/pocketmine/item/CookedFish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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/
*
*
*/

namespace pocketmine\item;


class CookedFish extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::RAW_FISH, $meta, $count, "Cooked Fish");
if($this->meta === 1){
$this->name = "Cooked Salmon";
}
}

}
37 changes: 37 additions & 0 deletions src/pocketmine/item/Fish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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/
*
*
*/

namespace pocketmine\item;


class Fish extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::RAW_FISH, $meta, $count, "Raw Fish");
if($this->meta === 1){
$this->name = "Raw Salmon";
}elseif($this->meta === 2){
$this->name = "Clownfish";
}elseif($this->meta === 3){
$this->name = "Pufferfish";
}
}

}
11 changes: 8 additions & 3 deletions src/pocketmine/item/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ class Item{
const CARROT_BLOCK = 141;
const POTATO_BLOCK = 142;

const REDSTONE_BLOCK = 152;

const QUARTZ_BLOCK = 155;
const QUARTZ_STAIRS = 156;
const DOUBLE_WOOD_SLAB = 157;
Expand Down Expand Up @@ -339,16 +341,16 @@ class Item{

const CLOCK = 347;
const GLOWSTONE_DUST = 348;
//const RAW_FISH = 349;
//const COOKED_FISH = 350;
const RAW_FISH = 349;
const COOKED_FISH = 350;
const DYE = 351;
const BONE = 352;
const SUGAR = 353;
const CAKE = 354;
const BED = 355;


//const COOKIE = 357;
const COOKIE = 357;


const SHEARS = 359;
Expand Down Expand Up @@ -479,6 +481,9 @@ public static function init(){
self::$list[self::SHEARS] = Shears::class;
self::$list[self::BOW] = Bow::class;

self::$list[self::RAW_FISH] = Fish::class;
self::$list[self::COOKED_FISH] = CookedFish::class;

for($i = 0; $i < 256; ++$i){
if(Block::$list[$i] !== null){
self::$list[$i] = Block::$list[$i];
Expand Down

0 comments on commit 7676729

Please sign in to comment.