-
-
Notifications
You must be signed in to change notification settings - Fork 399
EntityBlockStorage + Beehive #7316
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 24 commits into
SkriptLang:dev/feature
from
Absolutionism:dev/EntityBlockStorage
Mar 16, 2025
Merged
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
007935b
Initial Commit
Absolutionism 0bf4601
Tests
Absolutionism b6f65b6
Beehives
Absolutionism 8174791
Notes
Absolutionism b2a9f08
Cleanup
Absolutionism 19fc27d
Fix tests
Absolutionism c91e879
Partial Changes
Absolutionism 8af8d92
Requested Changes
Absolutionism 5aa35d3
Update
Absolutionism 38e9cd5
Additional Changes
Absolutionism afecf50
Requested Changes
Absolutionism d8f87cf
Merge branch 'dev/feature' into dev/EntityBlockStorage
Absolutionism fb1d4ad
Requested Changes
Absolutionism 9c51cc7
Requested Changes
Absolutionism 81619fb
Changes
Absolutionism 3b1b02e
Update Tests
Absolutionism add46b3
Merge branch 'dev/feature' into dev/EntityBlockStorage
Absolutionism e6c5bf2
Typo
Absolutionism ac2048f
Fix Tests
Absolutionism 37d58c4
Merge branch 'dev/feature' into dev/EntityBlockStorage
Absolutionism 24f9399
Fix Tests - 2
Absolutionism a6520ef
Merge branch 'dev/feature' into dev/EntityBlockStorage
Absolutionism b6fca24
Merge branch 'dev/feature' into dev/EntityBlockStorage
Absolutionism 25bdcf2
Merge branch 'dev/feature' into dev/EntityBlockStorage
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
68 changes: 68 additions & 0 deletions
68
src/main/java/ch/njol/skript/conditions/CondEntityStorageIsFull.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,68 @@ | ||
package ch.njol.skript.conditions; | ||
|
||
import ch.njol.skript.Skript; | ||
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.lang.Condition; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.SyntaxStringBuilder; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.EntityBlockStorage; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Entity Storage Is Full") | ||
@Description("Checks to see if an entity block storage (i.e beehive) is full.") | ||
@Examples({ | ||
"if the entity block storage of {_beehive} is full:", | ||
"\trelease the entity block storage of {_beehive}" | ||
}) | ||
@Since("INSERT VERSION") | ||
public class CondEntityStorageIsFull extends Condition { | ||
|
||
static { | ||
Skript.registerCondition(CondEntityStorageIsFull.class, ConditionType.PROPERTY, | ||
"[the] entity block storage of %blocks% (is|are) full", | ||
"[the] entity block storage of %blocks% (isn't|is not|aren't|are not) full"); | ||
} | ||
|
||
private Expression<Block> blocks; | ||
private boolean checkFull; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] exrps, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
checkFull = matchedPattern % 2 == 0; | ||
//noinspection unchecked | ||
blocks = (Expression<Block>) exrps[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event event) { | ||
return blocks.check(event, block -> { | ||
if (!(block.getState() instanceof EntityBlockStorage<?> blockStorage)) | ||
return false; | ||
return blockStorage.isFull() == checkFull; | ||
Absolutionism marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); | ||
builder.append("the entity block storage of", blocks); | ||
if (blocks.isSingle()) { | ||
builder.append("is"); | ||
} else { | ||
builder.append("are"); | ||
} | ||
if (!checkFull) | ||
builder.append("not"); | ||
builder.append("full"); | ||
return builder.toString(); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/ch/njol/skript/conditions/CondIsSedated.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,33 @@ | ||
package ch.njol.skript.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.Beehive; | ||
import org.bukkit.block.Block; | ||
|
||
@Name("Is Sedated") | ||
Absolutionism marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Description("Checks if a beehive is sedated from a nearby campfire.") | ||
@Examples("if {_beehive} is sedated:") | ||
@Since("INSERT VERSION") | ||
public class CondIsSedated extends PropertyCondition<Block> { | ||
|
||
static { | ||
PropertyCondition.register(CondIsSedated.class, PropertyType.BE, "sedated", "blocks"); | ||
} | ||
|
||
@Override | ||
public boolean check(Block block) { | ||
if (!(block.getState() instanceof Beehive beehive)) | ||
return false; | ||
return beehive.isSedated(); | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return "sedated"; | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/ch/njol/skript/effects/EffReleaseEntityStorage.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,90 @@ | ||
package ch.njol.skript.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.SyntaxStringBuilder; | ||
import ch.njol.skript.util.Timespan; | ||
import ch.njol.skript.util.Timespan.TimePeriod; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.EntityBlockStorage; | ||
import org.bukkit.entity.Bee; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
@Name("Release Entity Storage") | ||
Absolutionism marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Description({ | ||
"Release the entities stored in an entity block storage (i.e. beehive).", | ||
Absolutionism marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Providing a timespan will make the released entities unable to go back into the entity block storage for that amount of time.", | ||
Absolutionism marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Due to unstable behaviour on older versions, this effect requires Minecraft version 1.21+." | ||
}) | ||
@Examples({ | ||
"release the stored entities of {_beehive}", | ||
"release the entity block storage stored entities of {_hive} for 5 seconds" | ||
}) | ||
@RequiredPlugins("Minecraft 1.21") | ||
@Since("INSERT VERSION") | ||
public class EffReleaseEntityStorage extends Effect { | ||
|
||
/* | ||
Minecraft versions 1.19.4 -> 1.20.6 have unstable behavior. | ||
Either entities are not released or are released and not clearing the stored entities. | ||
Adding entities into EntityBlockStorage's are also unstable. | ||
Entities are either not added, or added but still exist. | ||
*/ | ||
|
||
static { | ||
if (Skript.isRunningMinecraft(1, 21, 0)) { | ||
Skript.registerEffect(EffReleaseEntityStorage.class, | ||
"(release|evict) [the] [entity block storage] stored entities of %blocks% [for %-timespan%]"); | ||
Absolutionism marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
private Expression<Block> blocks; | ||
private @Nullable Expression<Timespan> timespan; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
//noinspection unchecked | ||
blocks = (Expression<Block>) exprs[0]; | ||
return true; | ||
Absolutionism marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
protected void execute(Event event) { | ||
Integer ticks = null; | ||
if (timespan != null) { | ||
Timespan time = timespan.getSingle(event); | ||
if (time != null) | ||
ticks = (int) time.getAs(TimePeriod.TICK); | ||
} | ||
for (Block block : blocks.getArray(event)) { | ||
if (!(block.getState() instanceof EntityBlockStorage<?> blockStorage)) | ||
continue; | ||
List<? extends Entity> released = blockStorage.releaseEntities(); | ||
if (ticks != null) { | ||
for (Entity entity : released) { | ||
if (entity instanceof Bee bee) { | ||
bee.setCannotEnterHiveTicks(ticks); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); | ||
builder.append("release the entity block storage stored entities of", blocks); | ||
if (timespan != null) | ||
builder.append("for", timespan); | ||
return builder.toString(); | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/ch/njol/skript/expressions/ExprBeehiveFlower.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,71 @@ | ||
package ch.njol.skript.expressions; | ||
|
||
import ch.njol.skript.classes.Changer.ChangeMode; | ||
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.util.coll.CollectionUtils; | ||
import org.bukkit.Location; | ||
import org.bukkit.block.Beehive; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Beehive Flower Target") | ||
@Description("The flower a beehive has selected to pollinate from.") | ||
@Examples({ | ||
"set the flower target of {_beehive} to block at location(0, 0, 0)", | ||
"clear the flower target of {_beehive}" | ||
}) | ||
@Since("INSERT VERSION") | ||
public class ExprBeehiveFlower extends SimplePropertyExpression<Block, Location> { | ||
|
||
static { | ||
registerDefault(ExprBeehiveFlower.class, Location.class, "flower target", "blocks"); | ||
Absolutionism marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
public @Nullable Location convert(Block block) { | ||
if (!(block.getState() instanceof Beehive beehive)) | ||
return null; | ||
return beehive.getFlower(); | ||
} | ||
|
||
@Override | ||
public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) | ||
return CollectionUtils.array(Location.class, Block.class); | ||
return null; | ||
} | ||
|
||
@Override | ||
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||
Location location = null; | ||
if (delta != null) { | ||
if (delta[0] instanceof Location loc) { | ||
location = loc; | ||
} else if (delta[0] instanceof Block block) { | ||
location = block.getLocation(); | ||
} | ||
} | ||
for (Block block : getExpr().getArray(event)) { | ||
if (!(block.getState() instanceof Beehive beehive)) | ||
continue; | ||
beehive.setFlower(location); | ||
beehive.update(true, false); | ||
} | ||
} | ||
|
||
@Override | ||
public Class<Location> getReturnType() { | ||
return Location.class; | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return "flower target"; | ||
} | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
src/main/java/ch/njol/skript/expressions/ExprBeehiveHoneyLevel.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,94 @@ | ||
package ch.njol.skript.expressions; | ||
|
||
import ch.njol.skript.classes.Changer.ChangeMode; | ||
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.ParseResult; | ||
import ch.njol.util.Kleenean; | ||
import ch.njol.util.Math2; | ||
import ch.njol.util.coll.CollectionUtils; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.data.type.Beehive; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.Consumer; | ||
|
||
@Name("Beehive Honey Level") | ||
@Description({ | ||
"The current or max honey level of a beehive.", | ||
"The max level is 5, which cannot be changed." | ||
}) | ||
@Examples("set the honey level of {_beehive} to the max honey level of {_beehive}") | ||
@Since("INSERT VERSION") | ||
public class ExprBeehiveHoneyLevel extends SimplePropertyExpression<Block, Integer> { | ||
|
||
static { | ||
registerDefault(ExprBeehiveHoneyLevel.class, Integer.class, "[max:max[imum]] honey level", "blocks"); | ||
} | ||
|
||
private boolean isMax; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
isMax = parseResult.hasTag("max"); | ||
return super.init(expressions, matchedPattern, isDelayed, parseResult); | ||
} | ||
|
||
@Override | ||
public @Nullable Integer convert(Block block) { | ||
if (!(block.getBlockData() instanceof Beehive beehive)) | ||
return null; | ||
if (isMax) | ||
return beehive.getMaximumHoneyLevel(); | ||
return beehive.getHoneyLevel(); | ||
} | ||
|
||
@Override | ||
public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||
if (isMax) | ||
return null; | ||
return switch (mode) { | ||
case SET, ADD, REMOVE -> CollectionUtils.array(Integer.class); | ||
default -> null; | ||
}; | ||
} | ||
|
||
@Override | ||
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||
int value = delta != null ? (int) delta[0] : 0; | ||
Consumer<Beehive> consumer = switch (mode) { | ||
case SET -> beehive -> beehive.setHoneyLevel(Math2.fit(0, value, 5)); | ||
case ADD -> beehive -> { | ||
int current = beehive.getHoneyLevel(); | ||
beehive.setHoneyLevel(Math2.fit(0, current + value, 5)); | ||
}; | ||
case REMOVE -> beehive -> { | ||
int current = beehive.getHoneyLevel(); | ||
beehive.setHoneyLevel(Math2.fit(0, current - value, 5)); | ||
}; | ||
default -> throw new IllegalStateException("Unexpected value: " + mode); | ||
}; | ||
for (Block block : getExpr().getArray(event)) { | ||
if (!(block.getBlockData() instanceof Beehive beehive)) | ||
continue; | ||
consumer.accept(beehive); | ||
block.setBlockData(beehive); | ||
} | ||
} | ||
|
||
@Override | ||
public Class<Integer> getReturnType() { | ||
return Integer.class; | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return (isMax ? "maximum " : "") + "honey level"; | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
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.