Simplified tile creation

This commit is contained in:
jasonwynn10 2017-11-11 23:17:54 -05:00
parent 2a9c440d10
commit 1a5c3fb8f4

View file

@ -25,16 +25,13 @@ use pocketmine\block\Block;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender; use pocketmine\command\ConsoleCommandSender;
use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\level\ChunkLoadEvent;
use pocketmine\event\level\ChunkPopulateEvent; use pocketmine\event\level\ChunkPopulateEvent;
use pocketmine\event\Listener; use pocketmine\event\Listener;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\level\generator\biome\Biome; use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\Generator; use pocketmine\level\generator\Generator;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\level\Level;
use pocketmine\nbt\tag\IntTag; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\plugin\PluginBase; use pocketmine\plugin\PluginBase;
use pocketmine\tile\Chest; use pocketmine\tile\Chest;
@ -222,7 +219,6 @@ class Main extends PluginBase implements Listener {
return BetterForest::registerForest($name, $treeClass, $infos); return BetterForest::registerForest($name, $treeClass, $infos);
} }
/** /**
* Checks when a chunk populates to populate chests back * Checks when a chunk populates to populate chests back
* *
@ -242,50 +238,25 @@ class Main extends PluginBase implements Listener {
} }
} }
/** /**
* Checks when a player touches an ungenerated chest to generate it. * Loads chest tiles on chest blocks when a chunk is loaded
* *
* @param PlayerInteractEvent $event * @param ChunkLoadEvent $event
* @return void
*/ */
public function onInteract(PlayerInteractEvent $event) { public function onChunkLoad(ChunkLoadEvent $event) {
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON); if ($event->getLevel()->getProvider()->getGenerator() === "betternormal") {
if ($event->getBlock()->getId() !== Block::CHEST) return; $chunk = $event->getChunk();
if (!$cfg->exists($event->getBlock()->getX() . ";" . $event->getBlock()->getY() . ";" . $event->getBlock()->getZ())) return; for ($x = 0; $x < 16; $x++) {
$nbt = new CompoundTag("", [ for ($z = 0; $z < 16; $z++) {
new ListTag("Items", []), for ($y = 0; $y <= Level::Y_MAX; $y++) {
new StringTag("id", Tile::CHEST), $id = $chunk->getBlockId($x, $y, $z);
new IntTag("x", $event->getBlock()->x), $tile = $chunk->getTile($x, $y, $z);
new IntTag("y", $event->getBlock()->y), if($id === Block::CHEST and $tile === null) {
new IntTag("z", $event->getBlock()->z) Tile::createTile(Tile::CHEST, $event->getLevel(), Chest::createNBT($pos = new Vector3($chunk->getX() * 16 + $x, $y, $chunk->getZ() * 16 + $z), null)); //TODO: set face correctly
]); }
/** @var Chest $chest */ }
$chest = Tile::createTile(Tile::CHEST, $event->getBlock()->getLevel(), $nbt); }
$chest->setName("§k(Fake)§r Minecart chest"); }
LootTable::fillChest($chest->getInventory(), $event->getBlock());
} }
/**
* Checks when a players breaks an ungenerated chest to generate it.
*
* @param BlockBreakEvent $event
* @return void
*/
public function onBlockBreak(BlockBreakEvent $event) {
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
if ($event->getBlock()->getId() !== Block::CHEST) return;
if (!$cfg->exists($event->getBlock()->getX() . ";" . $event->getBlock()->getY() . ";" . $event->getBlock()->getZ())) return;
$nbt = new CompoundTag("", [
new ListTag("Items", []),
new StringTag("id", Tile::CHEST),
new IntTag("x", $event->getBlock()->x),
new IntTag("y", $event->getBlock()->y),
new IntTag("z", $event->getBlock()->z)
]);
/** @var Chest $chest */
$chest = Tile::createTile(Tile::CHEST, $event->getBlock()->getLevel(), $nbt);
$chest->setName("§k(Fake)§r Minecart chest");
LootTable::fillChest($chest->getInventory(), $event->getBlock());
} }
} }