Skip to content

Commit

Permalink
Remove free blocks from configuration (has become redundant) (#10339)
Browse files Browse the repository at this point in the history
Free blocks and positions become datapacks in favor of configuration values
  • Loading branch information
Thodor12 authored Oct 27, 2024
1 parent 5966a9a commit 0168260
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -144,16 +142,6 @@ public class CompatibilityManager implements ICompatibilityManager
*/
private static ImmutableList<ItemStack> allItems = ImmutableList.of();

/**
* Free block positions everyone can interact with.
*/
private final Set<Block> freeBlocks = new HashSet<>();

/**
* Free positions everyone can interact with.
*/
private final Set<BlockPos> freePositions = new HashSet<>();

/**
* Hashmap of mobs we may or may not attack.
*/
Expand Down Expand Up @@ -191,8 +179,6 @@ private void clear()
recruitmentCostsWeights.clear();
diseases.clear();
diseaseList.clear();
freeBlocks.clear();
freePositions.clear();
monsters = ImmutableSet.of();
creativeModeTabMap.clear();
}
Expand All @@ -211,7 +197,6 @@ public void discover(@NotNull final RecipeManager recipeManager, final Level lev
discoverLuckyOres();
discoverRecruitCosts();
discoverDiseases();
discoverFreeBlocksAndPos();
discoverModCompat();

discoverCompostRecipes(recipeManager);
Expand Down Expand Up @@ -268,7 +253,6 @@ public void deserialize(@NotNull final FriendlyByteBuf buf, final ClientLevel le
discoverLuckyOres();
discoverRecruitCosts();
discoverDiseases();
discoverFreeBlocksAndPos();
discoverModCompat();
}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -988,32 +960,6 @@ private static Tuple<BlockState, ItemStorage> 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public class ServerConfiguration extends AbstractConfiguration

public final ForgeConfigSpec.BooleanValue enableColonyProtection;
public final ForgeConfigSpec.EnumValue<Explosions> turnOffExplosionsInColonies;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> freeToInteractBlocks;

/* -------------------------------------------------------------------------------- *
* ------------------- ######## Compatibility Settings ######## ------------------- *
Expand Down Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 0168260

Please sign in to comment.