From fe08a3313f36a041857a1de2a4feb21740f46263 Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Thu, 25 Jan 2024 18:20:10 +0100 Subject: [PATCH] Fixes --- build.gradle | 6 ++--- gradle.properties | 2 +- .../java/eu/pb4/graves/config/Config.java | 3 +++ .../model/parts/ItemDisplayModelPart.java | 2 +- .../java/eu/pb4/graves/other/GraveUtils.java | 25 +++++++++++++------ .../pb4/graves/registry/GraveBlockEntity.java | 19 ++------------ .../tags/blocks/interact_whitelist.json | 6 +++++ 7 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 src/main/resources/data/ftbchunks/tags/blocks/interact_whitelist.json diff --git a/build.gradle b/build.gradle index 555be09..98e0113 100644 --- a/build.gradle +++ b/build.gradle @@ -59,9 +59,9 @@ dependencies { modImplementation include("eu.pb4:sgui:1.2.2+1.20") modImplementation include("eu.pb4:placeholder-api:2.1.3+1.20.1") modImplementation include('xyz.nucleoid:server-translations-api:2.0.0+1.20') - modImplementation include('eu.pb4:polymer-core:0.5.15+1.20.1') - modImplementation include('eu.pb4:polymer-resource-pack:0.5.15+1.20.1') - modImplementation include('eu.pb4:polymer-virtual-entity:0.5.15+1.20.1') + modImplementation include('eu.pb4:polymer-core:0.5.19+1.20.1') + modImplementation include('eu.pb4:polymer-resource-pack:0.5.19+1.20.1') + modImplementation include('eu.pb4:polymer-virtual-entity:0.5.19+1.20.1') modImplementation include('eu.pb4:predicate-api:0.2.1+1.20.1') modImplementation include("eu.pb4:common-protection-api:1.0.0") diff --git a/gradle.properties b/gradle.properties index 8edef2d..6072dac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ fabric_version=0.83.0+1.20.1 # Mod Properties - mod_version = 3.0.0+1.20.1 + mod_version = 3.0.1+1.20.1 maven_group = eu.pb4 archives_base_name = graves 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; } @@ -366,6 +374,8 @@ public static void createGrave(ServerPlayerEntity player, DamageSource source) { BlockState oldBlockState = world.getBlockState(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; @@ -379,13 +389,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 476e9e0..429d1c0 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