-
-
Notifications
You must be signed in to change notification settings - Fork 414
Copper Golem + Copper Block Support #8244
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
Open
Absolutionism
wants to merge
11
commits into
SkriptLang:dev/feature
Choose a base branch
from
Absolutionism:dev/CopperGolem
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8e25528
Merge remote-tracking branch 'upstream/dev/patch' into dev/feature
Absolutionism 4190cf1
Merge branch 'dev/feature' of https://github.com/SkriptLang/Skript in…
Absolutionism 018f2ef
Merge branch 'dev/feature' of https://github.com/SkriptLang/Skript in…
Absolutionism ae0e74a
Merge branch 'dev/feature' of https://github.com/SkriptLang/Skript in…
Absolutionism acd6b90
Merge branch 'dev/feature' of https://github.com/SkriptLang/Skript in…
Absolutionism 7f6451b
Initial Commit
Absolutionism 085034f
Merge remote-tracking branch 'upstream/dev/feature' into dev/CopperGolem
Absolutionism d4a8dc0
Requested Changes
Absolutionism eb1fd6d
Additional Changes
Absolutionism f555b8b
Sovde's Changes
Absolutionism 9a46b68
Efy's Changes
Absolutionism 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
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
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,54 @@ | ||
| package ch.njol.skript.conditions; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.conditions.base.PropertyCondition; | ||
| import ch.njol.skript.doc.Description; | ||
| import ch.njol.skript.doc.Example; | ||
| import ch.njol.skript.doc.Name; | ||
| import ch.njol.skript.doc.RequiredPlugins; | ||
| import ch.njol.skript.doc.Since; | ||
| import com.destroystokyo.paper.MaterialTags; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.entity.CopperGolem; | ||
| import org.bukkit.entity.CopperGolem.Oxidizing.Waxed; | ||
| import org.skriptlang.skript.util.ReflectUtils; | ||
|
|
||
| @Name("Is Waxed") | ||
| @Description("Whether a copper golem or copper block is waxed.") | ||
| @Example(""" | ||
| if last spawned copper golem is not waxed: | ||
| wax last spawned copper golem | ||
| """) | ||
| @Example(""" | ||
| if {_block} is waxed: | ||
| unwax {_block} | ||
| """) | ||
| @RequiredPlugins("Minecraft 1.21.9+ (copper golems)") | ||
| @Since("INSERT VERSION") | ||
| public class CondIsWaxed extends PropertyCondition<Object> { | ||
|
|
||
| private static final boolean COPPER_GOLEM_EXISTS = ReflectUtils.classExists("org.bukkit.entity.CopperGolem"); | ||
|
|
||
| static { | ||
| String type = "blocks"; | ||
| if (Skript.classExists("org.bukkit.entity.CopperGolem")) | ||
| type = "entities/blocks"; | ||
| register(CondIsWaxed.class, "waxed", type); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean check(Object object) { | ||
| if (COPPER_GOLEM_EXISTS && object instanceof CopperGolem golem) { | ||
| return golem.getOxidizing() instanceof Waxed; | ||
| } else if (object instanceof Block block) { | ||
| return MaterialTags.WAXED_COPPER_BLOCKS.isTagged(block); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getPropertyName() { | ||
| return "waxed"; | ||
| } | ||
|
|
||
| } |
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,105 @@ | ||
| package ch.njol.skript.effects; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.doc.Description; | ||
| import ch.njol.skript.doc.Example; | ||
| import ch.njol.skript.doc.Name; | ||
| import ch.njol.skript.doc.RequiredPlugins; | ||
| import ch.njol.skript.doc.Since; | ||
| 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.util.Kleenean; | ||
| import com.destroystokyo.paper.MaterialTags; | ||
| import com.google.common.collect.BiMap; | ||
| import com.google.common.collect.HashBiMap; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.entity.CopperGolem; | ||
| import org.bukkit.entity.CopperGolem.Oxidizing; | ||
| import org.bukkit.entity.CopperGolem.Oxidizing.Waxed; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.skriptlang.skript.util.ReflectUtils; | ||
|
|
||
| @Name("Wax") | ||
| @Description(""" | ||
| Wax or unwax a copper golem or copper block. | ||
| This does not change the weathering copper state of entities and blocks. | ||
| """) | ||
| @Example(""" | ||
| if last spawned copper golem is not waxed: | ||
| wax last spawned copper golem | ||
| """) | ||
| @Example(""" | ||
| if {_block} is waxed: | ||
| unwax {_block} | ||
| """) | ||
| @RequiredPlugins("Minecraft 1.21.9+ (copper golems)") | ||
| @Since("INSERT VERSION") | ||
| public class EffWax extends Effect { | ||
|
|
||
|
|
||
| private static final BiMap<Material, Material> WAX_CONVERSION; | ||
| private static final BiMap<Material, Material> UNWAX_CONVERSION = HashBiMap.create(); | ||
| private static final boolean COPPER_GOLEM_EXISTS = ReflectUtils.classExists("org.bukkit.entity.CopperGolem"); | ||
|
|
||
| static { | ||
| String type = "%blocks%"; | ||
| if (COPPER_GOLEM_EXISTS) | ||
| type = "%entities/blocks%"; | ||
| Skript.registerEffect(EffWax.class, "[:un]wax " + type); | ||
|
|
||
| for (Material waxed : MaterialTags.WAXED_COPPER_BLOCKS.getValues()) { | ||
| Material unwaxed = Material.valueOf(waxed.name().replaceAll("WAXED_", "")); | ||
| UNWAX_CONVERSION.put(waxed, unwaxed); | ||
| } | ||
| WAX_CONVERSION = UNWAX_CONVERSION.inverse(); | ||
| } | ||
|
|
||
| private boolean wax; | ||
| private Expression<?> objects; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| objects = exprs[0]; | ||
| wax = !parseResult.hasTag("un"); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected void execute(Event event) { | ||
| for (Object object : objects.getArray(event)) { | ||
| if (COPPER_GOLEM_EXISTS && object instanceof CopperGolem golem) { | ||
| boolean isWaxed = golem.getOxidizing() instanceof Waxed; | ||
| if (wax == isWaxed) | ||
| continue; | ||
| CopperGolem.Oxidizing oxidizing = wax ? Oxidizing.waxed() : Oxidizing.unset(); | ||
| golem.setOxidizing(oxidizing); | ||
| } else if (object instanceof Block block) { | ||
| if (!MaterialTags.COPPER_BLOCKS.isTagged(block)) | ||
| continue; | ||
| BiMap<Material, Material> conversion = wax ? WAX_CONVERSION : UNWAX_CONVERSION; | ||
| if (conversion.containsKey(block.getType())) { | ||
| Material material = conversion.get(block.getType()); | ||
| assert material != null; | ||
| block.setType(material); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); | ||
| if (wax) { | ||
| builder.append("wax"); | ||
| } else { | ||
| builder.append("unwax"); | ||
| } | ||
| builder.append(objects); | ||
| return builder.toString(); | ||
| } | ||
|
|
||
| } |
116 changes: 116 additions & 0 deletions
116
src/main/java/ch/njol/skript/entity/CopperGolemData.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,116 @@ | ||
| package ch.njol.skript.entity; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.lang.Literal; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.skript.localization.Language; | ||
| import ch.njol.util.Kleenean; | ||
| import io.papermc.paper.world.WeatheringCopperState; | ||
| import org.bukkit.entity.CopperGolem; | ||
| import org.bukkit.entity.CopperGolem.Oxidizing.Waxed; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class CopperGolemData extends EntityData<CopperGolem> { | ||
|
|
||
| static { | ||
| if (Skript.classExists("org.bukkit.entity.CopperGolem")) | ||
| register(CopperGolemData.class, "copper golem", CopperGolem.class, 0, "copper golem"); | ||
| } | ||
|
|
||
| private Kleenean waxed = Kleenean.UNKNOWN; | ||
| private @Nullable WeatheringCopperState state; | ||
|
|
||
| public CopperGolemData() {} | ||
|
|
||
| public CopperGolemData(@Nullable Kleenean waxed, @Nullable WeatheringCopperState state) { | ||
| this.waxed = waxed == null ? Kleenean.UNKNOWN : waxed; | ||
| this.state = state; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean init(Literal<?>[] exprs, int matchedCodeName, int matchedPattern, ParseResult parseResult) { | ||
| //noinspection unchecked | ||
| Literal<WeatheringCopperState> expr = (Literal<WeatheringCopperState>) exprs[0]; | ||
| if (expr != null) | ||
| state = expr.getSingle(); | ||
| if (matchedPattern == 1) { | ||
| waxed = Kleenean.TRUE; | ||
| } else if (matchedPattern == 2) { | ||
| waxed = Kleenean.FALSE; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean init(@Nullable Class<? extends CopperGolem> entityClass, @Nullable CopperGolem golem) { | ||
| if (golem != null) { | ||
| state = golem.getWeatheringState(); | ||
| waxed = Kleenean.get(golem.getOxidizing() instanceof Waxed); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void set(CopperGolem golem) { | ||
| if (state != null) | ||
| golem.setWeatheringState(state); | ||
| if (waxed.isTrue()) | ||
| golem.setOxidizing(CopperGolem.Oxidizing.waxed()); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean match(CopperGolem golem) { | ||
| if (!dataMatch(state, golem.getWeatheringState())) | ||
| return false; | ||
| return kleeneanMatch(waxed, Kleenean.get(golem.getOxidizing() instanceof Waxed)); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends CopperGolem> getType() { | ||
| return CopperGolem.class; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull EntityData<?> getSuperType() { | ||
| return new CopperGolemData(); | ||
| } | ||
|
|
||
| @Override | ||
| protected int hashCode_i() { | ||
| return Objects.hashCode(state) + waxed.hashCode(); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean equals_i(EntityData<?> entityData) { | ||
| if (!(entityData instanceof CopperGolemData other)) | ||
| return false; | ||
| return state == other.state && waxed == other.waxed; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSupertypeOf(EntityData<?> entityData) { | ||
| if (!(entityData instanceof CopperGolemData other)) | ||
| return false; | ||
| return dataMatch(state, other.state) && kleeneanMatch(waxed, other.waxed); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(int flags) { | ||
| StringBuilder builder = new StringBuilder(); | ||
| if (waxed.isTrue()) { | ||
| builder.append("waxed "); | ||
| } else if (waxed.isFalse()) { | ||
| builder.append("unwaxed "); | ||
| } | ||
| if (state != null) | ||
| builder.append(Language.getList("weathering copper states." + state.name())[0] + " "); | ||
| builder.append("copper golem"); | ||
| if (isPlural().isTrue()) | ||
| builder.append("s"); | ||
| return builder.toString(); | ||
| } | ||
|
|
||
| } |
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
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.