Skip to content

Commit 8e966d3

Browse files
committedOct 11, 2024·
Graves will no longer overwrite other graves when dying in exact same places outside the world
1 parent 122626a commit 8e966d3

File tree

4 files changed

+47
-41
lines changed

4 files changed

+47
-41
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# You're in Grave Danger 2.4.11
22

3+
### Fixes
4+
* Graves will no longer overwrite other graves when dying in exact same places
5+
outside the world
6+
37
---
48

59
# You're in Grave Danger 2.4.10

‎gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ org.gradle.parallel=true
3333
# inventorio_version=GX7qPAzO
3434
travelers_backpack_version=1.21-10.0.6
3535
# numismatic_version=0.2.14+1.20.3
36-
# apoli_version=2.12.0-alpha.4+mc.1.20.4
36+
# apoli_version=2.12.0-alpha.12+mc.1.21.x
3737
# origins_version=v1.12.10
3838
# levelz_version=1.4.13+1.20.1
3939
# beans_backpacks_version=bsSV8DuI

‎src/main/java/com/b1n_ry/yigd/components/GraveComponent.java

+38-40
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,41 @@ public DirectionalPos findGravePos(Direction defaultDirection) {
202202
return new DirectionalPos(this.pos, defaultDirection);
203203
}
204204

205+
YigdConfig config = YigdConfig.getConfig();
206+
int y = this.pos.getY();
207+
int lowerAcceptableY = config.graveConfig.lowestGraveY + this.world.getBottomY();
208+
if (config.graveConfig.generateGraveInVoid && this.pos.getY() <= lowerAcceptableY) {
209+
y = lowerAcceptableY;
210+
}
211+
int topY = this.world.getTopY() - 1; // Can't actually place blocks at top Y
212+
if (y > topY) {
213+
y = topY;
214+
}
215+
216+
int x = this.pos.getX();
217+
int z = this.pos.getZ();
218+
if (config.graveConfig.generateOnlyWithinBorder) {
219+
WorldBorder border = this.world.getWorldBorder();
220+
if (!border.contains(x, z)) {
221+
x = (int) Math.max(x, border.getBoundWest());
222+
x = (int) Math.min(x, border.getBoundEast());
223+
224+
z = (int) Math.max(z, border.getBoundNorth());
225+
z = (int) Math.min(z, border.getBoundSouth());
226+
}
227+
}
228+
229+
this.pos = new BlockPos(x, y, z);
230+
231+
// Makes sure the grave is not broken/replaced by portal, or the dragon egg
232+
if (this.world.getRegistryKey().equals(World.END)) {
233+
if (Math.abs(this.pos.getX()) + Math.abs(this.pos.getZ()) < 25 && this.world.getBlockState(this.pos.down()).isOf(Blocks.BEDROCK))
234+
this.pos = this.pos.up();
235+
}
205236
DirectionalPos graveyardPos = this.findPosInGraveyard(defaultDirection);
206237
if (graveyardPos != null)
207238
return graveyardPos;
208239

209-
YigdConfig config = YigdConfig.getConfig();
210240
YigdConfig.GraveConfig.Range generationMaxDistance = config.graveConfig.generationMaxDistance;
211241

212242
if (config.graveConfig.tryGenerateOnGround) {
@@ -218,6 +248,8 @@ public DirectionalPos findGravePos(Direction defaultDirection) {
218248
}
219249
}
220250

251+
DeathInfoManager.INSTANCE.markDirty(); // The "this" object is (at least should be) located inside DeathInfoManager.INSTANCE
252+
221253
// Loop should ABSOLUTELY NOT loop 50 times, but in case some stupid ass person (maybe me lol) doesn't return true by default
222254
// 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
223255
for (int i = 0; i < 50; i++) {
@@ -269,50 +301,16 @@ private DirectionalPos findPosInGraveyard(Direction defaultDirection) {
269301

270302
/**
271303
* Called to place down a grave block. Should only be called from server
272-
* @param attemptedPos Where the grave should try to be placed
304+
*
273305
* @param state Which block should be placed
274306
* @return Weather or not the grave was placed
275307
*/
276-
public boolean tryPlaceGraveAt(BlockPos attemptedPos, BlockState state) {
308+
public boolean tryPlaceGrave(BlockState state) {
277309
if (this.world == null) {
278310
Yigd.LOGGER.error("GraveComponent tried to place grave without knowing the ServerWorld");
279311
return false;
280312
}
281313

282-
YigdConfig.GraveConfig config = YigdConfig.getConfig().graveConfig;
283-
int y = attemptedPos.getY();
284-
int lowerAcceptableY = config.lowestGraveY + this.world.getBottomY();
285-
if (config.generateGraveInVoid && attemptedPos.getY() <= lowerAcceptableY) {
286-
y = lowerAcceptableY;
287-
}
288-
int topY = this.world.getTopY() - 1; // Can't actually place blocks at top Y
289-
if (y > topY) {
290-
y = topY;
291-
}
292-
293-
int x = attemptedPos.getX();
294-
int z = attemptedPos.getZ();
295-
if (config.generateOnlyWithinBorder) {
296-
WorldBorder border = this.world.getWorldBorder();
297-
if (!border.contains(x, z)) {
298-
x = (int) Math.max(x, border.getBoundWest());
299-
x = (int) Math.min(x, border.getBoundEast());
300-
301-
z = (int) Math.max(z, border.getBoundNorth());
302-
z = (int) Math.min(z, border.getBoundSouth());
303-
}
304-
}
305-
306-
this.pos = new BlockPos(x, y, z);
307-
308-
// Makes sure the grave is not broken/replaced by portal, or the dragon egg
309-
if (this.world.getRegistryKey().equals(World.END)) {
310-
if (Math.abs(attemptedPos.getX()) + Math.abs(attemptedPos.getZ()) < 25 && this.world.getBlockState(attemptedPos.down()).isOf(Blocks.BEDROCK))
311-
this.pos = this.pos.up();
312-
}
313-
314-
DeathInfoManager.INSTANCE.markDirty(); // The "this" object is (at least should be) located inside DeathInfoManager.INSTANCE
315-
316314
this.placeBlockUnder();
317315
return this.world.setBlockState(this.pos, state);
318316
}
@@ -341,12 +339,12 @@ public void placeAndLoad(Direction direction, DeathContext context, BlockPos pos
341339
Yigd.END_OF_TICK.add(() -> {
342340
BlockState previousState = world.getBlockState(pos);
343341

344-
boolean placed = this.tryPlaceGraveAt(pos, graveBlock);
342+
boolean placed = this.tryPlaceGrave(graveBlock);
345343
BlockPos placedPos = this.getPos();
346344

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

‎src/main/java/com/b1n_ry/yigd/events/YigdServerEventHandler.java

+4
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ public static void registerEventCallbacks() {
210210
(grave, currentUnder) -> YigdConfig.getConfig().graveConfig.blockUnderGrave.enabled && currentUnder.isIn(YigdTags.REPLACE_SOFT_WHITELIST));
211211

212212
GraveGenerationEvent.EVENT.register((world, pos, nthTry) -> {
213+
if (world.isOutOfHeightLimit(pos) || !world.getWorldBorder().contains(pos)) {
214+
return false;
215+
}
216+
213217
BlockState state = world.getBlockState(pos);
214218
YigdConfig.GraveConfig config = YigdConfig.getConfig().graveConfig;
215219
if (world.getBlockEntity(pos) != null) // Block entities should NOT be replaced by graves

0 commit comments

Comments
 (0)
Please sign in to comment.