-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make GameSpace attachment API strictly typed
- Loading branch information
Showing
5 changed files
with
55 additions
and
16 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/xyz/nucleoid/plasmid/game/GameAttachment.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,20 @@ | ||
package xyz.nucleoid.plasmid.game; | ||
|
||
import net.minecraft.util.Identifier; | ||
|
||
public class GameAttachment<T> { | ||
private final Identifier id; | ||
|
||
private GameAttachment(Identifier id) { | ||
this.id = id; | ||
} | ||
|
||
public static <T> GameAttachment<T> create(Identifier id) { | ||
return new GameAttachment<>(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.id.toString(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/xyz/nucleoid/plasmid/game/GameAttachmentHolder.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,18 @@ | ||
package xyz.nucleoid.plasmid.game; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface GameAttachmentHolder { | ||
@Nullable | ||
<T> T getAttachment(GameAttachment<? extends T> attachment); | ||
|
||
default <T> T getAttachmentOrThrow(GameAttachment<? extends T> attachment) { | ||
T value = this.getAttachment(attachment); | ||
if (value == null) { | ||
throw new IllegalArgumentException("Missing attachment " + attachment + " on " + this); | ||
} | ||
return value; | ||
} | ||
|
||
<T> void setAttachment(GameAttachment<? super T> attachment, @Nullable T value); | ||
} |
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