@@ -17,7 +17,7 @@ public final class TreeDetectionService {
1717 private final int MIN_LOGS_REQUIRED ;
1818
1919 // Maps log types to their corresponding leaf types
20- private final Map <Material , Material > LOG_TO_LEAF_MAP = new HashMap <>();
20+ private final Map <Material , List < Material > > LOG_TO_LEAF_MAP = new HashMap <>();
2121
2222 public TreeDetectionService (TimberZ plugin ) {
2323 this .plugin = plugin ;
@@ -45,7 +45,9 @@ public void fetchLogToLeaveMap() {
4545
4646 Material logType = Material .getMaterial (parts [0 ].toUpperCase ());
4747 Material leafType = Material .getMaterial (parts [1 ].toUpperCase ());
48- if (logType != null && leafType != null ) LOG_TO_LEAF_MAP .put (logType , leafType );
48+ if (logType != null && leafType != null ) {
49+ LOG_TO_LEAF_MAP .computeIfAbsent (logType , k -> new ArrayList <>()).add (leafType );
50+ }
4951 }
5052 }
5153
@@ -57,9 +59,9 @@ public void fetchLogToLeaveMap() {
5759 */
5860 public Set <Block > identifyTreeStructure (Block sourceBlock ) {
5961 Material sourceType = sourceBlock .getType ();
60- Material matchingLeafType = LOG_TO_LEAF_MAP .get (sourceType );
62+ List < Material > matchingLeafTypes = LOG_TO_LEAF_MAP .get (sourceType );
6163
62- if (matchingLeafType == null ) {
64+ if (matchingLeafTypes == null ) {
6365 return Collections .emptySet (); // Not a valid log type
6466 }
6567
@@ -95,7 +97,7 @@ public Set<Block> identifyTreeStructure(Block sourceBlock) {
9597 }
9698
9799 // Verify the existence of matching leaf blocks
98- boolean hasLeaves = validateLeaves (connectedLogs , matchingLeafType );
100+ boolean hasLeaves = validateLeaves (connectedLogs , matchingLeafTypes );
99101 if (!hasLeaves ) {
100102 return Collections .emptySet (); // No leaves found, not a tree
101103 }
@@ -207,7 +209,7 @@ private boolean isDiagonalConnectionValid(Block block1, Block block2, Material l
207209 /**
208210 * Validate that the connected logs have appropriate leaf blocks nearby.
209211 */
210- private boolean validateLeaves (Set <Block > connectedLogs , Material leafType ) {
212+ private boolean validateLeaves (Set <Block > connectedLogs , List < Material > leafTypes ) {
211213 int leafCount = 0 ;
212214 Set <Block > checkedBlocks = new HashSet <>();
213215
@@ -217,18 +219,14 @@ private boolean validateLeaves(Set<Block> connectedLogs, Material leafType) {
217219 for (int z = -MAX_SEARCH_RADIUS ; z <= MAX_SEARCH_RADIUS ; z ++) {
218220 // Skip blocks we already checked
219221 Block checkBlock = log .getRelative (x , y , z );
220- if (checkedBlocks .contains (checkBlock )) {
221- continue ;
222- }
222+ if (checkedBlocks .contains (checkBlock )) continue ;
223223
224224 checkedBlocks .add (checkBlock );
225225
226- if (checkBlock .getType () == leafType ) {
226+ if (leafTypes . contains ( checkBlock .getType ()) ) {
227227 leafCount ++;
228228
229- if (leafCount >= MIN_LEAVES_REQUIRED ) {
230- return true ;
231- }
229+ if (leafCount >= MIN_LEAVES_REQUIRED ) return true ;
232230 }
233231 }
234232 }
@@ -252,7 +250,7 @@ public boolean containsLog(Material blockType){
252250 /**
253251 * Get the corresponding leaf type for a log type
254252 */
255- public Material getLeafType (Material logType ) {
253+ public List < Material > getLeafTypes (Material logType ) {
256254 return LOG_TO_LEAF_MAP .get (logType );
257255 }
258256}
0 commit comments