Skip to content

Commit

Permalink
Added blockface mod xyz expression and cartesian condition
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeGBLP committed Jul 23, 2024
1 parent 3b392df commit 47e5f70
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package it.jakegblp.lusk.elements.minecraft.blockface.conditions;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import org.bukkit.block.BlockFace;
import org.jetbrains.annotations.NotNull;

@Name("Blockface - is Cartesian")
@Description("Returns true if the provided blockfaces are aligned with one of the unit axes in 3D Cartesian space (NORTH, SOUTH, EAST, WEST, UP, DOWN).")
@Examples("if {_blockface} is cartesian")
@Since("1.2")
public class CondBlockFaceCartesian extends PropertyCondition<BlockFace> {
static {
register(CondBlockFaceCartesian.class, "cartesian", "blockfaces");
}

@Override
public boolean check(BlockFace blockFace) {
return blockFace.isCartesian();
}

@Override
protected @NotNull String getPropertyName() {
return "cartesian";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package it.jakegblp.lusk.elements.minecraft.blockface.expressions;

import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import org.bukkit.block.BlockFace;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;

@Name("BlockFace - Mod XYZ")
@Description("Returns the amount of x/y/z to modify to get the represented block(s).")
@Examples({"broadcast mod-y of {_blockfaces::*}"})
@Since("1.2")
public class ExprBlockFaceModXYZ extends SimplePropertyExpression<BlockFace, Integer> {
static {
register(ExprBlockFaceModXYZ.class, Integer.class, "mod(-| )(:y|:x|z)", "blockfaces");
}

int which;

@Override
public @NotNull Class<? extends Integer> getReturnType() {
return Integer.class;
}

@Override
public boolean init(Expression<?> @NotNull [] expressions, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
which = parseResult.hasTag("y") ? 0 : (parseResult.hasTag("x") ? 1 : 2);
return super.init(expressions, matchedPattern, isDelayed, parseResult);
}

@Override
@Nullable
public Integer convert(BlockFace blockFace) {
return which == 0 ? blockFace.getModX() : (which == 1 ? blockFace.getModY() : blockFace.getModZ());
}

@Override
protected @NotNull String getPropertyName() {
return "opposite blockface";
}
}

0 comments on commit 47e5f70

Please sign in to comment.