Skip to content

Commit

Permalink
Fixed items from creative stacking bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RKAbdul authored Nov 7, 2020
1 parent 3c6c72c commit e22899d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/RKAbdul/OreSpawners/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ public function onPlayerInteract(PlayerInteractEvent $event) {
array_push($blocks, $blockID);
};
if (in_array($event->getBlock()->getId(), $blocks)) {
if (!$item->getNamedTag()->hasTag("orespawner")) return;
$tile = $event->getPlayer()->getLevel()->getTile($event->getBlock());
if (!$tile instanceof SimpleTile) return;
$event->setCancelled(true);
if($player->getGamemode() == 1) return $player->sendMessage(TF::RED . "You can only use stacking system in survival");
$stacked = $tile instanceof SimpleTile ? $tile->getData("stacked")->getValue() : 1;

if (!in_array($item->getId(), $blocks)) return $player->sendMessage("§aThere are currently " . TF::YELLOW . $stacked. " §astacked OreSpawners");
if ($event->getBlock()->getId() != $item->getId()) return $player->sendMessage("§cPlease hold the right type of OreSpawner to stack");
if ($stacked >= intval($this->cfg["max"])) return $player->sendMessage(str_replace("&", "§", $this->cfg["limit-reached"] ?? "&cYou can't stack anymore orespawners, you have reached the limit"));

$event->setCancelled(true);

$tile->setData("stacked", $stacked + 1);
$item->setCount($item->getCount() - 1);
$player->getInventory()->setItem($player->getInventory()->getHeldItemIndex(), $item);
Expand All @@ -110,11 +111,7 @@ public function onPlayerInteract(PlayerInteractEvent $event) {

public function getDelay(Block $block) {
$tile = $block->getLevel()->getTile($block->asVector3());
if ($tile instanceof SimpleTile) {
$stacked = $tile->getData("stacked")->getValue();
} else {
$stacked = 1;
}
$stacked = $tile->getData("stacked")->getValue();
$base = intval($this->cfg["base-delay"]);
$delay = ($base / $stacked) * 20;
return $delay;
Expand Down

0 comments on commit e22899d

Please sign in to comment.