Skip to content

Commit

Permalink
add preconditions to conduit registration
Browse files Browse the repository at this point in the history
  • Loading branch information
rlnt committed Nov 10, 2023
1 parent d6d6a51 commit d2f738c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog],
and this project adheres to [Semantic Versioning].

## [0.4.0] - 2023-11-10

### Added
- added `EnderIOEvents.conduits` event to allow adding custom energy conduits

## [0.3.1] - 2023-09-22

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.enderio.EnderIO;
import com.enderio.api.conduit.ConduitItemFactory;
import com.enderio.api.conduit.ConduitTypes;
import com.google.common.base.Preconditions;
import dev.latvian.mods.kubejs.event.EventJS;
import dev.latvian.mods.rhino.util.HideFromJS;
import net.minecraft.world.item.Item;
Expand All @@ -19,6 +20,13 @@ public class ConduitRegistryEvent extends EventJS {
public static final Set<CustomConduitEntry> CONDUITS = new HashSet<>();

public void registerEnergyConduit(String id, String name, int transferRate) {
Preconditions.checkArgument(!id.contains(":"), "id must not contain a colon (:)");
Preconditions.checkArgument(!id.contains(" "), "id must not contain a space");
Preconditions.checkArgument(
CONDUITS.stream().anyMatch(conduit -> conduit.id().equals(id)),
"id must be unique"
);

var type = ConduitTypes.CONDUIT_TYPES.register(id, () -> new CustomEnergyConduitType(
EnderIO.loc("block/conduit/" + id),
transferRate
Expand Down

0 comments on commit d2f738c

Please sign in to comment.