forked from SlimeKnights/TinkersConstruct
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of AoE Blacklist for Tinker's Construct Tools (#121)
* Implement AoE exclusion list for Tinkers' Construct tools - Created AoEExclusionList class in tconstruct.library.util package - Added config file loading for tool-specific block exclusions - Modified AOEHarvestTool class to check exclusions before breaking blocks - Updated Hammer class to use new exclusion system - Added debug logging for troubleshooting This change allows users to specify blocks that should not be broken by the AoE effect of tools like the Hammer, while still allowing the targeted block to be broken. * Implement AoE exclusion list for Tinkers' Construct tools - Created AoEExclusionList class in tconstruct.library.util package - Added config file loading for tool-specific block exclusions - Modified AOEHarvestTool class to check exclusions before breaking blocks - Updated Hammer class to use new exclusion system - Added debug logging for troubleshooting This change allows users to specify blocks that should not be broken by the AoE effect of tools like the Hammer, while still allowing the targeted block to be broken. * Update README.md * Removed/Commented debug. * Gradle Clean * Removed missed debug message Added example formatting for config file. Inlined Variable * Added the license back, oops * Removed redundant variable * Brought back toolName, used proper getAOEToolName variable, intended for caching the name instead of calling the method later on. Changed function call to simply toolName in relation to this. * Removed now redundant if statements. * Spotless Apply * Changed to use Set<String> instead of Map<String>, and other appropriate changes made so other parts still work properly & SpotlesApply * Reinstated original README * Changed to include metadata (optionally) in the blacklist. * Changed to include metadata (optionally) in the blacklist. * Removed bad import. * .
- Loading branch information
1 parent
c2c2f14
commit 1a97bff
Showing
6 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/tconstruct/library/util/AoEExclusionList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package tconstruct.library.util; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraftforge.common.config.Configuration; | ||
|
||
public class AoEExclusionList { | ||
|
||
private static final Map<String, Set<String>> toolExclusionLists = new HashMap<>(); | ||
private static Configuration config; | ||
|
||
public static void init(File configFile) { | ||
config = new Configuration(configFile); | ||
loadConfig(); | ||
} | ||
|
||
private static void loadConfig() { | ||
config.load(); | ||
|
||
String[] tools = { "tool.hammer", "tool.excavator", "tool.lumberaxe" }; | ||
for (String tool : tools) { | ||
String[] exclusionArray = config.getStringList( | ||
tool + "Exclusions", | ||
"AOE_Exclusions", | ||
new String[] { "examplemod:exampleblock", "examplemod:exampleblock:1" }, | ||
"Block IDs (with optional metadata) that should not be broken by " + tool + "'s AOE effect"); | ||
Set<String> exclusionSet = new HashSet<>(Arrays.asList(exclusionArray)); | ||
toolExclusionLists.put(tool, exclusionSet); | ||
} | ||
|
||
if (config.hasChanged()) { | ||
config.save(); | ||
} | ||
} | ||
|
||
public static boolean isBlockExcluded(String tool, Block block, int metadata) { | ||
Set<String> exclusions = toolExclusionLists.get(tool); | ||
if (exclusions == null) { | ||
exclusions = toolExclusionLists.get("tool." + tool); | ||
} | ||
|
||
if (exclusions == null || exclusions.isEmpty()) { | ||
return false; | ||
} | ||
|
||
String blockId = Block.blockRegistry.getNameForObject(block); | ||
return exclusions.contains(blockId) || exclusions.contains(blockId + ":" + metadata); | ||
} | ||
} |