-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/direction dependent block attachment (#681)
* Attempt 1 * Attempt 5 * Solved! (incomeplete) Needs a block whitelist ty <3 ohnoey * Add Lanterns + small refactor * Remove commented code * Refactor shorthanded variables * Remove Debugging and useless variable * Undo: Revert a conditional * Made SupportUtils class * Adding Reminders + More robust FaceAttachable checks * Add directionDependentMaterials * Fix Signs (only get wall signs as they are directional) * Use `Tag.WALL_SIGNS` instead * Created Tags.WALL_TORCHES and used that instead --------- Co-authored-by: TylerS1066 <TylerS1066@users.noreply.github.com>
- Loading branch information
1 parent
b23f98a
commit 953f7d0
Showing
5 changed files
with
98 additions
and
22 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
47 changes: 47 additions & 0 deletions
47
...aft/src/main/java/net/countercraft/movecraft/processing/tasks/detection/SupportUtils.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,47 @@ | ||
package net.countercraft.movecraft.processing.tasks.detection; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.block.BlockFace; | ||
import org.bukkit.block.data.BlockData; | ||
import org.bukkit.block.data.Directional; | ||
import org.bukkit.block.data.FaceAttachable; | ||
import org.bukkit.block.data.type.Lantern; | ||
|
||
import java.util.EnumSet; | ||
import java.util.Optional; | ||
|
||
/** | ||
* @author Intybyte/Vaan1310 | ||
* An util craft that uses block data to get its supporting block | ||
*/ | ||
|
||
public class SupportUtils { | ||
public static Optional<BlockFace> getSupportFace(BlockData data, EnumSet<Material> directionalDependent) { | ||
|
||
Material material = data.getMaterial(); | ||
if (!directionalDependent.contains(material)) { | ||
return Optional.empty(); | ||
} | ||
|
||
//TODO: Use pattern matched switch statements once we update do Java 21 | ||
//TODO: This should become Hangable instead when we drop support for 1.18 | ||
if (data instanceof Lantern lantern) | ||
return Optional.of(lantern.isHanging() ? BlockFace.UP : BlockFace.DOWN); | ||
|
||
if (data instanceof Directional directional) { | ||
BlockFace normalCase = directional.getFacing().getOppositeFace(); | ||
|
||
if (data instanceof FaceAttachable faceAttachable) { | ||
return switch (faceAttachable.getAttachedFace()) { | ||
case FLOOR -> Optional.of(BlockFace.DOWN); | ||
case WALL -> Optional.of(normalCase); | ||
case CEILING -> Optional.of(BlockFace.UP); | ||
}; | ||
} | ||
|
||
return Optional.of(normalCase); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
} |
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