diff --git a/src/main/java/eu/pb4/graves/config/Config.java b/src/main/java/eu/pb4/graves/config/Config.java index 4fea509..7b1a239 100644 --- a/src/main/java/eu/pb4/graves/config/Config.java +++ b/src/main/java/eu/pb4/graves/config/Config.java @@ -119,6 +119,9 @@ public static class Placement { public int shiftDistance = 40; @SerializedName("generate_on_top_of_fluids") public boolean generateOnTopOfFluids = false; + @SerializedName("generate_on_ground") + public boolean generateOnGround = false; + @SerializedName("create_gravestone_after_emptying") public boolean createVisualGrave = false; @SerializedName("restore_replaced_block_after_player_breaking") diff --git a/src/main/java/eu/pb4/graves/model/parts/ItemDisplayModelPart.java b/src/main/java/eu/pb4/graves/model/parts/ItemDisplayModelPart.java index 3f7df60..5b0c835 100644 --- a/src/main/java/eu/pb4/graves/model/parts/ItemDisplayModelPart.java +++ b/src/main/java/eu/pb4/graves/model/parts/ItemDisplayModelPart.java @@ -15,7 +15,7 @@ public class ItemDisplayModelPart extends DisplayModelPart GRAVE_TICKED = ChunkTicketType.create("universal_graves", Comparator.comparing(Grave::getId), 5); + public static final Identifier REPLACEABLE_ID = new Identifier("universal_graves", "replaceable"); public static final TagKey REPLACEABLE_TAG = TagKey.of(RegistryKeys.BLOCK, REPLACEABLE_ID); public static final Inventory EMPTY_INVENTORY = new SimpleInventory(0); @@ -82,6 +82,11 @@ public static BlockCheckResult findGravePosition(ServerPlayerEntity player, Serv var border = world.getWorldBorder(); blockPos = BlockPos.ofFloored(MathHelper.clamp(blockPos.getX(), border.getBoundWest() + 1, border.getBoundEast() - 1), MathHelper.clamp(blockPos.getY(), world.getBottomY(), world.getTopY() - 1), MathHelper.clamp(blockPos.getZ(), border.getBoundNorth() + 1, border.getBoundSouth() - 1)); var config = ConfigManager.getConfig(); + if (config.placement.generateOnGround) { + while (world.getBlockState(blockPos).isAir() && world.getBottomY() + 2 < blockPos.getY()) { + blockPos = blockPos.down(); + } + } var result = isValidPos(player, world, border, blockPos, false, config); if (result.allow) { @@ -287,7 +292,7 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) { WrappedText text = null; var placeholders = Map.of( - "position", Text.literal("" + player.getBlockPos().toShortString()), + "position", Text.literal(player.getBlockPos().toShortString()), "world", GraveUtils.toWorldName(player.getWorld().getRegistryKey().getValue()) ); @@ -320,6 +325,9 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) { var model = config.getGraveModel(player); BlockPos gravePos = result.pos(); + if (gravePos == null) { + return; + } List items = new ArrayList<>(); for (var mask : GravesApi.getAllInventoryMasks()) { @@ -331,7 +339,7 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) { experience = config.storage.xpStorageType.converter.calc(player); } - if (items.size() == 0 && (!config.storage.canStoreOnlyXp || experience == 0)) { + if (items.isEmpty() && (!config.storage.canStoreOnlyXp || experience == 0)) { return; } @@ -367,6 +375,8 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) { var fluidState = world.getFluidState(gravePos); world.setBlockState(gravePos, TempBlock.INSTANCE.getDefaultState()); + world.getChunkManager().addTicket(GRAVE_TICKED, new ChunkPos(gravePos), 1, grave); + GravesMod.DO_ON_NEXT_TICK.add(() -> { WrappedText text2; Map placeholders2 = placeholders; @@ -381,13 +391,14 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) { GraveManager.INSTANCE.add(grave); graveBlockEntity.setGrave(grave, storedBlockState); graveBlockEntity.setModelId(model); + world.markDirty(gravePos); text2 = config.texts.messageGraveCreated; placeholders2 = grave.getPlaceholders(player.getServer()); if (config.placement.maxGraveCount > -1) { var graves = new ArrayList<>(GraveManager.INSTANCE.getByPlayer(player)); - graves.sort(Comparator.comparing(x -> x.getCreationTime())); + graves.sort(Comparator.comparing(Grave::getCreationTime)); while (graves.size() > config.placement.maxGraveCount) { graves.remove(0).destroyGrave(player.server, null); } diff --git a/src/main/java/eu/pb4/graves/registry/GraveBlockEntity.java b/src/main/java/eu/pb4/graves/registry/GraveBlockEntity.java index c3a0629..c3f111f 100644 --- a/src/main/java/eu/pb4/graves/registry/GraveBlockEntity.java +++ b/src/main/java/eu/pb4/graves/registry/GraveBlockEntity.java @@ -76,25 +76,10 @@ protected void writeNbt(NbtCompound nbt) { public void readNbt(NbtCompound nbt) { super.readNbt(nbt); try { - if (nbt.contains("GraveInfo", NbtElement.COMPOUND_TYPE)) { - // Legacy grave handling - this.data = new Grave(); - this.data.readNbt(nbt.getCompound("GraveInfo")); - - NbtList nbtList = nbt.getList("Items", NbtElement.COMPOUND_TYPE); - - for (NbtElement compound : nbtList) { - this.data.getItems().add(new PositionedItemStack(ItemStack.fromNbt((NbtCompound) compound), -1, VanillaInventoryMask.INSTANCE, null, Set.of())); - } - GraveManager.INSTANCE.add(this.data); - this.visualData = this.data.toVisualGraveData(); - } else if (nbt.contains("GraveId", NbtElement.LONG_TYPE)) { + if (nbt.contains("GraveId", NbtElement.LONG_TYPE)) { this.graveId = nbt.getLong("GraveId"); } - - if (this.data == null) { - this.fetchGraveData(); - } + this.fetchGraveData(); if (this.visualData == null) { this.visualData = VisualGraveData.fromNbt(nbt.getCompound("VisualData")); diff --git a/src/main/resources/data/ftbchunks/tags/blocks/interact_whitelist.json b/src/main/resources/data/ftbchunks/tags/blocks/interact_whitelist.json new file mode 100644 index 0000000..f861c6a --- /dev/null +++ b/src/main/resources/data/ftbchunks/tags/blocks/interact_whitelist.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "universal_graves:grave" + ] +} \ No newline at end of file