Skip to content

Commit 866023f

Browse files
committed
Fix Mixins issue
This was fun to solve \s
1 parent 256f2f5 commit 866023f

4 files changed

Lines changed: 13 additions & 23 deletions

File tree

src/main/java/de/geolykt/starloader/api/event/star/StarOwnershipTakeoverEvent.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
import de.geolykt.starloader.api.event.Cancellable;
88

99
/**
10-
* @deprecated Not fired by the API due to issues with mixins, other implementations are welcome to use it though
11-
*
1210
* Event fired when the ownership of a star changes.
1311
*/
14-
@Deprecated(forRemoval = false)
1512
public class StarOwnershipTakeoverEvent extends StarEvent implements Cancellable {
1613

1714
protected boolean cancelled = false;

src/main/java/de/geolykt/starloader/apimixins/EmpireMixins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ public void setReligion(Religion religion) {
416416
a(religion);
417417
}
418418

419-
@Inject(method = "b", at = @At(value = "HEAD"), cancellable = true)
419+
// FIXME Mixin tends to behave a bit strange with this one
420+
@Inject(method = "b(I)V", at = @At(value = "HEAD"), cancellable = true)
420421
public void setTechlevel(final int techLevel, final CallbackInfo ci) {
421422
if (techLevel == getTechnologyLevel()) {
422423
return;
@@ -446,7 +447,7 @@ public void tick(CallbackInfo info) {
446447
}
447448

448449
@Shadow
449-
public boolean Y() { // is larger empire
450+
public boolean Y() { // isNoteable
450451
return false; // I am not sure that this is actually the name of the method, but I have to assume
451452
// that based on what I currently know about this method
452453
}

src/main/java/de/geolykt/starloader/apimixins/StarMixins.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import de.geolykt.starloader.api.NamespacedKey;
1919
import de.geolykt.starloader.api.empire.ActiveEmpire;
2020
import de.geolykt.starloader.api.empire.Star;
21+
import de.geolykt.starloader.api.event.EventManager;
2122
import de.geolykt.starloader.api.event.TickCallback;
23+
import de.geolykt.starloader.api.event.star.StarOwnershipTakeoverEvent;
2224
import snoddasmannen.galimulator.Religion;
2325

2426
@Mixin(snoddasmannen.galimulator.Star.class)
@@ -249,19 +251,14 @@ public void syncCoordinates() {
249251
y = q.y;
250252
}
251253

252-
/* FIXME Spongepowered's Mixins finds it very funny to not want to apply this mixin,
253-
sadly I cannot do this otherwise (i. e. using @Overwrite instead of @Inject) since otherwise
254-
I'd have a very angry snoddasmannen, and if I use some improper ASM hacks I'd have a very angry
255-
userbase that is wondering why their classes load 10 times longer than they should be loading,
256-
additionally I do not know the consequences of that action as improper ASM hacks do not stack well with Mixins.*/
257-
// @Inject(method = "b", at = @At("HEAD"), cancellable = true)
258-
// public void takeover(Empire empire, CallbackInfo info) {
259-
// StarOwnershipTakeoverEvent event = new StarOwnershipTakeoverEvent(this, getAssignedEmpire(), (ActiveEmpire) empire);
260-
// EventManager.handleEvent(event);
261-
// if (event.isCancelled()) {
262-
// info.cancel();
263-
// }
264-
// }
254+
@Inject(method = "b(Lsnoddasmannen/galimulator/Empire;)V", at = @At("HEAD"), cancellable = true)
255+
public void takeover(snoddasmannen.galimulator.Empire empire, CallbackInfo info) {
256+
StarOwnershipTakeoverEvent event = new StarOwnershipTakeoverEvent(this, getAssignedEmpire(), (ActiveEmpire) empire);
257+
EventManager.handleEvent(event);
258+
if (event.isCancelled()) {
259+
info.cancel();
260+
}
261+
}
265262

266263
@Inject(method = "e", at = @At("HEAD"))
267264
public void tick(CallbackInfo info) {

src/main/resources/starloader-api.accesswidener

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,3 @@ accessible field snoddasmannen/galimulator/Space i
2020

2121
# Enums
2222
denumerised class snoddasmannen/galimulator/EmpireSpecial
23-
24-
# Synthetics
25-
# Does not appear to work
26-
natural field snoddasmannen/galimulator/EmpireSpecial r [Lsnoddasmannen/galimulator/EmpireSpecial;
27-
accessible field snoddasmannen/galimulator/EmpireSpecial r [Lsnoddasmannen/galimulator/EmpireSpecial;

0 commit comments

Comments
 (0)