-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
## #43: Prevent players from swimming up waterfalls #46
Open
Nixotica
wants to merge
5
commits into
main
Choose a base branch
from
spike/waterfall-swimming
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
30ddb62
## #43: Prevent players from swimming up waterfalls
Nixotica 3fd81c1
Improve error messages for missing registry entries (#49)
mworzala be44f88
Fix a few minor bugs (#47)
GreatWyrm 1aede46
Changes for splitting project (#50)
mworzala 87dcff9
#43: Prevent players from swimming up waterfalls
Nixotica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 22 additions & 0 deletions
22
modules/common/src/main/java/net/hollowcube/registry/MissingEntryException.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,22 @@ | ||
package net.hollowcube.registry; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MissingEntryException extends RuntimeException{ | ||
private final @NotNull Registry<?> registry; | ||
private final @NotNull String key; | ||
|
||
public MissingEntryException(@NotNull Registry<?> registry, @NotNull String key) { | ||
super("Missing registry entry: " + key + " in " + registry + "!"); | ||
this.registry = registry; | ||
this.key = key; | ||
} | ||
|
||
public @NotNull Registry<?> registry() { | ||
return registry; | ||
} | ||
|
||
public @NotNull String key() { | ||
return key; | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
modules/common/src/test/java/net/hollowcube/registry/TestMissingEntry.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,17 @@ | ||
package net.hollowcube.registry; | ||
|
||
import com.google.gson.JsonParser; | ||
import com.mojang.serialization.JsonOps; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class TestMissingEntry { | ||
|
||
@Test | ||
public void testMissingRegistryEntry() { | ||
var json = JsonParser.parseString("{\"type\": \"missing\"}"); | ||
assertThrows(MissingEntryException.class, () -> JsonOps.INSTANCE.withDecoder(TestResource.CODEC).apply(json)); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
modules/common/src/test/java/net/hollowcube/registry/TestResource.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,26 @@ | ||
package net.hollowcube.registry; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minestom.server.utils.NamespaceID; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface TestResource extends Resource { | ||
|
||
Codec<TestResource> CODEC = Factory.CODEC.dispatch(Factory::from, Factory::codec); | ||
|
||
abstract class Factory extends ResourceFactory<TestResource> { | ||
static Registry<Factory> REGISTRY = Registry.service("test_resource", Factory.class); | ||
static Registry.Index<Class<?>, Factory> TYPE_REGISTRY = REGISTRY.index(Factory::type); | ||
|
||
static Codec<Factory> CODEC = Codec.STRING.xmap(ns -> REGISTRY.required(ns), Factory::name); | ||
|
||
public Factory(NamespaceID namespace, Class<? extends TestResource> type, Codec<? extends TestResource> codec) { | ||
super(namespace, type, codec); | ||
} | ||
|
||
public static @NotNull Factory from(@NotNull TestResource resource) { | ||
return TYPE_REGISTRY.get(resource.getClass()); | ||
} | ||
} | ||
|
||
} |
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
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
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
37 changes: 37 additions & 0 deletions
37
modules/player/src/main/java/net/hollowcube/player/event/PlayerBubbleColumnSinkEvent.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,37 @@ | ||
package net.hollowcube.player.event; | ||
|
||
import net.minestom.server.entity.Player; | ||
import net.minestom.server.event.trait.PlayerInstanceEvent; | ||
import net.minestom.server.instance.block.Block; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class PlayerBubbleColumnSinkEvent implements PlayerInstanceEvent { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure if an event is strictly necessary right now. It may be useful in the future, but I'm uncertain if it needs to be included here. |
||
private final Player player; | ||
private final int energyLevel; | ||
|
||
public PlayerBubbleColumnSinkEvent(Player player, int energyLevel) { | ||
this.player = player; | ||
this.energyLevel = energyLevel; | ||
} | ||
|
||
@Override | ||
public @NotNull Player getPlayer() { | ||
return player; | ||
} | ||
|
||
public int getEnergyLevel() { | ||
return energyLevel; | ||
} | ||
|
||
public void cancelPlayerSwimming() { | ||
if (player.getInstance().getBlock(player.getPosition()) == Block.BUBBLE_COLUMN) { | ||
player.setFood(6); | ||
} | ||
} | ||
|
||
public void restorePlayerEnergy() { | ||
if (player.getInstance().getBlock(player.getPosition()) != Block.BUBBLE_COLUMN) { | ||
player.setFood(energyLevel); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove these changes, as I am making this change in a separate PR.