From e8d9c73bfb9f322acf693309dd992042f7021699 Mon Sep 17 00:00:00 2001 From: fan87 Date: Mon, 14 Mar 2022 22:23:26 +0800 Subject: [PATCH] Some mess up + document update --- .../testmixin/TestMixin.java | 4 +-- .../EDragonArrowShieldRemover.java | 25 ++++++++++++++++++- docs/Getting Started.md | 2 ++ pom.xml | 7 ++++++ readme.md | 1 + .../action/impl/MActionMethodReplacer.java | 1 - 6 files changed, 36 insertions(+), 4 deletions(-) rename TestMixin/src/main/java/com/dragoncommissions/testmixin/{mixins => examples}/EDragonArrowShieldRemover.java (56%) diff --git a/TestMixin/src/main/java/com/dragoncommissions/testmixin/TestMixin.java b/TestMixin/src/main/java/com/dragoncommissions/testmixin/TestMixin.java index 7635087..a4f531f 100644 --- a/TestMixin/src/main/java/com/dragoncommissions/testmixin/TestMixin.java +++ b/TestMixin/src/main/java/com/dragoncommissions/testmixin/TestMixin.java @@ -3,7 +3,6 @@ import com.dragoncommissions.mixbukkit.MixBukkit; import com.dragoncommissions.mixbukkit.addons.AutoMapper; import com.dragoncommissions.mixbukkit.api.MixinPlugin; -import com.dragoncommissions.testmixin.mixins.EDragonArrowShieldRemover; import lombok.SneakyThrows; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; @@ -16,7 +15,8 @@ public class TestMixin extends JavaPlugin implements Listener { public void onEnable() { MixinPlugin plugin = MixBukkit.registerMixinPlugin(this, AutoMapper.getMappingAsStream()); - EDragonArrowShieldRemover.register(plugin); +// EDragonArrowShieldRemover.register(plugin); + } diff --git a/TestMixin/src/main/java/com/dragoncommissions/testmixin/mixins/EDragonArrowShieldRemover.java b/TestMixin/src/main/java/com/dragoncommissions/testmixin/examples/EDragonArrowShieldRemover.java similarity index 56% rename from TestMixin/src/main/java/com/dragoncommissions/testmixin/mixins/EDragonArrowShieldRemover.java rename to TestMixin/src/main/java/com/dragoncommissions/testmixin/examples/EDragonArrowShieldRemover.java index 9712f9a..0805e22 100644 --- a/TestMixin/src/main/java/com/dragoncommissions/testmixin/mixins/EDragonArrowShieldRemover.java +++ b/TestMixin/src/main/java/com/dragoncommissions/testmixin/examples/EDragonArrowShieldRemover.java @@ -1,4 +1,4 @@ -package com.dragoncommissions.testmixin.mixins; +package com.dragoncommissions.testmixin.examples; import com.dragoncommissions.mixbukkit.api.MixinPlugin; import com.dragoncommissions.mixbukkit.api.action.impl.MActionInsertShellCode; @@ -22,6 +22,29 @@ public static void register(MixinPlugin plugin) { ), AbstractDragonSittingPhase.class, "onHurt", float.class, DamageSource.class, float.class); } + /* + Original Sourcecode of AbstractDragonSittingPhase#onHurt(DamageSource, float): + public float onHurt(DamageSource var0, float var1) { + if (var0.getDirectEntity() instanceof AbstractArrow) { // A + var0.getDirectEntity().setSecondsOnFire(1); // B + return 0.0F; // C + } else { + return super.onHurt(var0, var1); + } + } + + + this code prevents players from attacking dragons with arrows while dragon is in sitting phase. + There's no way to make it possible with vanilla bukkit API other than tracing down EnderDragon#hurt(EnderDragonPart, DamageSource, float) + Well, that's not a good idea. + + In this case, Mixin is the best solution (if you are fine making it only works with 1 version) + + In this mixin, it modifies the original onHurt method, makes a call to EDragonArrowShieldRemover#onHurt(AbstractDragonSittingPhase, DamageSource, float, CallbackInfo) + It checks of the damage source is arrow, if it is then it will return the original damage instead of 0 (0 is returned in vanilla if source is arrow) + Since the "A" will never be called, the arrow will never bounce off again. + */ + public static void onHurt(AbstractDragonSittingPhase phase, DamageSource source, float damage, CallbackInfo info) { if (source.getDirectEntity() instanceof AbstractArrow) { info.setReturned(true); diff --git a/docs/Getting Started.md b/docs/Getting Started.md index 6a1f64b..c6cf2d1 100644 --- a/docs/Getting Started.md +++ b/docs/Getting Started.md @@ -1,5 +1,7 @@ # Getting Started In this tutorial, I'll be teaching you how to start coding your first mixin plugin! +## Out of date +This document is outdated. Require an update. ## Requirements 1. Some basic Java knowledge diff --git a/pom.xml b/pom.xml index b39a4b3..f28a2ec 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,13 @@ 8 + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + org.spigotmc diff --git a/readme.md b/readme.md index 2321ffd..3b36466 100644 --- a/readme.md +++ b/readme.md @@ -9,6 +9,7 @@ In theory, it should work from Java 8 ~ Java latest, Linux & Windows & MacOS, bu Minecraft version is not limited, but it will result in mapping different ## Basic Usage +(Please check `docs/Getting Started.md` for more information) ### Mapping #### Method 1. Use Spigot's Members Mapping If you want to make things easy/fast/good/great/simple, you can use this method. diff --git a/src/main/java/com/dragoncommissions/mixbukkit/api/action/impl/MActionMethodReplacer.java b/src/main/java/com/dragoncommissions/mixbukkit/api/action/impl/MActionMethodReplacer.java index 93f924d..8c50265 100644 --- a/src/main/java/com/dragoncommissions/mixbukkit/api/action/impl/MActionMethodReplacer.java +++ b/src/main/java/com/dragoncommissions/mixbukkit/api/action/impl/MActionMethodReplacer.java @@ -12,7 +12,6 @@ import java.lang.reflect.Method; -@SuppressWarnings("Untested") public class MActionMethodReplacer implements MixinAction { private Method handler;