Skip to content

Commit

Permalink
Added config for generating the grave on the ground when dying mid-air
Browse files Browse the repository at this point in the history
  • Loading branch information
B1n-ry committed Sep 29, 2024
1 parent c67b527 commit f3aba36
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# You're in Grave Danger 2.0.6

### Changes
* Added new config to look downward for ground to place a grave on, when dying in
the air

### Fixes
* If dying for the first time in a world with an empty inventory, players will
no longer be disconnected.
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/b1n_ry/yigd/components/GraveComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ public DirectionalPos findGravePos(Direction defaultDirection) {
YigdConfig config = YigdConfig.getConfig();
YigdConfig.GraveConfig.Range generationMaxDistance = config.graveConfig.generationMaxDistance;

if (config.graveConfig.tryGenerateOnGround) {
for (BlockPos pos = this.pos.below(); pos.getY() >= this.world.getMinBuildHeight(); pos = pos.below()) {
if (!this.world.getBlockState(pos).is(YigdTags.REPLACE_SOFT_WHITELIST)) {
this.pos = pos.above();
break;
}
}
}

// Loop should ABSOLUTELY NOT loop 50 times, but in case some stupid ass person (maybe me lol) doesn't return true by default
// in canGenerate when i reaches some value (maybe 4) there is a cap at least, so the loop won't continue forever and freeze the game
for (int i = 0; i < 50; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/b1n_ry/yigd/config/YigdConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public static class GraveConfig {
public RandomSpawn randomSpawn = new RandomSpawn();
// use last ground position
public boolean generateOnLastGroundPos = false;
public boolean tryGenerateOnGround = false;
// How far in X, Y, and Z the grave can generate from where you died
@ConfigEntry.Gui.CollapsibleObject
public Range generationMaxDistance = new Range();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void graveClaimEvent(GraveClaimEvent event) {
return;
}
case PLAYER_GRAVE -> {
if (userNbt != null && Objects.equals(ResolvableProfile.CODEC.parse(NbtOps.INSTANCE, userNbt).result().orElse(null), grave.getOwner())) {
if (Objects.equals(ResolvableProfile.CODEC.parse(NbtOps.INSTANCE, userNbt).result().orElse(null), grave.getOwner())) {
tool.shrink(1);
event.setCanClaim(true);
event.setCanceled(true);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/yigd/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"text.autoconfig.yigd.option.graveConfig.randomSpawn.spawnEntity": "Entity",
"text.autoconfig.yigd.option.graveConfig.randomSpawn.spawnNbt": "Entity NBT",
"text.autoconfig.yigd.option.graveConfig.generateOnLastGroundPos": "Generate Where Last on Ground",
"text.autoconfig.yigd.option.graveConfig.tryGenerateOnGround": "Try Generate On Ground",
"text.autoconfig.yigd.option.graveConfig.generationMaxDistance": "Max Distance Generated From Death Location",
"text.autoconfig.yigd.option.graveConfig.generationMaxDistance.x": "X",
"text.autoconfig.yigd.option.graveConfig.generationMaxDistance.y": "Y",
Expand Down

0 comments on commit f3aba36

Please sign in to comment.