@@ -202,11 +202,41 @@ public DirectionalPos findGravePos(Direction defaultDirection) {
202
202
return new DirectionalPos (this .pos , defaultDirection );
203
203
}
204
204
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
+ }
205
236
DirectionalPos graveyardPos = this .findPosInGraveyard (defaultDirection );
206
237
if (graveyardPos != null )
207
238
return graveyardPos ;
208
239
209
- YigdConfig config = YigdConfig .getConfig ();
210
240
YigdConfig .GraveConfig .Range generationMaxDistance = config .graveConfig .generationMaxDistance ;
211
241
212
242
if (config .graveConfig .tryGenerateOnGround ) {
@@ -218,6 +248,8 @@ public DirectionalPos findGravePos(Direction defaultDirection) {
218
248
}
219
249
}
220
250
251
+ DeathInfoManager .INSTANCE .markDirty (); // The "this" object is (at least should be) located inside DeathInfoManager.INSTANCE
252
+
221
253
// Loop should ABSOLUTELY NOT loop 50 times, but in case some stupid ass person (maybe me lol) doesn't return true by default
222
254
// 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
223
255
for (int i = 0 ; i < 50 ; i ++) {
@@ -269,50 +301,16 @@ private DirectionalPos findPosInGraveyard(Direction defaultDirection) {
269
301
270
302
/**
271
303
* 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
+ *
273
305
* @param state Which block should be placed
274
306
* @return Weather or not the grave was placed
275
307
*/
276
- public boolean tryPlaceGraveAt ( BlockPos attemptedPos , BlockState state ) {
308
+ public boolean tryPlaceGrave ( BlockState state ) {
277
309
if (this .world == null ) {
278
310
Yigd .LOGGER .error ("GraveComponent tried to place grave without knowing the ServerWorld" );
279
311
return false ;
280
312
}
281
313
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
-
316
314
this .placeBlockUnder ();
317
315
return this .world .setBlockState (this .pos , state );
318
316
}
@@ -341,12 +339,12 @@ public void placeAndLoad(Direction direction, DeathContext context, BlockPos pos
341
339
Yigd .END_OF_TICK .add (() -> {
342
340
BlockState previousState = world .getBlockState (pos );
343
341
344
- boolean placed = this .tryPlaceGraveAt ( pos , graveBlock );
342
+ boolean placed = this .tryPlaceGrave ( graveBlock );
345
343
BlockPos placedPos = this .getPos ();
346
344
347
345
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 ());
350
348
Yigd .LOGGER .info ("Dropping items on ground instead of in grave" );
351
349
context .player ().sendMessage (Text .translatable ("text.yigd.message.grave_generation_error" ));
352
350
this .getInventoryComponent ().dropGraveItems (world , Vec3d .of (placedPos ));
0 commit comments