From 806ea3fbaed3c4bc9bdbeeb1b5b826c4a61ea717 Mon Sep 17 00:00:00 2001 From: Flemmli97 Date: Wed, 18 Nov 2020 18:48:51 +0100 Subject: [PATCH] open container flag changes. fix #14 --- Changelog.txt | 6 ++++ gradle.properties | 2 +- .../com/flemmli97/flan/config/Config.java | 4 +++ .../flan/event/BlockInteractEvents.java | 33 ++++++++++--------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 469ff98..5052a59 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,9 @@ +Flan 1.1.5 +====================== +- Make tile entitys always at least be in the open container flag. + Making them always be protected. This can be turned off to only include inventory type tile entities. + #14 + Flan 1.1.4 ====================== - Directly check player class for item usage. So fake players get ignored. diff --git a/gradle.properties b/gradle.properties index bc3e4e6..f345fa8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx2G loader_version=0.9.1+build.205 # Mod Properties - mod_version = 1.1.4 + mod_version = 1.1.5 maven_group = com.flemmli97.flan archives_base_name = flan diff --git a/src/main/java/com/flemmli97/flan/config/Config.java b/src/main/java/com/flemmli97/flan/config/Config.java index 4e03710..212f84b 100644 --- a/src/main/java/com/flemmli97/flan/config/Config.java +++ b/src/main/java/com/flemmli97/flan/config/Config.java @@ -29,6 +29,7 @@ public class Config { public int ticksForNextBlock = 1200; public int minClaimsize = 100; public int defaultClaimDepth = 10; + public boolean lenientBlockEntityCheck; public String[] blacklistedWorlds = new String[0]; public boolean worldWhitelist; @@ -70,6 +71,8 @@ public class Config { this.minClaimsize = ConfigHandler.fromJson(obj, "minClaimsize", this.minClaimsize); this.defaultClaimDepth = ConfigHandler.fromJson(obj, "defaultClaimDepth", this.defaultClaimDepth); JsonArray arr = ConfigHandler.arryFromJson(obj, "blacklistedWorlds"); + this.lenientBlockEntityCheck = ConfigHandler.fromJson(obj, "lenientBlockEntityCheck", this.lenientBlockEntityCheck); + this.blacklistedWorlds = new String[arr.size()]; for (int i = 0; i < arr.size(); i++) this.blacklistedWorlds[i] = arr.get(i).getAsString(); @@ -111,6 +114,7 @@ public class Config { obj.addProperty("ticksForNextBlock", this.ticksForNextBlock); obj.addProperty("minClaimsize", this.minClaimsize); obj.addProperty("defaultClaimDepth", this.defaultClaimDepth); + obj.addProperty("lenientBlockEntityCheck", this.lenientBlockEntityCheck); JsonArray arr = new JsonArray(); obj.add("blacklistedWorlds", arr); obj.addProperty("worldWhitelist", this.worldWhitelist); diff --git a/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java b/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java index cbbd9d8..012a723 100644 --- a/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java +++ b/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java @@ -10,6 +10,7 @@ import com.flemmli97.flan.player.EnumDisplayType; import com.flemmli97.flan.player.PlayerClaimData; import net.minecraft.block.BlockState; import net.minecraft.block.DoorBlock; +import net.minecraft.block.InventoryProvider; import net.minecraft.block.LecternBlock; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.LecternBlockEntity; @@ -67,22 +68,6 @@ public class BlockInteractEvents { boolean cancelBlockInteract = player.shouldCancelInteraction() && emptyHand; if (!cancelBlockInteract) { BlockState state = world.getBlockState(hitResult.getBlockPos()); - BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos()); - if (blockEntity != null) { - if (blockEntity instanceof Inventory) { - if (claim.canInteract(player, EnumPermission.OPENCONTAINER, hitResult.getBlockPos(), true)) - return ActionResult.PASS; - PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); - return ActionResult.FAIL; - } - if (blockEntity instanceof LecternBlockEntity) { - if (claim.canInteract(player, EnumPermission.LECTERNTAKE, hitResult.getBlockPos(), false)) - return ActionResult.PASS; - if (state.get(LecternBlock.HAS_BOOK)) - LockedLecternScreenHandler.create(player, (LecternBlockEntity) blockEntity); - return ActionResult.FAIL; - } - } EnumPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock()); //Pressureplate handled elsewhere if (perm != null && perm != EnumPermission.PRESSUREPLATE) { @@ -101,6 +86,22 @@ public class BlockInteractEvents { PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); return ActionResult.FAIL; } + BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos()); + if (blockEntity != null) { + if (blockEntity instanceof LecternBlockEntity) { + if (claim.canInteract(player, EnumPermission.LECTERNTAKE, hitResult.getBlockPos(), false)) + return ActionResult.PASS; + if (state.get(LecternBlock.HAS_BOOK)) + LockedLecternScreenHandler.create(player, (LecternBlockEntity) blockEntity); + return ActionResult.FAIL; + } + if (!ConfigHandler.config.lenientBlockEntityCheck || blockEntity instanceof Inventory || blockEntity instanceof InventoryProvider) { + if (claim.canInteract(player, EnumPermission.OPENCONTAINER, hitResult.getBlockPos(), true)) + return ActionResult.PASS; + PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); + return ActionResult.FAIL; + } + } } } return ActionResult.PASS;