Skip to content

Commit

Permalink
Some mess up + document update
Browse files Browse the repository at this point in the history
  • Loading branch information
fan87 committed Mar 14, 2022
1 parent c9b3757 commit e8d9c73
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

}


Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions docs/Getting Started.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
<maven.compiler.target>8</maven.compiler.target>
</properties>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import java.lang.reflect.Method;

@SuppressWarnings("Untested")
public class MActionMethodReplacer implements MixinAction {

private Method handler;
Expand Down

0 comments on commit e8d9c73

Please sign in to comment.