Skip to content

Commit

Permalink
Grave selection GUI will no longer say you have the same amount of le…
Browse files Browse the repository at this point in the history
…vels as xp points

Empty graves will generate if they are configured to
Added some logging and a message to a player if a grave failed to generate
  • Loading branch information
B1n-ry committed Sep 11, 2024
1 parent de32653 commit 99774dd
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
### Fixes
* Graves can now generate below y=0 (if blocks can exist there) when `generateGraveInVoid`
config is set to `false`
* When selecting graves in the GUI, it will no longer tell you that you have your xp point
total number of levels
* Empty graves will now generate if they are configured to

---

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/b1n_ry/yigd/DeathHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public void onPlayerDeath(ServerPlayerEntity player, ServerWorld world, Vec3d po
GraveComponent graveComponent = new GraveComponent(player.getGameProfile(), inventoryComponent, expComponent,
world, graveGenerationPos.add(0D, .5D, 0D), new TranslatableDeathMessage(deathSource, player), killerId); // Will keep track of player grave (if enabled)

if (graveComponent.isEmpty() && respawnComponent.isEmpty()) return; // There is literally no information worth saving

GameProfile profile = player.getGameProfile();
graveComponent.backUp();
if (!graveComponent.isEmpty() || !respawnComponent.isEmpty()) { // There is literally no information worth saving
Yigd.LOGGER.info("Did not backup data (grave data empty)");
graveComponent.backUp();
}

respawnComponent.primeForRespawn(profile);

Direction playerDirection = player.getHorizontalFacing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.b1n_ry.yigd.client.gui.widget.WCardButton;
import com.b1n_ry.yigd.client.gui.widget.WFilterableListPanel;
import com.b1n_ry.yigd.client.gui.widget.WHoverToggleButton;
import com.b1n_ry.yigd.components.ExpComponent;
import com.b1n_ry.yigd.data.GraveStatus;
import com.b1n_ry.yigd.packets.ClientPacketHandler;
import com.b1n_ry.yigd.packets.LightGraveData;
Expand Down Expand Up @@ -54,7 +55,7 @@ private WFilterableListPanel<LightGraveData, WCardButton> addGraveList(WGridPane
Text.translatable("text.yigd.gui.grave_location", gravePos.getX(), gravePos.getY(), gravePos.getZ()),
Text.translatableWithFallback("text.yigd.dimension.name." + dimensionName, dimensionName),
Text.translatable("text.yigd.gui.item_count", lightGraveData.itemCount()),
Text.translatable("text.yigd.gui.level_count", lightGraveData.xpPoints())
Text.translatable("text.yigd.gui.level_count", ExpComponent.xpToLevels(lightGraveData.xpPoints()))
));
wCardButton.setOnClick(() -> ClientPacketHandler.sendGraveOverviewRequest(lightGraveData.id()));
});
Expand Down
31 changes: 17 additions & 14 deletions src/main/java/com/b1n_ry/yigd/components/ExpComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,7 @@ private double getTotalExperience(ServerPlayerEntity player) {
}

public int getXpLevel() {
int totalXp = this.storedXp;

int i;
for (i = 0; totalXp >= 0; i++) {
if (i < 16) {
totalXp -= (2 * i) + 7;
} else if(i < 31) {
totalXp -= (5 * i) - 38;
} else {
totalXp -= (9 * i) - 158;
}
}

return i - 1;
return ExpComponent.xpToLevels(this.storedXp);
}

public boolean isEmpty() {
Expand Down Expand Up @@ -123,6 +110,22 @@ public static void clearXp(ServerPlayerEntity player) {
player.experienceProgress = 0;
}

public static int xpToLevels(int totalXp) {

int i;
for (i = 0; totalXp >= 0; i++) {
if (i < 16) {
totalXp -= (2 * i) + 7;
} else if(i < 31) {
totalXp -= (5 * i) - 38;
} else {
totalXp -= (9 * i) - 158;
}
}

return i - 1;
}

public ExpComponent copy() {
return new ExpComponent(this.storedXp, this.originalXp);
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/b1n_ry/yigd/components/GraveComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@ public void placeAndLoad(Direction direction, DeathContext context, BlockPos pos
.with(net.minecraft.state.property.Properties.HORIZONTAL_FACING, direction)
.with(Properties.WATERLOGGED, waterlogged);

respawnComponent.setGraveGenerated(true); // Not guaranteed yet, but only errors can stop it from generating after this point
DeathInfoManager.INSTANCE.markDirty(); // Make sure respawn component is updated

// At this point is where the END_OF_TICK would be implemented, unless it wasn't already so
Yigd.END_OF_TICK.add(() -> {
BlockState previousState = world.getBlockState(pos);
Expand All @@ -337,14 +334,18 @@ public void placeAndLoad(Direction direction, DeathContext context, BlockPos pos
BlockPos placedPos = this.getPos();

if (!placed) {
Yigd.LOGGER.error("Failed to generate grave at X: %d, Y: %d, Z: %d, %s".formatted(
Yigd.LOGGER.error("Failed to generate grave at X: %d, Y: %d, Z: %d, %s. Grave block placement failed".formatted(
placedPos.getX(), placedPos.getY(), placedPos.getZ(), world.getRegistryKey().getValue()));
Yigd.LOGGER.info("Dropping items on ground instead of in grave");
context.player().sendMessage(Text.translatable("text.yigd.message.grave_generation_error"));
this.getInventoryComponent().dropGraveItems(world, Vec3d.of(placedPos));
this.getExpComponent().dropAll(world, Vec3d.of(placedPos));
return;
}

respawnComponent.setGraveGenerated(true); // Not guaranteed yet, but only errors can stop it from generating after this point
DeathInfoManager.INSTANCE.markDirty(); // Make sure respawn component is updated

GraveBlockEntity be = (GraveBlockEntity) world.getBlockEntity(placedPos);
if (be == null) return;
be.setPreviousState(previousState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ public static void registerEventCallbacks() {
YigdConfig.GraveConfig graveConfig = YigdConfig.getConfig().graveConfig;
if (!graveConfig.enabled) return false;

if (DeathInfoManager.INSTANCE.getGraveListMode() == ListMode.WHITELIST && !DeathInfoManager.INSTANCE.isInList(context.player().getGameProfile())) return false;
if (DeathInfoManager.INSTANCE.getGraveListMode() == ListMode.BLACKLIST && DeathInfoManager.INSTANCE.isInList(context.player().getGameProfile())) return false;
if (DeathInfoManager.INSTANCE.getGraveListMode() == ListMode.WHITELIST && !DeathInfoManager.INSTANCE.isInList(context.player().getGameProfile())
|| DeathInfoManager.INSTANCE.getGraveListMode() == ListMode.BLACKLIST && DeathInfoManager.INSTANCE.isInList(context.player().getGameProfile())) {
Yigd.LOGGER.info("%s found on whitelist/blacklist, disallowing grave generation");
return false;
}

if (!graveConfig.generateEmptyGraves && grave.isGraveEmpty()) return false;

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 @@ -75,6 +75,7 @@
"text.yigd.message.irl_time": " (%d %s, %d, %d:%d%s)",
"text.yigd.message.grave_destroyed": "Your grave has been unexpectedly destroyed. With proper permissions graves can be restored by using /yigd commands",
"text.yigd.message.grave_relocated": "Your grave has been relocated to X: %d / Y: %d / Z: %d / %s",
"text.yigd.message.grave_generation_error": "Grave failed to generate. Dropping items",

"text.yigd.dimension.name.minecraft:overworld": "The Overworld",
"text.yigd.dimension.name.minecraft:the_nether": "The Nether",
Expand Down

0 comments on commit 99774dd

Please sign in to comment.