Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix block direction getting #4280

Merged
merged 2 commits into from
Aug 30, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions src/main/java/ch/njol/skript/util/BlockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
}

Expand All @@ -69,7 +65,7 @@ public static void sendBlockChange(Player player, Location location, Material ty
}

@SuppressWarnings("null")
public static Iterable<Block> getBlocksAround(final Block b) {
public static Iterable<Block> getBlocksAround(Block b) {
return Arrays.asList(b.getRelative(BlockFace.NORTH), b.getRelative(BlockFace.EAST), b.getRelative(BlockFace.SOUTH), b.getRelative(BlockFace.WEST));
}

Expand All @@ -83,17 +79,15 @@ public static Iterable<BlockFace> 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;
}

Expand Down