Git Product home page Git Product logo

vanillahopper's Introduction

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

Improved block update scheduling

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.

Event-driven hoppers

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.

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.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

TODO

Make pushing and pulling more modular

Currently, the pushing and pulling methods are not very developer friendly when it comes to customizations, since it is hard to access and overwrite the Hopper::push() and Hopper::pull() methods without beeing forced to copy code. This could be done by implementing a behaviour system which lets developers register custom behaviours for any block. Since this would include rewriting some parts of the existing core, which would cost much time, what I do not see benefitial at the moment, PLEASE create an issue, if you find yourself needing a better implementation. Till then, this will stay as a TODO.

Implementing entity pulling

Normally, hoppers can not only pull items from blocks, but from entities like minecarts too. But since PocketMine-MP does not support them, there is no point in implementing this, since this would be out of the scope of this plugin. Although it should be at least possible to let hoppers also scan for entities when pulling, which is not possible with the current system.

Supporting more blocks

Composters, Brewing Stands and Jukeboxes are currently either not or just poorly supported. This should be changed. But since PocketMine-MP itself does not implement these blocks correctly, there is no reason for us at the moment of writing this.

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.

Custom ItemEntity class

As there is no EntityMoveEvent, which can easily be listened for, a way to check whether an item entity moved onto a hopper had to be found. This was done by implementing a custom item entity class that checks only when the entity actually moved. Otherwise, we would have to make a task that constantly checks all item entities and if they moved. So this method has the most performance benefits. But this method makes this plugin incompatible with other plugins that implement a custom item entity class, as either this or the other plugin will no longer work as intended anymore.

vanillahopper's People

Contributors

colinhdev avatar poggit-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vanillahopper's Issues

drop

Tidy up the drop, player can't drop item anywhere

Question

Any plans on updating the PM 5 branch to latest beta?

Ghost Hoppers

Placing hopper on a block makes it work fine.

Placing a hopper on a chest, furnace, another hopper, a shulker results in a “ghost” hopper. Visually the block is there but it does not function. On server restart or chunk unloading, or right clicking the hopper causes the hopper to disappear.

Minecraft_2024-03-24_08-40-17.mov
Minecraft_2024-03-24_08-40-17.mov

PM 5 Issue

For some reason the hoppers are not working on the latest PM5 version. I have attached the details below:
image

ApplicationFrameHost_DygjrnEcOd.mp4

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 ;-;

Crash

Hello, since a few days my server has crashed 2 times with your plugin VanilliaHoppers and for this error. And once the server restarted, we have a chunk that is corrupted...
Mon_Apr_10-16.58.03-CEST_2023.log

Hoppers stop working or do not work properly

Hello,

I've come to see you following several reports from our players who are reporting bugs on your latest version of your plugin (we're on the latest version of PocketMine 5).

We're getting reports that on server restarts, or just when the world unloads, the hoppers stop working or slow down (for example, we're getting reports that it transfers 1 item out of 2, etc.).

Here's our configuration:

# Define the number of ticks a hopper is on cooldown after pushing, pulling or picking up an item.
# Default: 8
hopper.transferCooldown: 8
# Define the number of items the hopper tries to push, pull or pick up when updated.
# Default: 1
hopper.itemsPerUpdate: 8
# Define how many hoppers are allowed to be updated every tick.
# Default: 0 (disabled)
hopper.updatesPerTick: 0

We suspect there may be a problem with the tiles, which have recently been modified.

Thanks in advance

Hopper not working PM5 latest

Google Translate : I don't know how to describe it, the problem is that the hopper doesn't absorb items and doesn't push items down to other chests. When I open a chest or hopper, it sends items down normally, but only for a moment it stopped. Hope you read this issue !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.