From 2fa7a248eab14fb748120d93e46332eb50544e9a Mon Sep 17 00:00:00 2001 From: TPGamesNL Date: Sun, 15 Aug 2021 19:36:15 +0200 Subject: [PATCH] Update BlockUtils.java --- .../java/ch/njol/skript/util/BlockUtils.java | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/main/java/ch/njol/skript/util/BlockUtils.java b/src/main/java/ch/njol/skript/util/BlockUtils.java index ddb5f4a9fa2..c40e8a9e717 100644 --- a/src/main/java/ch/njol/skript/util/BlockUtils.java +++ b/src/main/java/ch/njol/skript/util/BlockUtils.java @@ -18,9 +18,11 @@ */ package ch.njol.skript.util; -import java.util.Arrays; - +import ch.njol.skript.aliases.ItemData; import ch.njol.skript.aliases.ItemType; +import ch.njol.skript.bukkitutil.block.BlockCompat; +import ch.njol.skript.bukkitutil.block.BlockSetter; +import ch.njol.skript.bukkitutil.block.BlockValues; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -30,17 +32,12 @@ import org.bukkit.entity.Player; import org.eclipse.jdt.annotation.Nullable; -import ch.njol.skript.aliases.ItemData; -import ch.njol.skript.bukkitutil.block.BlockCompat; -import ch.njol.skript.bukkitutil.block.BlockSetter; -import ch.njol.skript.bukkitutil.block.BlockValues; +import java.util.Arrays; /** * TODO !Update with every version [blocks] - also update aliases-*.sk - * - * @author Peter Güttinger */ -public abstract class BlockUtils { +public class BlockUtils { /** * Sets the given block. @@ -55,8 +52,7 @@ public static boolean set(Block block, Material type, @Nullable BlockValues bloc if (applyPhysics) flags |= BlockSetter.APPLY_PHYSICS; BlockCompat.SETTER.setBlock(block, type, blockValues, flags); - - + return true; } @@ -69,7 +65,7 @@ public static void sendBlockChange(Player player, Location location, Material ty } @SuppressWarnings("null") - public static Iterable getBlocksAround(final Block b) { + public static Iterable getBlocksAround(Block b) { return Arrays.asList(b.getRelative(BlockFace.NORTH), b.getRelative(BlockFace.EAST), b.getRelative(BlockFace.SOUTH), b.getRelative(BlockFace.WEST)); } @@ -83,17 +79,15 @@ public static Iterable getFaces() { * @return Location of the block, including its direction */ @Nullable - public static Location getLocation(final @Nullable Block b) { + public static Location getLocation(@Nullable Block b) { if (b == null) return null; - final Location l = b.getLocation().add(0.5, 0.5, 0.5); -// final Material m = b.getType(); -// if (Directional.class.isAssignableFrom(m.getData())) { -// final BlockFace f = ((Directional) m.getNewData(b.getData())).getFacing(); -// l.setPitch(Direction.getPitch(Math.sin(f.getModY()))); -// l.setYaw(Direction.getYaw(Math.atan2(f.getModZ(), f.getModX()))); -// } - // TODO figure out what this code means + Location l = b.getLocation().add(0.5, 0.5, 0.5); + BlockFace blockFace = Direction.getFacing(b); + if (blockFace != BlockFace.SELF) { + l.setPitch(Direction.getPitch(Math.sin(blockFace.getModY()))); + l.setYaw(Direction.getYaw(Math.atan2(blockFace.getModZ(), blockFace.getModX()))); + } return l; }