-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `UpgradeItem#isCompatibleWith` * Expose sync update tags * Add an event for when modules are executed * Add an event to register menu data * Add a capability cacher * Update .gitignore
- Loading branch information
1 parent
ad33236
commit 8b0577b
Showing
9 changed files
with
263 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,5 @@ mcmodsrepo | |
|
||
# datagen caches | ||
**/.cache | ||
|
||
repo/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/me/desht/modularrouters/api/event/ExecuteModuleEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package me.desht.modularrouters.api.event; | ||
|
||
import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; | ||
import me.desht.modularrouters.logic.compiled.CompiledModule; | ||
import net.neoforged.bus.api.Event; | ||
import net.neoforged.bus.api.ICancellableEvent; | ||
|
||
/** | ||
* Called when a router {@link me.desht.modularrouters.logic.compiled.CompiledModule#execute(ModularRouterBlockEntity) executes} a module. | ||
*/ | ||
public class ExecuteModuleEvent extends Event implements ICancellableEvent { | ||
private boolean executed; | ||
private final ModularRouterBlockEntity router; | ||
private final CompiledModule module; | ||
|
||
public ExecuteModuleEvent(ModularRouterBlockEntity router, CompiledModule module) { | ||
this.router = router; | ||
this.module = module; | ||
} | ||
|
||
/** | ||
* {@return the router executing the module} | ||
*/ | ||
public ModularRouterBlockEntity getRouter() { | ||
return router; | ||
} | ||
|
||
/** | ||
* {@return the executed module} | ||
*/ | ||
public CompiledModule getModule() { | ||
return module; | ||
} | ||
|
||
/** | ||
* If set to {@code true}, the router will consider the module executed. | ||
* | ||
* @apiNote to prevent the module itself from being executed, you need to {@link #setCanceled(boolean) cancel} the event too | ||
*/ | ||
public void setExecuted(boolean executed) { | ||
this.executed = executed; | ||
} | ||
|
||
/** | ||
* {@return whether the router should consider the module executed} | ||
*/ | ||
public boolean isExecuted() { | ||
return this.executed; | ||
} | ||
|
||
/** | ||
* Cancel this event to prevent the module from executing. | ||
*/ | ||
@Override | ||
public void setCanceled(boolean canceled) { | ||
ICancellableEvent.super.setCanceled(canceled); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/me/desht/modularrouters/api/event/RegisterRouterContainerData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package me.desht.modularrouters.api.event; | ||
|
||
import me.desht.modularrouters.block.tile.ModularRouterBlockEntity; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.inventory.ContainerData; | ||
import net.minecraft.world.inventory.DataSlot; | ||
import net.neoforged.bus.api.Event; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Fired to register {@link DataSlot data slots} for the router menu. <br> | ||
* Use this to sync data to display in the GUI. | ||
*/ | ||
public class RegisterRouterContainerData extends Event { | ||
private final ModularRouterBlockEntity router; | ||
private final Map<ResourceLocation, DataSlot> data = new HashMap<>(); | ||
|
||
@ApiStatus.Internal | ||
public RegisterRouterContainerData(ModularRouterBlockEntity router) { | ||
this.router = router; | ||
} | ||
|
||
/** | ||
* Register a {@link DataSlot data slot}. | ||
* | ||
* @param id the ID of the slot | ||
* @param dataSlot the slot to register | ||
*/ | ||
public void register(ResourceLocation id, DataSlot dataSlot) { | ||
data.put(id, dataSlot); | ||
} | ||
|
||
/** | ||
* {@return the router of the menu} | ||
*/ | ||
public ModularRouterBlockEntity getRouter() { | ||
return router; | ||
} | ||
|
||
@ApiStatus.Internal | ||
public Map<ResourceLocation, DataSlot> getData() { | ||
return Collections.unmodifiableMap(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.