本文整理汇总了PHP中pocketmine\event\inventory\CraftItemEvent类的典型用法代码示例。如果您正苦于以下问题:PHP CraftItemEvent类的具体用法?PHP CraftItemEvent怎么用?PHP CraftItemEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CraftItemEvent类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: craftEvent
public function craftEvent(CraftItemEvent $event)
{
$ItemId = $event->getRecipe()->getResult()->getId() . ":" . $event->getRecipe()->getResult()->getDamage();
if ($this->isData($ItemId)) {
$event->setCancelled(true);
$event->getPlayer()->sendMessage(TextFormat::RED . $ItemId . "조합 금지 블록을 사용하였습니다");
}
}
示例2: execute
public function execute()
{
if ($this->hasExecuted() or !$this->canExecute()) {
return false;
}
Server::getInstance()->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $this->getMatchingRecipe()));
if ($ev->isCancelled()) {
foreach ($this->inventories as $inventory) {
$inventory->sendContents($inventory->getViewers());
}
return false;
}
foreach ($this->transactions as $transaction) {
$transaction->getInventory()->setItem($transaction->getSlot(), $transaction->getTargetItem(), $this->getSource());
}
$this->hasExecuted = true;
return true;
}
示例3: onCrafting
/**
* @priority LOWEST
*/
public function onCrafting(CraftItemEvent $event)
{
echo __METHOD__ . "," . __LINE__ . "\n";
//##DEBUG
foreach ($event->getTransaction()->getInventories() as $inv) {
echo __METHOD__ . "," . __LINE__ . "\n";
//##DEBUG
if ($inv instanceof PlayerInventory) {
continue;
}
echo __METHOD__ . "," . __LINE__ . "\n";
//##DEBUG
$player = $inv->getHolder();
if (!$this->auth->isPlayerAuthenticated($inv->getHolder())) {
echo __METHOD__ . "," . __LINE__ . "\n";
//##DEBUG
$event->setCancelled(true);
return;
}
}
}
示例4: handleDataPacket
//.........这里部分代码省略.........
$canCraft = false;
}
} else {
$canCraft = false;
}
/** @var Item[] $ingredients */
$ingredients = $packet->input;
$result = $packet->output[0];
if (!$canCraft or !$recipe->getResult() === $result) {
$this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": expected " . $recipe->getResult() . ", got " . $result . ", using: " . implode(", ", $ingredients));
$this->inventory->sendContents($this);
break;
}
$used = array_fill(0, $this->inventory->getSize(), 0);
foreach ($ingredients as $ingredient) {
$slot = -1;
foreach ($this->inventory->getContents() as $index => $i) {
if ($ingredient->getId() !== 0 and $ingredient === $i and $i->getDamage() !== null and $i->getCount() - $used[$index] >= 1) {
$slot = $index;
$used[$index]++;
break;
}
}
if ($ingredient->getId() !== 0 and $slot === -1) {
$canCraft = false;
break;
}
}
if (!$canCraft) {
$this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": client does not have enough items, using: " . implode(", ", $ingredients));
$this->inventory->sendContents($this);
break;
}
$this->server->getPluginManager()->callEvent($ev = new CraftItemEvent($ingredients, $recipe));
if ($ev->isCancelled()) {
$this->inventory->sendContents($this);
break;
}
foreach ($used as $slot => $count) {
if ($count === 0) {
continue;
}
$item = $this->inventory->getItem($slot);
if ($item->getCount() > $count) {
$newItem = clone $item;
$newItem->setCount($item->getCount() - $count);
} else {
$newItem = Item::get(Item::AIR, 0, 0);
}
$this->inventory->setItem($slot, $newItem);
}
$extraItem = $this->inventory->addItem($recipe->getResult());
if (count($extraItem) > 0) {
foreach ($extraItem as $item) {
$this->level->dropItem($this, $item);
}
}
switch ($recipe->getResult()->getId()) {
case Item::WORKBENCH:
$this->awardAchievement("buildWorkBench");
break;
case Item::WOODEN_PICKAXE:
$this->awardAchievement("buildPickaxe");
break;
case Item::FURNACE:
$this->awardAchievement("buildFurnace");
示例5: handleDataPacket
//.........这里部分代码省略.........
* it will send the recipe UUID for a wooden pressure plate. Unknown currently whether this is a client
* bug or if there is something wrong with the way the server handles recipes.
* TODO: Remove recipe correction and fix desktop crafting recipes properly.
* In fact, TODO: Rewrite crafting entirely.
*/
$possibleRecipes = $this->server->getCraftingManager()->getRecipesByResult($packet->output[0]);
if (!$packet->output[0]->deepEquals($recipe->getResult())) {
$this->server->getLogger()->debug("Mismatched desktop recipe received from player " . $this->getName() . ", expected " . $recipe->getResult() . ", got " . $packet->output[0]);
}
$recipe = null;
foreach ($possibleRecipes as $r) {
/* Check the ingredient list and see if it matches the ingredients we've put into the crafting grid
* As soon as we find a recipe that we have all the ingredients for, take it and run with it. */
//Make a copy of the floating inventory that we can make changes to.
$floatingInventory = clone $this->floatingInventory;
$ingredients = $r->getIngredientList();
//Check we have all the necessary ingredients.
foreach ($ingredients as $ingredient) {
if (!$floatingInventory->contains($ingredient)) {
//We're short on ingredients, try the next recipe
$canCraft = false;
break;
}
//This will only be reached if we have the item to take away.
$floatingInventory->removeItem($ingredient);
}
if ($canCraft) {
//Found a recipe that works, take it and run with it.
$recipe = $r;
break;
}
}
if ($recipe !== null) {
$this->server->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $ingredients, $recipe));
if ($ev->isCancelled()) {
$this->inventory->sendContents($this);
break;
}
$this->floatingInventory = $floatingInventory;
//Set player crafting inv to the idea one created in this process
$this->floatingInventory->addItem(clone $recipe->getResult());
//Add the result to our picture of the crafting inventory
} else {
$this->server->getLogger()->debug("Unmatched desktop crafting recipe " . $packet->id . " from player " . $this->getName());
$this->inventory->sendContents($this);
break;
}
} else {
if ($recipe instanceof ShapedRecipe) {
for ($x = 0; $x < 3 and $canCraft; ++$x) {
for ($y = 0; $y < 3; ++$y) {
$item = $packet->input[$y * 3 + $x];
$ingredient = $recipe->getIngredient($x, $y);
if ($item->getCount() > 0 and $item->getId() > 0) {
if ($ingredient == null) {
$canCraft = false;
break;
}
if ($ingredient->getId() != 0 and !$ingredient->deepEquals($item, $ingredient->getDamage() !== null, $ingredient->getCompoundTag() !== null)) {
$canCraft = false;
break;
}
} elseif ($ingredient !== null and $item->getId() !== 0) {
$canCraft = false;
break;
}
示例6: onCraftItem
public function onCraftItem(CraftItemEvent $event)
{
$t = $event->getTransaction();
if (!($p = $t->getSource()) instanceof Player) {
return;
}
$r = $t->getResult();
if (!$p->hasPermission("mineblock.bancraft.craft") && in_array($id = $r->getID() . ":" . $r->getDamage(), $this->bc)) {
$p->sendMessage("[BanCraft] {$id}" . ($this->isKorean() ? "는 조합금지 아이템입니다. 조합할수없습니다." : " is Ban. You can't craft."));
$p->getInventory()->sendContents($p);
$event->setCancelled();
}
}
示例7: handleDataPacket
//.........这里部分代码省略.........
$canCraft = false;
}
} else {
$canCraft = false;
}
/** @var Item[] $ingredients */
$ingredients = $packet->input;
$result = $packet->output[0];
if (!$canCraft or !$recipe->getResult()->deepEquals($result)) {
$this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": expected " . $recipe->getResult() . ", got " . $result . ", using: " . implode(", ", $ingredients));
$this->inventory->sendContents($this);
break;
}
$used = array_fill(0, $this->inventory->getSize(), 0);
foreach ($ingredients as $ingredient) {
$slot = -1;
foreach ($this->inventory->getContents() as $index => $i) {
if ($ingredient->getId() !== 0 and $ingredient->deepEquals($i, $ingredient->getDamage() !== null) and $i->getCount() - $used[$index] >= 1) {
$slot = $index;
$used[$index]++;
break;
}
}
if ($ingredient->getId() !== 0 and $slot === -1) {
$canCraft = false;
break;
}
}
if (!$canCraft) {
$this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": client does not have enough items, using: " . implode(", ", $ingredients));
$this->inventory->sendContents($this);
break;
}
$this->server->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $ingredients, $recipe));
if ($ev->isCancelled()) {
$this->inventory->sendContents($this);
break;
}
foreach ($used as $slot => $count) {
if ($count === 0) {
continue;
}
$item = $this->inventory->getItem($slot);
if ($item->getCount() > $count) {
$newItem = clone $item;
$newItem->setCount($item->getCount() - $count);
} else {
$newItem = Item::get(Item::AIR, 0, 0);
}
$this->inventory->setItem($slot, $newItem);
}
$extraItem = $this->inventory->addItem($recipe->getResult());
if (count($extraItem) > 0) {
foreach ($extraItem as $item) {
$this->level->dropItem($this, $item);
}
}
switch ($recipe->getResult()->getId()) {
case Item::WORKBENCH:
$this->awardAchievement("buildWorkBench");
break;
case Item::WOODEN_PICKAXE:
$this->awardAchievement("buildPickaxe");
break;
case Item::FURNACE:
$this->awardAchievement("buildFurnace");
示例8: onCraftItem
public function onCraftItem(CraftItemEvent $event)
{
//CraftingBug
$recipe = $event->getRecipe();
if (!$event->isCancelled() and $recipe instanceof ShapedRecipe and self::ENABLE_CRAFTING_BUG) {
//todo もっと効率的な処理
$player = $event->getPlayer();
$event->setCancelled();
//イベントをキャンセル
$mapitems = $recipe->getIngredientMap();
$items = array();
foreach ($mapitems as $key => $map) {
//mapから材料となるアイテムをまとめる
foreach ($map as $key2 => $item) {
$r = true;
foreach ($items as $item2) {
if ($item->equals($item2)) {
$item2->setCount($item2->getCount() + 1);
$r = false;
break;
}
}
if ($r and $item->getId() !== Item::AIR) {
$items[] = $item;
}
}
}
foreach ($items as $item) {
//材料となるアイテムを持っているかを一応確認
if (!$player->getInventory()->contains($item)) {
echo "test";
return false;
}
}
$debug = "";
$contents = $player->getInventory()->getContents();
foreach ($items as $item) {
//材料アイテムをプレーヤーからとる
$count = $item->getCount();
$checkDamage = $item->getDamage() === null ? false : true;
$checkTags = $item->getCompoundTag() === null ? false : true;
foreach ($contents as $slot => $i) {
if ($item->equals($i, $checkDamage, $checkTags)) {
$nc = min($i->getCount(), $count);
$count -= $nc;
$newItem = clone $i;
$newItem->setCount($i->getCount() - $nc);
$player->getInventory()->setItem($slot, $newItem);
$debug .= "test:" . $i . "\n";
$debug .= $newItem . "\ncount." . $count . "\nnc." . $nc . "\nbc." . $item->getCount() . "\n\n";
}
if ($count <= 0) {
break;
}
}
if ($count > 0) {
continue;
//...
}
}
$debug .= "result:" . $recipe->getResult() . "\n\n";
$extra = $player->getInventory()->addItem($recipe->getResult());
//完成後のアイテムをインベントリへ
if (count($extra) > 0) {
foreach ($extra as $item) {
//インベントリが一杯だった場合はその場にドロップさせる
$player->getLevel()->dropItem($player, $item);
}
}
$this->getLogger()->debug($debug);
} else {
$event->setCancelled();
}
}
示例9: onCraftItem
public function onCraftItem(CraftItemEvent $event)
{
/**
* @var $player Player
*/
$player = $event->getPlayer();
$craftingPlayer = $this->getRPGPlayerByName($event->getPlayer());
if ($craftingPlayer === null) {
$player->sendMessage(TextFormat::RED . self::getTranslation("INVALID_PLAYER"));
$event->setCancelled();
return;
}
$recipe = $event->getRecipe();
if ($recipe instanceof ShapelessRecipe) {
foreach ($recipe->getIngredientList() as $item) {
echo $item->getName() . "x" . $item->getCount();
if ($craftingPlayer->getSkillByItem($item) !== null) {
if (!$player->getInventory()->contains(Item::get($item->getId(), $item->getDamage(), $item->getCount() + 1))) {
echo "cancelledEvent";
$event->setCancelled();
return;
}
}
}
}
if ($recipe instanceof ShapedRecipe) {
foreach ($recipe->getIngredientMap() as $items) {
/**
* @var $item Item
*/
foreach ($items as $item) {
if ($craftingPlayer->getSkillByItem($item) !== null) {
if (!$player->getInventory()->contains(Item::get($item->getId(), $item->getDamage(), $item->getCount() + 1))) {
$event->setCancelled();
return;
}
}
}
}
}
}
示例10: handleDataPacket
//.........这里部分代码省略.........
} else {
$canCraft = false;
}
/** @var Item[] $ingredients */
$canCraft = true;
//0.13.1大量物品本地配方出现问题,无法解决,使用极端(唯一)方法修复.
$ingredients = $packet->input;
$result = $packet->output[0];
if (!$canCraft or !$recipe->getResult()->deepEquals($result)) {
$this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": expected " . $recipe->getResult() . ", got " . $result . ", using: " . implode(", ", $ingredients));
$this->inventory->sendContents($this);
break;
}
$used = array_fill(0, $this->inventory->getSize(), 0);
foreach ($ingredients as $ingredient) {
$slot = -1;
foreach ($this->inventory->getContents() as $index => $i) {
if ($ingredient->getId() !== 0 and $ingredient->deepEquals($i, $ingredient->getDamage() !== null) and $i->getCount() - $used[$index] >= 1) {
$slot = $index;
$used[$index]++;
break;
}
}
if ($ingredient->getId() !== 0 and $slot === -1) {
$canCraft = false;
break;
}
}
if (!$canCraft) {
$this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": client does not have enough items, using: " . implode(", ", $ingredients));
$this->inventory->sendContents($this);
break;
}
$this->server->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $ingredients, $recipe));
if ($ev->isCancelled()) {
$this->inventory->sendContents($this);
break;
}
foreach ($used as $slot => $count) {
if ($count === 0) {
continue;
}
$item = $this->inventory->getItem($slot);
if ($item->getCount() > $count) {
$newItem = clone $item;
$newItem->setCount($item->getCount() - $count);
} else {
$newItem = Item::get(Item::AIR, 0, 0);
}
$this->inventory->setItem($slot, $newItem);
}
$extraItem = $this->inventory->addItem($recipe->getResult());
if (count($extraItem) > 0) {
foreach ($extraItem as $item) {
$this->level->dropItem($this, $item);
}
}
switch ($recipe->getResult()->getId()) {
case Item::WORKBENCH:
$this->awardAchievement("buildWorkBench");
break;
case Item::WOODEN_PICKAXE:
$this->awardAchievement("buildPickaxe");
break;
case Item::FURNACE:
$this->awardAchievement("buildFurnace");
示例11: handleDataPacket
//.........这里部分代码省略.........
$canCraft = false;
}
} else {
$canCraft = false;
}
/** @var Item[] $ingredients */
$ingredients = $packet->input;
$result = $packet->output[0];
if (!$canCraft or !$recipe->getResult()->deepEquals($result)) {
$this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": expected " . $recipe->getResult() . ", got " . $result . ", using: " . implode(", ", $ingredients));
$this->inventory->sendContents($this);
break;
}
$used = array_fill(0, $this->inventory->getSize(), 0);
foreach ($ingredients as $ingredient) {
$slot = -1;
foreach ($this->inventory->getContents() as $index => $i) {
if ($ingredient->getId() !== 0 and $ingredient->deepEquals($i, $i->getDamage() !== null) and $i->getCount() - $used[$index] >= 1) {
$slot = $index;
$used[$index]++;
break;
}
}
if ($ingredient->getId() !== 0 and $slot === -1) {
$canCraft = false;
break;
}
}
if (!$canCraft) {
$this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": client does not have enough items, using: " . implode(", ", $ingredients));
$this->inventory->sendContents($this);
break;
}
$this->server->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $ingredients, $recipe));
if ($ev->isCancelled()) {
$this->inventory->sendContents($this);
break;
}
foreach ($used as $slot => $count) {
if ($count === 0) {
continue;
}
$item = $this->inventory->getItem($slot);
if ($item->getCount() > $count) {
$newItem = clone $item;
$newItem->setCount($item->getCount() - $count);
} else {
$newItem = Item::get(Item::AIR, 0, 0);
}
$this->inventory->setItem($slot, $newItem);
}
$extraItem = $this->inventory->addItem($recipe->getResult());
if (count($extraItem) > 0) {
foreach ($extraItem as $item) {
$this->level->dropItem($this, $item);
}
}
switch ($recipe->getResult()->getId()) {
case Item::WORKBENCH:
$this->awardAchievement("buildWorkBench");
break;
case Item::WOODEN_PICKAXE:
$this->awardAchievement("buildPickaxe");
break;
case Item::FURNACE:
$this->awardAchievement("buildFurnace");