From 01682602caa2540b13d6e0ebc71869666a79cee3 Mon Sep 17 00:00:00 2001 From: Thom van den Akker Date: Sun, 27 Oct 2024 17:52:20 +0100 Subject: [PATCH] Remove free blocks from configuration (has become redundant) (#10339) Free blocks and positions become datapacks in favor of configuration values --- .../compatibility/CompatibilityManager.java | 54 ------------------- .../compatibility/ICompatibilityManager.java | 15 ------ .../configuration/ServerConfiguration.java | 6 --- .../ColonyPermissionEventHandler.java | 2 +- 4 files changed, 1 insertion(+), 76 deletions(-) diff --git a/src/main/java/com/minecolonies/api/compatibility/CompatibilityManager.java b/src/main/java/com/minecolonies/api/compatibility/CompatibilityManager.java index 145dd38e535..ca45a8fae78 100755 --- a/src/main/java/com/minecolonies/api/compatibility/CompatibilityManager.java +++ b/src/main/java/com/minecolonies/api/compatibility/CompatibilityManager.java @@ -16,7 +16,6 @@ import com.minecolonies.api.util.*; import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -31,7 +30,6 @@ import net.minecraft.world.item.*; import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.AirBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.FurnaceBlockEntity; @@ -144,16 +142,6 @@ public class CompatibilityManager implements ICompatibilityManager */ private static ImmutableList allItems = ImmutableList.of(); - /** - * Free block positions everyone can interact with. - */ - private final Set freeBlocks = new HashSet<>(); - - /** - * Free positions everyone can interact with. - */ - private final Set freePositions = new HashSet<>(); - /** * Hashmap of mobs we may or may not attack. */ @@ -191,8 +179,6 @@ private void clear() recruitmentCostsWeights.clear(); diseases.clear(); diseaseList.clear(); - freeBlocks.clear(); - freePositions.clear(); monsters = ImmutableSet.of(); creativeModeTabMap.clear(); } @@ -211,7 +197,6 @@ public void discover(@NotNull final RecipeManager recipeManager, final Level lev discoverLuckyOres(); discoverRecruitCosts(); discoverDiseases(); - discoverFreeBlocksAndPos(); discoverModCompat(); discoverCompostRecipes(recipeManager); @@ -268,7 +253,6 @@ public void deserialize(@NotNull final FriendlyByteBuf buf, final ClientLevel le discoverLuckyOres(); discoverRecruitCosts(); discoverDiseases(); - discoverFreeBlocksAndPos(); discoverModCompat(); } @@ -586,18 +570,6 @@ public ItemStack getRandomLuckyOre(final double chanceBonus, final int buildingL return ItemStack.EMPTY; } - @Override - public boolean isFreeBlock(final Block block) - { - return freeBlocks.contains(block); - } - - @Override - public boolean isFreePos(final BlockPos block) - { - return freePositions.contains(block); - } - @Override public CreativeModeTab getCreativeTab(final ItemStorage checkItem) { @@ -988,32 +960,6 @@ private static Tuple readLeafSaplingEntryFromNBT(final return new Tuple<>(NbtUtils.readBlockState(BuiltInRegistries.BLOCK.asLookup(), compound), new ItemStorage(ItemStack.of(compound), false, true)); } - /** - * Load free blocks and pos from the config and add to colony. - */ - private void discoverFreeBlocksAndPos() - { - for (final String s : MinecoloniesAPIProxy.getInstance().getConfig().getServer().freeToInteractBlocks.get()) - { - try - { - final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(s)); - if (block != null && !(block instanceof AirBlock)) - { - freeBlocks.add(block); - } - } - catch (final Exception ex) - { - final BlockPos pos = BlockPosUtil.getBlockPosOfString(s); - if (pos != null) - { - freePositions.add(pos); - } - } - } - } - /** * Inits compats */ diff --git a/src/main/java/com/minecolonies/api/compatibility/ICompatibilityManager.java b/src/main/java/com/minecolonies/api/compatibility/ICompatibilityManager.java index 09cc1b0461f..f2b30ed7546 100755 --- a/src/main/java/com/minecolonies/api/compatibility/ICompatibilityManager.java +++ b/src/main/java/com/minecolonies/api/compatibility/ICompatibilityManager.java @@ -6,7 +6,6 @@ import com.minecolonies.api.util.Disease; import com.minecolonies.api.util.Tuple; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -247,20 +246,6 @@ public interface ICompatibilityManager */ ItemStack getRandomLuckyOre(final double chanceBonus, final int buildingLevel); - /** - * Check if the block is configured to bypass the colony restrictions. - * @param block the block to check. - * @return true if so. - */ - boolean isFreeBlock(Block block); - - /** - * Check if the position is configured to bypass the colony restrictions. - * @param block the position to check. - * @return true if so. - */ - boolean isFreePos(BlockPos block); - /** * Get the creative tab for a stack. * @param checkItem the storage wrapper. diff --git a/src/main/java/com/minecolonies/api/configuration/ServerConfiguration.java b/src/main/java/com/minecolonies/api/configuration/ServerConfiguration.java index ec3bb5fabb7..ff1f45c8a60 100755 --- a/src/main/java/com/minecolonies/api/configuration/ServerConfiguration.java +++ b/src/main/java/com/minecolonies/api/configuration/ServerConfiguration.java @@ -91,7 +91,6 @@ public class ServerConfiguration extends AbstractConfiguration public final ForgeConfigSpec.BooleanValue enableColonyProtection; public final ForgeConfigSpec.EnumValue turnOffExplosionsInColonies; - public final ForgeConfigSpec.ConfigValue> freeToInteractBlocks; /* -------------------------------------------------------------------------------- * * ------------------- ######## Compatibility Settings ######## ------------------- * @@ -192,11 +191,6 @@ protected ServerConfiguration(final ForgeConfigSpec.Builder builder) enableColonyProtection = defineBoolean(builder, "enablecolonyprotection", true); turnOffExplosionsInColonies = defineEnum(builder, "turnoffexplosionsincolonies", Explosions.DAMAGE_ENTITIES); - freeToInteractBlocks = defineList(builder, "freetointeractblocks", - Arrays.asList - ("dirt", - "0 0 0"), - s -> s instanceof String); swapToCategory(builder, "compatibility"); diff --git a/src/main/java/com/minecolonies/core/colony/permissions/ColonyPermissionEventHandler.java b/src/main/java/com/minecolonies/core/colony/permissions/ColonyPermissionEventHandler.java index 242e5b08de9..4345fc182e3 100755 --- a/src/main/java/com/minecolonies/core/colony/permissions/ColonyPermissionEventHandler.java +++ b/src/main/java/com/minecolonies/core/colony/permissions/ColonyPermissionEventHandler.java @@ -417,7 +417,7 @@ public void on(final PlayerInteractEvent event) */ private boolean isFreeToInteractWith(@Nullable final Block block, final BlockPos pos) { - return (block != null && (IColonyManager.getInstance().getCompatibilityManager().isFreeBlock(block) || colony.getFreeBlocks().contains(block) || block.defaultBlockState().is(ModTags.colonyProtectionException))) || colony.getFreePositions().contains(pos) || IColonyManager.getInstance().getCompatibilityManager().isFreePos(pos); + return (block != null && (colony.getFreeBlocks().contains(block) || block.defaultBlockState().is(ModTags.colonyProtectionException))) || colony.getFreePositions().contains(pos); } /**