-
-
Notifications
You must be signed in to change notification settings - Fork 414
Brush-related expressions #6902
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
Merged
sovdeeth
merged 45 commits into
SkriptLang:dev/feature
from
Asleeepp:addition-brush-stuff
Jun 3, 2025
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
2cc8bfb
initial commit
Asleeepp fbdc23f
Merge branch 'dev/feature' into addition-brush-stuff
Asleeepp 977c1c2
syntax change
Asleeepp 4649cf6
remove comment
Asleeepp 42773ae
slight change in test
Asleeepp a378b9b
forgot these
Asleeepp bd0f309
changes
Asleeepp 48eb734
Merge branch 'dev/feature' into addition-brush-stuff
Asleeepp b59c9d2
Merge branch 'dev/feature' into addition-brush-stuff
Asleeepp 23f407c
test
Asleeepp 2b6bd5e
Merge remote-tracking branch 'origin/addition-brush-stuff' into addit…
Asleeepp 5fc7fb4
test
Asleeepp 4299c3e
changes
Asleeepp 9b7a14a
nevermind
Asleeepp e311c0a
Apply suggestions from code review
Asleeepp ecf0888
initial commit
Asleeepp 5836857
syntax change
Asleeepp 44f775e
remove comment
Asleeepp f0f4fac
slight change in test
Asleeepp e469a9b
forgot these
Asleeepp ae29f92
changes
Asleeepp bd4f695
test
Asleeepp f8eb5b2
test
Asleeepp 05d06bd
changes
Asleeepp 2eb5002
nevermind
Asleeepp 75ecd80
Apply suggestions from code review
Asleeepp e27b88d
UPDATEEEEEEE
Asleeepp 5797f5c
Merge remote-tracking branch 'origin/addition-brush-stuff' into addit…
Asleeepp 1dd5af1
Merge branch 'dev/feature' into addition-brush-stuff
Moderocky 6dd9152
Suggested changes.
Asleeepp ab0173b
Merge branch 'dev/feature' into addition-brush-stuff
Asleeepp adc7842
Merge branch 'dev/feature' into addition-brush-stuff
Efnilite 0bc3528
Apply suggestions from code review
Asleeepp d1f5187
Suggested Changes
Asleeepp 4eb5719
Apply suggestions from code review
Asleeepp fe55f97
Suggested Changes
Asleeepp c87a631
Merge remote-tracking branch 'origin/addition-brush-stuff' into addit…
Asleeepp efebaed
Update src/test/skript/tests/syntaxes/expressions/ExprDusted.sk
Asleeepp 99ec3a1
Merge remote-tracking branch 'upstream/dev/feature' into addition-bru…
Asleeepp b76f323
Merge branch 'dev/feature' into addition-brush-stuff
Asleeepp a1c6260
Suggested
Asleeepp a272d30
fix: logic error
Asleeepp befbca9
feat: add blockdata support and multiple changers
Asleeepp f86eed8
Merge branch 'dev/feature' into addition-brush-stuff
sovdeeth b8ba1ea
Merge branch 'dev/feature' into addition-brush-stuff
sovdeeth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/main/java/ch/njol/skript/expressions/ExprBrushableItem.java
This file contains hidden or 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,78 @@ | ||
| package ch.njol.skript.expressions; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.classes.Changer; | ||
| import ch.njol.skript.classes.Changer.ChangeMode; | ||
| import ch.njol.skript.doc.*; | ||
| import ch.njol.skript.expressions.base.SimplePropertyExpression; | ||
| import ch.njol.util.coll.CollectionUtils; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.block.BrushableBlock; | ||
| import org.bukkit.block.BlockState; | ||
| import org.bukkit.event.Event; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @Name("Buried Item") | ||
| @Description({ | ||
| "Represents the item that is uncovered when dusting.", | ||
| "The only blocks that can currently be \"dusted\" are Suspicious Gravel and Suspicious Sand." | ||
| }) | ||
| @Examples({ | ||
| "send target block's brushable item", | ||
| "set {_gravel}'s brushable item to emerald" | ||
| }) | ||
| @Since("INSERT VERSION") | ||
| @RequiredPlugins("Minecraft 1.20+") | ||
| public class ExprBrushableItem extends SimplePropertyExpression<Block, ItemStack> { | ||
|
|
||
| private static final boolean SUPPORTS_DUSTING = Skript.classExists("org.bukkit.block.BrushableBlock"); | ||
|
|
||
| static { | ||
| if (SUPPORTS_DUSTING) | ||
| register(ExprBrushableItem.class, ItemStack.class, | ||
| "(brushable|buried) item", | ||
| "blocks"); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable ItemStack convert(Block block) { | ||
| if (block.getState() instanceof BrushableBlock brushableBlock) { | ||
| return brushableBlock.getItem(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||
| if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) { | ||
| return CollectionUtils.array(ItemStack.class); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||
| if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) { | ||
| ItemStack newItem = (mode == ChangeMode.SET) ? (ItemStack) delta[0] : null; | ||
| for (Block block : getExpr().getArray(event)) { | ||
| BlockState state = block.getState(); | ||
| if (state instanceof BrushableBlock brushableBlock) { | ||
| brushableBlock.setItem(newItem); | ||
| state.update(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends ItemStack> getReturnType() { | ||
| return ItemStack.class; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getPropertyName() { | ||
| return "brushable item"; | ||
| } | ||
|
|
||
| } |
140 changes: 140 additions & 0 deletions
140
src/main/java/ch/njol/skript/expressions/ExprDustedStage.java
This file contains hidden or 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,140 @@ | ||
| package ch.njol.skript.expressions; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.classes.Changer.ChangeMode; | ||
| import ch.njol.skript.doc.*; | ||
| import ch.njol.skript.expressions.base.PropertyExpression; | ||
| import ch.njol.skript.lang.Expression; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.util.Kleenean; | ||
| import ch.njol.util.coll.CollectionUtils; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.block.data.BlockData; | ||
| import org.bukkit.block.data.Brushable; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @Name("Dusted Stage") | ||
| @Description({ | ||
| "Represents how far the block has been uncovered.", | ||
| "The only blocks that can currently be \"dusted\" are Suspicious Gravel and Suspicious Sand." | ||
| }) | ||
| @Examples({ | ||
| "send target block's maximum dusted stage", | ||
| "set {_sand}'s dusted stage to 2" | ||
| }) | ||
| @Since("INSERT VERSION") | ||
| @RequiredPlugins("Minecraft 1.20+") | ||
| public class ExprDustedStage extends PropertyExpression<Object, Integer> { | ||
|
|
||
| private static final boolean SUPPORTS_DUSTING = Skript.classExists("org.bukkit.block.data.Brushable"); | ||
|
|
||
| static { | ||
| if (SUPPORTS_DUSTING) | ||
| register(ExprDustedStage.class, Integer.class, | ||
| "[:max[imum]] dust[ed|ing] (value|stage|progress[ion])", | ||
| "blocks/blockdatas"); | ||
| } | ||
|
|
||
| private boolean isMax; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| setExpr((Expression<Block>) exprs[0]); | ||
| isMax = parseResult.hasTag("max"); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected Integer @Nullable [] get(Event event, Object[] source) { | ||
| return get(source, obj -> { | ||
| Brushable brushable = getBrushable(obj); | ||
| if (brushable != null) { | ||
| return isMax ? brushable.getMaximumDusted() : brushable.getDusted(); | ||
| } | ||
| return null; | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||
| if (isMax) { | ||
| Skript.error("Attempting to modify the max dusted stage is not supported."); | ||
| return null; | ||
| } | ||
|
|
||
| return switch (mode) { | ||
| case SET, ADD, REMOVE, RESET -> CollectionUtils.array(Integer.class); | ||
| default -> null; | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||
| if (isMax) return; | ||
| Integer value = (delta != null && delta.length > 0) ? (Integer) delta[0] : null; | ||
|
|
||
| for (Object obj : getExpr().getArray(event)) { | ||
| Brushable brushable = getBrushable(obj); | ||
| if (brushable == null) | ||
| continue; | ||
|
|
||
| int currentValue = brushable.getDusted(); | ||
| int maxValue = brushable.getMaximumDusted(); | ||
| int newValue = currentValue; | ||
|
|
||
| switch (mode) { | ||
| case SET -> { | ||
| if (value != null) { | ||
| newValue = value; | ||
| } | ||
| } | ||
| case ADD -> { | ||
| if (value != null) { | ||
| newValue = currentValue + value; | ||
| } | ||
| } | ||
| case REMOVE -> { | ||
| if (value != null) { | ||
| newValue = currentValue - value; | ||
| } | ||
| } | ||
| case RESET -> newValue = 0; | ||
| default -> { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| newValue = Math.max(0, Math.min(newValue, maxValue)); | ||
|
|
||
| brushable.setDusted(newValue); | ||
| if (obj instanceof Block) { | ||
| ((Block) obj).setBlockData(brushable); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Nullable | ||
| private Brushable getBrushable(Object obj) { | ||
| if (obj instanceof Block block) { | ||
| BlockData blockData = block.getBlockData(); | ||
| if (blockData instanceof Brushable) | ||
| return (Brushable) blockData; | ||
| } else if (obj instanceof Brushable brushable) { | ||
| return brushable; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public Class<? extends Integer> getReturnType() { | ||
| return Integer.class; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return getExpr().toString(event, debug) + "'s " + (isMax ? "maximum " : "") + " dusted stage"; | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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,57 @@ | ||
| test "Dusted Stage" when running minecraft "1.20": | ||
| set block 1 block under event-location to stone | ||
| set block at event-location to suspicious gravel | ||
| set {_block} to block at event-location | ||
| set {_blockdata} to block data of {_block} | ||
|
|
||
| set dusted stage of {_block} to 2 | ||
| assert dusted stage of {_block} is 2 with "Failed to set dusted stage to 2" | ||
|
|
||
| assert maximum dusted stage of {_block} is 3 with "Maximum dusted stage should be 3" | ||
|
|
||
| add 1 to dusted stage of {_block} | ||
| assert dusted stage of {_block} is 3 with "Failed to add 1 to dusted stage" | ||
|
|
||
| add 5 to dusted stage of {_block} | ||
| assert dusted stage of {_block} is 3 with "Dusted stage should be capped at maximum value" | ||
|
|
||
| remove 2 from dusted stage of {_block} | ||
| assert dusted stage of {_block} is 1 with "Failed to remove 2 from dusted stage" | ||
|
|
||
| remove 5 from dusted stage of {_block} | ||
| assert dusted stage of {_block} is 0 with "Dusted stage should be capped at minimum value" | ||
|
|
||
| set dusted stage of {_block} to 2 | ||
| reset dusted stage of {_block} | ||
| assert dusted stage of {_block} is 0 with "Failed to reset dusted stage" | ||
|
|
||
| set dusted stage of {_blockdata} to 2 | ||
| assert dusted stage of {_blockdata} is 2 with "Failed to set dusted stage on blockdata" | ||
|
|
||
| set block at event-location to suspicious sand | ||
| set {_sand} to block at event-location | ||
|
|
||
| set dusted stage of {_sand} to 1 | ||
| assert dusted stage of {_sand} is 1 with "Failed to set dusted stage on suspicious sand" | ||
| add 1 to dusted stage of {_sand} | ||
| assert dusted stage of {_sand} is 2 with "Failed to add to dusted stage on suspicious sand" | ||
|
|
||
| set block at event-location to air | ||
| set block 1 block under event-location to air | ||
|
|
||
| test "Brushable Item" when running minecraft "1.20": | ||
| set block 1 block under event-location to stone | ||
| set block at event-location to suspicious gravel | ||
| set {_block} to block at event-location | ||
|
|
||
| set {_block}'s brushable item to gold nugget | ||
| assert {_block}'s brushable item is gold nugget with "Failed to set brushable item to gold nugget" | ||
|
|
||
| set {_block}'s brushable item to diamond | ||
| assert {_block}'s brushable item is diamond with "Failed to set brushable item to diamond" | ||
|
|
||
| set {_block}'s brushable item to air | ||
| assert {_block}'s brushable item is air with "Failed to clear brushable item" | ||
| set block at {_block} to air | ||
| set block 1 block under {_block} to air | ||
Asleeepp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.