Implementation of hopper logic for pushing, pulling and picking up items for PocketMine-MP.

Overview

VanillaHopper

In pm4, hopper blocks were implemented to have an inventory. But the logic for pushing, pulling and picking up items was missing nonetheless. This plugin aims to add this logic to the hopper.

Optimizations

Normally a hopper should run a block update every tick to reduce and check its cooldown if it has expired. Because it is highly inefficient to update all loaded hoppers every tick, just for letting them reduce their cooldown by one, the block update of hoppers is always scheduled to the expiration of their cooldown and not directly the next tick. To prevent any issues with the cooldown, hoppers are saving in which tick they were lastly updated to prevent them from updating too early.

Customizations

Customizations can be done in the config.yml in the plugin's plugin_data folder:

  • hopper.transferCooldown: 8
    • The default cooldown of hoppers in Minecraft is 8 ticks. To in- or decrease the cooldown, you can just edit this number.
  • hopper.itemsPerUpdate: 1
    • Normally a hopper only pushes one item and pulls or picks up one per update. You can specify how many items a hopper will try to push, pull or pick up when updated. This can be useful if you increased the cooldown of hoppers but want to keep the same "item per tick" ratio.
  • hopper.alwaysSetCooldown: false
    • A hopper is normally only set on cooldown if it either pushed, pulled or picked up an item in an update. If it couldn't, it would receive another update in the next tick. As it is very performance costly that maybe dozens of hoppers of an empty hopper system are updated every tick, you can specify if hoppers should even be set back on cooldown, if they haven't pushed, pulled or picked up an item.
  • hopper.updatesPerTick: 0
    • By default, there is no limit on how many block updates can be scheduled per tick. As it would be very performance costly to have scheduled hundreds of hopper updates scheduled on the same tick, you can change this number, to limit the number of hopper updates that are allowed to be scheduled per tick. If a hopper update would be scheduled on a tick that is already on the max value, the update is scheduled on the next tick that's not on the max value.

FAQ

What are your sources?

Every information about the logic for pushing, pulling and picking up items came from the minecraft fandom wiki.

Why are there so many comments in the code?

Minecraft's hopper logic is very complex. To prevent anybody from getting confused about how certain things were done, most parts were commented to explain what was done and why.

Why not create a PR?

I did, but it was stated that hopper logic won't be implemented in pm4 and because I didn't want to maintain a PR for the time till pm5, I closed it. Still, I wanted to use that logic in a plugin to use it myself and therefore I created this.

Tests

For developers

Event handling

  • Through the different events, you can easily implement your own rules for hoppers. Handle these events by simply creating an ordinary listener (class EventListener implements Listener) in your plugin and import (use keyword) them by their namespace (event name: namespace).
  • BlockItemPickupEvent: pocketmine\event\block\BlockItemPickupEvent
    • This event is called when a hopper tries to pick up an item.
  • HopperEvent: ColinHDev\VanillaHopper\events\HopperEvent
    • This event is called when a hopper either tries to push or pull an item.
  • HopperPushEvent: ColinHDev\VanillaHopper\events\HopperPushEvent
    • This event is called when a hopper tries to push an item.
  • HopperPushContainerEvent: ColinHDev\VanillaHopper\events\HopperPushContainerEvent
    • This event is called when a hopper tries to push an item into a block's inventory.
  • HopperPushJukeboxEvent: ColinHDev\VanillaHopper\events\HopperPushJukeboxEvent
    • This event is called when a hopper tries to push a record into a jukebox.
  • HopperPullEvent: ColinHDev\VanillaHopper\events\HopperPullEvent
    • This event is called when a hopper tries to pull an item.
  • HopperPullContainerEvent: ColinHDev\VanillaHopper\events\HopperPullContainerEvent
    • This event is called when a hopper tries to pull an item from a block's inventory.
You might also like...
Toxiproxy PHP Client - Toxiproxy makes it easy and trivial to test network conditions, for example low-bandwidth and high-latency situations

Toxiproxy makes it easy and trivial to test network conditions, for example low-bandwidth and high-latency situations. toxiproxy-php-client includes everything needed to get started with configuring Toxiproxy upstream connection and listen endpoints.

Laravel Package for 1APP. Learn how to integrate our APIs to build a web or mobile integration to send and accept payments for your application and businesses.
Laravel Package for 1APP. Learn how to integrate our APIs to build a web or mobile integration to send and accept payments for your application and businesses.

1APP Laravel Library Learn how to integrate our APIs to build a web or mobile integration to accept payments, make payment of Bills and as well custom

A simple PHP GitHub API client, Object Oriented, tested and documented.

PHP GitHub API A simple Object Oriented wrapper for GitHub API, written with PHP. Uses GitHub API v3 & supports GitHub API v4. The object API (v3) is

A PHP library for communicating with the Twilio REST API and generating TwiML.

twilio-php The default branch name for this repository has been changed to main as of 07/27/2020. Documentation The documentation for the Twilio API c

A Laravel package to retrieve pageviews and other data from Google Analytics
A Laravel package to retrieve pageviews and other data from Google Analytics

Retrieve data from Google Analytics Using this package you can easily retrieve data from Google Analytics. Here are a few examples of the provided met

PHP library to use IOTA REST API to help node management and tangle queries

iota.php About PHP library to use IOTA REST API to help node management and tangle queries. Please be aware that this library is in an early developme

A simple API documentation package for Laravel using OpenAPI and Redoc

Laravel Redoc Easily publish your API documentation using your OpenAPI document in your Laravel Application. Installation You can install this package

A PHP class for querying the Twitter API and rendering tweets as an HTML list

TweetPHP A PHP class for querying the Twitter API and rendering tweets as an HTML list. Features Works with Twitter API v1.1 Tweets are cached to avoi

playSMS is a web interface for SMS gateways and bulk SMS services

README Latest development release is playSMS version 1.4.4-beta4 Latest stable release is playSMS version 1.4.3 Official project website: https://play

Comments
  • Vanilla Hopper won't pull an item from another hopper.

    Vanilla Hopper won't pull an item from another hopper.

    Vanilla Hopper won't pull an item from another hopper. Otherwise, it will pull stuff out of its above hopper at twice as speed as normal making the hopper behave wrong.

    P/s: Your is nice but I hate to say it but I didn't know there were so many hopper plugins, I already made two different hopper plugins bruh, just randomly scrolling poggit and found your. So this is the feeling of wasting time ;-;

    Resolution: Works As Intended 
    opened by NTT1906 2
Releases(v2.1.0)
  • v2.1.0(Dec 7, 2022)

  • v2.0.2(May 4, 2022)

  • v2.0.1(Jan 8, 2022)

  • v2.0.0(Dec 19, 2021)

    Changelog

    • Improved optimization
      • If a hopper did anything, it will be set on transfer cooldown and as explained above, its next update will be on the tick of the transfer. But if the hopper did nothing, it wouldn't be on cooldown and therefore would require an update on the next tick. As it is highly ineffective to schedule hundreds of hoppers for updates, who are not even doing anything, most parts are now event-driven. This means, that hoppers will only be scheduled for another block update, if an item entity landed on them or if any update on the blocks or inventories around them occurred. To accomplish this the implementation of a custom item entity and a variety of event listeners was required.
    • Removed hopper.alwaysSetCooldown customization
    Source code(tar.gz)
    Source code(zip)
    VanillaHopper.phar(29.05 KB)
  • v1.3.0(Sep 12, 2021)

    Changelog

    • Added optimization
      • Normally a hopper should run a block update every tick to reduce and check its cooldown if it has expired. Because it is highly inefficient to update all loaded hoppers every tick, just for letting them reduce their cooldown by one, the block update of hoppers is always scheduled to the expiration of their cooldown and not directly the next tick. To prevent any issues with the cooldown, hoppers are saving in which tick they were lastly updated to prevent them from updating too early.
    • Added customization
      • Customizations can be done in the config.yml in the plugin's plugin_data folder:
        • hopper.transferCooldown: 8
          • The default cooldown of hoppers in Minecraft is 8 ticks. To in- or decrease the cooldown, you can just edit this number.
        • hopper.itemsPerUpdate: 1
          • Normally a hopper only pushes one item and pulls or picks up one per update. You can specify how many items a hopper will try to push, pull or pick up when updated. This can be useful if you increased the cooldown of hoppers but want to keep the same "item per tick" ratio.
        • hopper.alwaysSetCooldown: false
          • A hopper is normally only set on cooldown if it either pushed, pulled or picked up an item in an update. If it couldn't, it would receive another update in the next tick. As it is very performance costly that maybe dozens of hoppers of an empty hopper system are updated every tick, you can specify if hoppers should even be set back on cooldown, if they haven't pushed, pulled or picked up an item.
        • hopper.updatesPerTick: 0
          • By default, there is no limit on how many block updates can be scheduled per tick. As it would be very performance costly to have scheduled hundreds of hopper updates scheduled on the same tick, you can change this number, to limit the number of hopper updates that are allowed to be scheduled per tick. If a hopper update would be scheduled on a tick that is already on the max value, the update is scheduled on the next tick that's not on the max value.
    Source code(tar.gz)
    Source code(zip)
    VanillaHopper.phar(16.53 KB)
  • v1.2.0(Sep 11, 2021)

    Changelog

    • Added HopperEvent
      • This event is called when a hopper either tries to push or pull an item.
    • Added HopperPushEvent
      • This event is called when a hopper tries to push an item.
    • Added HopperPushContainerEvent
      • This event is called when a hopper tries to push an item into a block's inventory.
    • Added HopperPushJukeboxEvent
      • This event is called when a hopper tries to push a record into a jukebox.
    • Added HopperPullEvent
      • This event is called when a hopper tries to pull an item.
    • Added HopperPullContainerEvent
      • This event is called when a hopper tries to pull an item from a block's inventory.
    • Removed HopperTransferContainerEvent
    • Removed HopperTransferJukeboxEvent
    Source code(tar.gz)
    Source code(zip)
    VanillaHopper.phar(13.53 KB)
  • v1.1.0(Sep 8, 2021)

    Changelog

    • Added usage of PocketMine-MP's BlockItemPickupEvent
      • This event is called when a hopper tries to pick up an item.
    • Added HopperTransferContainerEvent
      • This event is called when a hopper tries to either push or pull items from a container.
    • Added HopperTransferJukeboxEvent
      • This event is called when a hopper tries to either push or pull records from a jukebox.
    Source code(tar.gz)
    Source code(zip)
    VanillaHopper.phar(11.17 KB)
  • v1.0.0(Sep 8, 2021)

Owner
Colin
>~<
Colin
The Kafka Enqueue transport - This is an implementation of Queue Interop specification

Supporting Enqueue Enqueue is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and

Enqueue 40 Oct 6, 2022
PHP JSON-RPC 2.0 Server/Client Implementation with Automatic Client Class Generation via SMD

PHP JSON-RPC 2.0 Server/Client Implementation with Automatic Client Class Generation via SMD

Sergey Bykov 63 Feb 14, 2022
PHP Implementation of the all new Basecamp API

Basecamp SDK for PHP The Basecamp SDK for PHP enables PHP developers to easily integrate 37signals Basecamp all new API into their applications. NOTE:

Netvlies Internetdiensten 38 Feb 14, 2022
Implementation of a library to process SISP vinti4 payment in a easy way.

Implementation of a library to process SISP vinti4 payment in a easy way.

Faxi 6 Nov 3, 2022
PHP library with ready-to-use Yunbi API implementation.

yunbi-client-php A simple PHP client for Crypto Trade Site Yunbi.com Quick example <?php require_once('lib/yunbi-client.php'); try { $client = new

null 6 Dec 2, 2019
A PerkSystem for PocketMine-MP!

Perks System v4.5-BETA This is a Perk System for Pocketmine-MP. You can all funktion edit in config.yml Download Here you can install the new .phar fi

Bubbelwubbel 15 Aug 16, 2022
An ultimate troll plugin for PocketMine-MP

LMAO An ultimate troll plugin for PocketMine-MP Feature Feature Description Alone Hides every player, let them feed alone Burn Burn the player FakeOp

Ngọc Lam 8 Oct 20, 2022
The very FIRST ever server sided hack client for the PocketMine-MP API (4.x.x)

PHqx or Phqzing Hacks is a Server Sided Hack "Client" you can use for trolling friends (if you have one) or destroying other people at pvp.

Phqzing 5 Jul 25, 2022
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

DeviceDetector Code Status Description The Universal Device Detection library that parses User Agents and detects devices (desktop, tablet, mobile, tv

Matomo Analytics 2.4k Jan 9, 2023