rewrite of interact system, bugfixes, ai tweaks

This commit is contained in:
GameHerobrine 2022-11-01 00:55:49 +03:00
parent f5222be9d2
commit ac1a1b2449
62 changed files with 649 additions and 491 deletions

View file

@ -7,6 +7,8 @@ class Item{
const TOOL_SHOVEL = 3;
const TOOL_HOE = 4;
const DEF_DAMAGE = 1;
public static $class = array(
//armor
@ -150,6 +152,10 @@ class Item{
}
}
public function isPickaxe(){
return false;
}
public function getName(){
return $this->name;
}
@ -210,21 +216,13 @@ class Item{
}
public function useOn($object, $force = false){
if($this->isTool() or $force === true){
if(($object instanceof Entity) and !$this->isSword()){
$this->meta += 2;
}else{
$this->meta++;
}
if($force){
if(($object instanceof Entity) and !$this->isSword()){
$this->meta += 2;
}else{
$this->meta++;
}
return true;
}elseif($this->isHoe()){
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
$this->meta++;
}
}elseif(($object instanceof Crepper) and $this->id === FLINT_STEEL){
$this->meta++;
}elseif(($object instanceof Sheep) and $this->id === SHEARS){
$this->meta++;
}
return false;
}
@ -281,67 +279,19 @@ class Item{
}
public function isAxe(){
switch($this->id){
case WOODEN_AXE:
return 1;
case GOLDEN_AXE:
return 2;
case STONE_AXE:
return 3;
case IRON_AXE:
return 4;
case DIAMOND_AXE:
return 5;
default:
return false;
}
return false;
}
public function isSword(){
switch($this->id){
case WOODEN_SWORD:
return 1;
case GOLDEN_SWORD:
return 2;
case STONE_SWORD:
return 3;
case IRON_SWORD:
return 4;
case DIAMOND_SWORD:
return 5;
default:
return false;
}
return false;
}
public function isShovel(){
switch($this->id){
case WOODEN_SHOVEL:
return 1;
case GOLDEN_SHOVEL:
return 2;
case STONE_SHOVEL:
return 3;
case IRON_SHOVEL:
return 4;
case DIAMOND_SHOVEL:
return 5;
default:
return false;
}
return false;
}
public function isHoe(){
switch($this->id){
case WOODEN_HOE:
case GOLDEN_HOE:
case STONE_HOE:
case IRON_HOE:
case DIAMOND_HOE:
return true;
default:
return false;
}
return false;
}
public function isShears(){
@ -352,6 +302,10 @@ class Item{
return "Item ". $this->name ." (".$this->id.":".$this->meta.")";
}
public function getDamageAgainstOf($e){
return Item::DEF_DAMAGE;
}
public function getDestroySpeed(Block $block, Player $player){
return 1;
}

View file

@ -0,0 +1,11 @@
<?php
abstract class ItemAxe extends ItemTool
{
public function isAxe(){
return true;
}
}

View file

@ -0,0 +1,18 @@
<?php
abstract class ItemHoe extends ItemTool
{
public function isHoe(){
return true;
}
public function useOn($object, $force = false){
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
$this->meta++;
return true;
}else{
return parent::useOn($object, $force);
}
}
}

View file

@ -0,0 +1,13 @@
<?php
abstract class ItemPickaxe extends ItemTool
{
public function isTool(){
return true;
}
public function isPickaxe(){
return true;
}
}

View file

@ -0,0 +1,9 @@
<?php
class ItemShovel extends ItemTool
{
public function isShovel(){
return true;
}
}

View file

@ -0,0 +1,10 @@
<?php
abstract class ItemSword extends ItemTool
{
public function isSword(){
return true;
}
}

View file

@ -0,0 +1,17 @@
<?php
abstract class ItemTool extends Item
{
public function isTool(){
return true;
}
public function useOn($object, $force = false){
if(($object instanceof Entity) and !$this->isSword()){
$this->meta += 2;
}else{
$this->meta++;
}
return true;
}
}

View file

@ -1,11 +1,11 @@
<?php
class DiamondAxeItem extends Item{
class DiamondAxeItem extends ItemAxe{
public function __construct($meta = 0, $count = 1){
parent::__construct(DIAMOND_AXE, $meta, $count, "Diamond Axe");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 6;
}
}

View file

@ -1,11 +1,7 @@
<?php
class DiamondHoeItem extends Item{
class DiamondHoeItem extends ItemHoe{
public function __construct($meta = 0, $count = 1){
parent::__construct(DIAMOND_HOE, $meta, $count, "Diamond Hoe");
}
public function isTool(){
return true;
}
}

View file

@ -1,11 +1,11 @@
<?php
class DiamondPickaxeItem extends Item{
class DiamondPickaxeItem extends ItemPickaxe{
public function __construct($meta = 0, $count = 1){
parent::__construct(DIAMOND_PICKAXE, $meta, $count, "Diamond Pickaxe");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 5;
}
}

View file

@ -1,11 +1,10 @@
<?php
class DiamondShovelItem extends Item{
class DiamondShovelItem extends ItemShovel{
public function __construct($meta = 0, $count = 1){
parent::__construct(DIAMOND_SHOVEL, $meta, $count, "Diamond Shovel");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 4;
}
}

View file

@ -1,10 +1,12 @@
<?php
class DiamondSwordItem extends Item{
class DiamondSwordItem extends ItemSword{
public function __construct($meta = 0, $count = 1){
parent::__construct(DIAMOND_SWORD, $meta, $count, "Diamond Sword");
}
public function isTool(){
return true;
}
public function getDamageAgainstOf($e)
{
return 7;
}
}

View file

@ -1,6 +1,6 @@
<?php
class FlintSteelItem extends Item{
class FlintSteelItem extends ItemTool{
public function __construct($meta = 0, $count = 1){
parent::__construct(FLINT_STEEL, $meta, $count, "Flint and Steel");
$this->isActivable = true;
@ -20,7 +20,12 @@ class FlintSteelItem extends Item{
return false;
}
public function isTool(){
return true;
public function useOn($object, $force = false){
if(($object instanceof Creeper) and $this->id === FLINT_STEEL){
$this->meta++;
return true;
}else{
return parent::useOn($object, $force);
}
}
}

View file

@ -1,11 +1,10 @@
<?php
class GoldenAxeItem extends Item{
class GoldenAxeItem extends ItemAxe{
public function __construct($meta = 0, $count = 1){
parent::__construct(GOLDEN_AXE, $meta, $count, "Golden Axe");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 3;
}
}

View file

@ -1,11 +1,7 @@
<?php
class GoldenHoeItem extends Item{
class GoldenHoeItem extends ItemHoe{
public function __construct($meta = 0, $count = 1){
parent::__construct(GOLDEN_HOE, $meta, $count, "Golden Hoe");
}
public function isTool(){
return true;
}
}

View file

@ -1,11 +1,11 @@
<?php
class GoldenPickaxeItem extends Item{
class GoldenPickaxeItem extends ItemPickaxe{
public function __construct($meta = 0, $count = 1){
parent::__construct(GOLDEN_PICKAXE, $meta, $count, "Golden Pickaxe");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 2;
}
}

View file

@ -1,11 +1,7 @@
<?php
class GoldenShovelItem extends Item{
class GoldenShovelItem extends ItemShovel{
public function __construct($meta = 0, $count = 1){
parent::__construct(GOLDEN_SHOVEL, $meta, $count, "Golden Shovel");
}
public function isTool(){
return true;
}
}

View file

@ -1,10 +1,12 @@
<?php
class GoldenSwordItem extends Item{
class GoldenSwordItem extends ItemSword{
public function __construct($meta = 0, $count = 1){
parent::__construct(GOLDEN_SWORD, $meta, $count, "Golden Sword");
}
public function isTool(){
return true;
}
public function getDamageAgainstOf($e)
{
return 4;
}
}

View file

@ -1,11 +1,11 @@
<?php
class IronAxeItem extends Item{
class IronAxeItem extends ItemAxe{
public function __construct($meta = 0, $count = 1){
parent::__construct(IRON_AXE, $meta, $count, "Iron Axe");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 5;
}
}

View file

@ -1,11 +1,7 @@
<?php
class IronHoeItem extends Item{
class IronHoeItem extends ItemHoe{
public function __construct($meta = 0, $count = 1){
parent::__construct(IRON_HOE, $meta, $count, "Iron Hoe");
}
public function isTool(){
return true;
}
}

View file

@ -1,11 +1,11 @@
<?php
class IronPickaxeItem extends Item{
class IronPickaxeItem extends ItemPickaxe{
public function __construct($meta = 0, $count = 1){
parent::__construct(IRON_PICKAXE, $meta, $count, "Iron Pickaxe");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 4;
}
}

View file

@ -1,11 +1,11 @@
<?php
class IronShovelItem extends Item{
class IronShovelItem extends ItemShovel{
public function __construct($meta = 0, $count = 1){
parent::__construct(IRON_SHOVEL, $meta, $count, "Iron Shovel");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 3;
}
}

View file

@ -1,10 +1,10 @@
<?php
class IronSwordItem extends Item{
class IronSwordItem extends ItemSword{
public function __construct($meta = 0, $count = 1){
parent::__construct(IRON_SWORD, $meta, $count, "Iron Sword");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 6;
}
}

View file

@ -1,11 +1,15 @@
<?php
class ShearsItem extends Item{
class ShearsItem extends ItemTool{
public function __construct($meta = 0, $count = 1){
parent::__construct(SHEARS, $meta, $count, "Shears");
}
public function isTool(){
return true;
public function useOn($object, $force = false){
if(($object instanceof Sheep) and $this->id === SHEARS){
$this->meta++;
return true;
}
parent::useOn($object, $force);
}
}

View file

@ -1,11 +1,11 @@
<?php
class StoneAxeItem extends Item{
class StoneAxeItem extends ItemAxe{
public function __construct($meta = 0, $count = 1){
parent::__construct(STONE_AXE, $meta, $count, "Stone Axe");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 4;
}
}

View file

@ -1,11 +1,7 @@
<?php
class StoneHoeItem extends Item{
class StoneHoeItem extends ItemHoe{
public function __construct($meta = 0, $count = 1){
parent::__construct(STONE_HOE, $meta, $count, "Stone Hoe");
}
public function isTool(){
return true;
}
}

View file

@ -1,11 +1,11 @@
<?php
class StonePickaxeItem extends Item{
class StonePickaxeItem extends ItemPickaxe{
public function __construct($meta = 0, $count = 1){
parent::__construct(STONE_PICKAXE, $meta, $count, "Stone Pickaxe");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 3;
}
}

View file

@ -1,8 +1,12 @@
<?php
class StoneShovelItem extends Item{
class StoneShovelItem extends ItemShovel{
public function __construct($meta = 0, $count = 1){
parent::__construct(STONE_SHOVEL, $meta, $count, "Stone Shovel");
}
public function getDamageAgainstOf($e){
return 2;
}
}

View file

@ -1,10 +1,10 @@
<?php
class StoneSwordItem extends Item{
class StoneSwordItem extends ItemSword{
public function __construct($meta = 0, $count = 1){
parent::__construct(STONE_SWORD, $meta, $count, "Stone Sword");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 5;
}
}

View file

@ -1,11 +1,11 @@
<?php
class WoodenAxeItem extends Item{
class WoodenAxeItem extends ItemAxe{
public function __construct($meta = 0, $count = 1){
parent::__construct(WOODEN_AXE, $meta, $count, "Wooden Axe");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 3;
}
}

View file

@ -1,11 +1,7 @@
<?php
class WoodenHoeItem extends Item{
class WoodenHoeItem extends ItemHoe{
public function __construct($meta = 0, $count = 1){
parent::__construct(WOODEN_HOE, $meta, $count, "Wooden Hoe");
}
public function isTool(){
return true;
}
}

View file

@ -1,11 +1,11 @@
<?php
class WoodenPickaxeItem extends Item{
class WoodenPickaxeItem extends ItemPickaxe{
public function __construct($meta = 0, $count = 1){
parent::__construct(WOODEN_PICKAXE, $meta, $count, "Wooden Pickaxe");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 2;
}
}

View file

@ -1,11 +1,7 @@
<?php
class WoodenShovelItem extends Item{
class WoodenShovelItem extends ItemShovel{
public function __construct($meta = 0, $count = 1){
parent::__construct(WOODEN_SHOVEL, $meta, $count, "Wooden Shovel");
}
public function isTool(){
return true;
}
}

View file

@ -1,10 +1,10 @@
<?php
class WoodenSwordItem extends Item{
class WoodenSwordItem extends ItemSword{
public function __construct($meta = 0, $count = 1){
parent::__construct(WOODEN_SWORD, $meta, $count, "Wooden Sword");
}
public function isTool(){
return true;
public function getDamageAgainstOf($e){
return 4;
}
}