More Events
Since Hytale doesn't support certain cancellable events yet, I've made a mod that adds them!
With this mod you can treat events like :
- Gathering
- Harvesting
- Filling Buckets
- Placing Fluids
- Changing block styles
As you would other cancellable events like breaking or placing blocks without interfering with the ability of other mods to customize the behavior of those events.
This is pretty neat because if, for example, you wanted to modify an interaction behavior across two plugins using only class registration overrides the logic of BOTH plugins would have to go into one, as the override is a server-wide (not plugin-specific) setting.
How to use it
Download MoreEvents
Move MoreEvents.jar into your plugin dependency folder (the same folder as the Hytale.jar your plugin references for dependencies)
Mark MoreEvents.jar as a compile-only dependency in build.gradle.kts (or your equivalent) :
dependencies {
compileOnly(files("libs/HytaleServer.jar"))
compileOnly(files("libs/MoreEvents-1.0.jar"))
}
Add MoreEvents to your mod's manifest.json as a dependency in the format :
"Dependencies" : {
"Mods:MoreEvents" : ">=1.0.0"
}
Import the event you'd like to use
Register a system with the imported event! Ex :
public class YourPlugin extends JavaPlugin {
@Override
protected void setup() {
getEntityStoreRegistry().registerSystem(
new PlaceFluidEventSystem(PlaceFluidEvent.class));
}
}
public class PlaceFluidEventSystem extends EntityEventSystem<EntityStore, PlaceFluidEvent> {
public PlaceFluidEventSystem(@Nonnull Class<PlaceFluidEvent> eventType) {
super(eventType);
}
@Override
public void handle(int i, @Nonnull ArchetypeChunk<EntityStore> archetypeChunk,
@Nonnull Store<EntityStore> store,
@Nonnull CommandBuffer<EntityStore> commandBuffer,
@Nonnull PlaceFluidEvent placeFluidEvent) {
}
@Nullable
@Override
public Query<EntityStore> getQuery() {
return Player.getComponentType();
}
}
Don't see the event you want?
There are now generic events you can listen for when a player hits or interacts (F Key) with a block and use the provided context to detect specific events. This event intercepts these interactions early enough to actually cancel most of them, unlike the event built in to Hytale.
If you'd like to request that a specific kind of event be added to the plugin, just ask and I'll see if I can add support for it.