Skip to content

Commit be5c03b

Browse files
committed
chore: mixin cleanup
1 parent 035f392 commit be5c03b

15 files changed

Lines changed: 77 additions & 101 deletions

.editorconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Thank you Twiston for this superb file!
2-
31
root = true
42

53
[*]

src/main/java/org/cobalt/init/MixinAutoDiscover.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ public void onLoad(String mixinPackage) {
4141
}
4242
}
4343
} catch (IOException | URISyntaxException e) {
44-
System.err.println("Failed to auto-discover mixins: " + e.getMessage());
45-
e.printStackTrace();
44+
throw new RuntimeException(e);
4645
}
4746
}
4847

src/main/java/org/cobalt/mixin/client/AddonList_CrashReportMixin.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
import org.spongepowered.asm.mixin.injection.Inject;
99
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1010

11-
/**
12-
* Superb mixin by oblongboot!
13-
*/
1411
@Mixin(CrashReport.class)
1512
public abstract class AddonList_CrashReportMixin {
1613

1714
@Inject(method = "getDetails(Ljava/lang/StringBuilder;)V", at = @At("HEAD"))
18-
private void addAddonInfo(StringBuilder crashReportBuilder, CallbackInfo ci) {
15+
private void addAddonInfo(StringBuilder crashReportBuilder, CallbackInfo callbackInfo) {
1916
String addons = AddonLoader.INSTANCE.getAddons().stream()
2017
.map(info -> info.getFirst().getName() + " v" + info.getFirst().getVersion())
2118
.collect(Collectors.joining(", "));
@@ -24,12 +21,10 @@ private void addAddonInfo(StringBuilder crashReportBuilder, CallbackInfo ci) {
2421
addons = "None";
2522
}
2623

27-
int count = AddonLoader.INSTANCE.getAddons().size();
28-
2924
crashReportBuilder
3025
.append("\n========================================")
3126
.append("\nCobalt Addons (")
32-
.append(count)
27+
.append(AddonLoader.INSTANCE.getAddons().size())
3328
.append("): ")
3429
.append(addons)
3530
.append("\n========================================\n");

src/main/java/org/cobalt/mixin/client/BlockBreak_ClientPlayerInteractionManagerMixin.java renamed to src/main/java/org/cobalt/mixin/client/BlockChangeEvent_ClientPlayerInteractionManagerMixin.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1212

1313
@Mixin(Level.class)
14-
abstract class BlockBreak_ClientPlayerInteractionManagerMixin {
14+
abstract class BlockChangeEvent_ClientPlayerInteractionManagerMixin {
1515

1616
@Inject(method = "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z", at = @At("HEAD"))
17-
private void onBlockChange(BlockPos pos, BlockState newState, int flags, int maxUpdateDepth, CallbackInfoReturnable<Boolean> cir) {
17+
private void onBlockChange(BlockPos blockPos, BlockState newBlockState, int flags, int maxUpdateDepth, CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
1818
if (Minecraft.getInstance().level != (Object) this) {
1919
return;
2020
}
2121

22-
BlockState oldBlock = ((Level) (Object) this).getBlockState(pos);
22+
BlockState oldBlockState = ((Level) (Object) this).getBlockState(blockPos);
2323

24-
if (oldBlock.getBlock() != newState.getBlock()) {
25-
new BlockChangeEvent(pos.immutable(), oldBlock, newState).post();
24+
if (oldBlockState.getBlock() != newBlockState.getBlock()) {
25+
new BlockChangeEvent(blockPos.immutable(), oldBlockState, newBlockState).post();
2626
}
2727
}
2828

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.cobalt.mixin.client;
2+
3+
import net.minecraft.client.MouseHandler;
4+
import net.minecraft.client.input.MouseButtonInfo;
5+
import org.cobalt.api.event.impl.client.MouseEvent;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Unique;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
12+
@Mixin(MouseHandler.class)
13+
public class MouseEvent_MouseHandlerMixin {
14+
15+
@Inject(method = "onButton", at = @At("HEAD"), cancellable = true)
16+
private void onMouseButton(long window, MouseButtonInfo input, int action, CallbackInfo ci) {
17+
MouseEvent event = cobalt$createMouseEvent(input.button(), action == 1);
18+
19+
if (event != null && event.post()) {
20+
ci.cancel();
21+
}
22+
}
23+
24+
@Unique
25+
private MouseEvent cobalt$createMouseEvent(int button, boolean isDown) {
26+
return switch (button) {
27+
case 0 -> isDown ? new MouseEvent.LeftClick(button) : new MouseEvent.LeftRelease(button);
28+
case 1 -> isDown ? new MouseEvent.RightClick(button) : new MouseEvent.RightRelease(button);
29+
case 2 -> isDown ? new MouseEvent.MiddleClick(button) : new MouseEvent.MiddleRelease(button);
30+
default -> null;
31+
};
32+
}
33+
34+
}

src/main/java/org/cobalt/mixin/client/MouseHandlerEvent_MouseHandlerMixin.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/main/java/org/cobalt/mixin/client/TickEvent_MinecraftMixin.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
public class TickEvent_MinecraftMixin {
1212

1313
@Inject(at = @At("HEAD"), method = "tick")
14-
private void onStartTick(CallbackInfo info) {
15-
new TickEvent.Start().post();
14+
private void onStartTick(CallbackInfo callbackInfo) {
15+
TickEvent.Start startTickEvent = new TickEvent.Start();
16+
startTickEvent.post();
1617
}
1718

1819
@Inject(at = @At("RETURN"), method = "tick")
19-
private void onEndTick(CallbackInfo info) {
20-
new TickEvent.End().post();
20+
private void onEndTick(CallbackInfo callbackInfo) {
21+
TickEvent.End endTickEvent = new TickEvent.End();
22+
endTickEvent.post();
2123
}
2224

2325
}

src/main/java/org/cobalt/mixin/client/UnloadAddons_MinecraftMixin.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
package org.cobalt.mixin.client;
22

3+
import kotlin.Pair;
34
import net.minecraft.client.Minecraft;
5+
import org.cobalt.api.addon.Addon;
6+
import org.cobalt.api.addon.AddonMetadata;
47
import org.cobalt.internal.loader.AddonLoader;
58
import org.spongepowered.asm.mixin.Mixin;
69
import org.spongepowered.asm.mixin.injection.At;
710
import org.spongepowered.asm.mixin.injection.Inject;
811
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
import java.util.List;
913

1014
@Mixin(Minecraft.class)
1115
public class UnloadAddons_MinecraftMixin {
1216

1317
@Inject(method = "close", at = @At("HEAD"))
14-
public void onClose(CallbackInfo ci) {
15-
AddonLoader.INSTANCE.getAddons().forEach((addon) -> {
18+
public void onClose(CallbackInfo callbackInfo) {
19+
List<Pair<AddonMetadata, Addon>> addonsList = AddonLoader.INSTANCE.getAddons();
20+
21+
addonsList.forEach((addon) -> {
1622
addon.getSecond().onUnload();
1723
});
1824
}

src/main/java/org/cobalt/mixin/network/PacketEvent_ConnectionMixin.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
public class PacketEvent_ConnectionMixin {
2020

2121
@Inject(method = "genericsFtw", at = @At("HEAD"), cancellable = true)
22-
private static void onPacketReceived(Packet<?> packet, PacketListener listener, CallbackInfo ci) {
23-
PacketEvent.Incoming event = new PacketEvent.Incoming(packet);
24-
event.post();
22+
private static void onPacketReceived(Packet<?> packet, PacketListener listener, CallbackInfo callbackInfo) {
23+
PacketEvent.Incoming incomingPacketEvent = new PacketEvent.Incoming(packet);
2524

26-
if (event.isCancelled()) {
27-
ci.cancel();
25+
if (incomingPacketEvent.post()) {
26+
callbackInfo.cancel();
2827
return;
2928
}
3029

@@ -33,13 +32,12 @@ private static void onPacketReceived(Packet<?> packet, PacketListener listener,
3332
}
3433
}
3534

36-
@Inject(method = "sendPacket", at = @At("HEAD"))
37-
private void onPacketSent(Packet<?> packet, ChannelFutureListener listener, boolean flush, CallbackInfo ci) {
38-
PacketEvent.Outgoing event = new PacketEvent.Outgoing(packet);
39-
event.post();
35+
@Inject(method = "sendPacket", at = @At("HEAD"), cancellable = true)
36+
private void onPacketSent(Packet<?> packet, ChannelFutureListener listener, boolean flush, CallbackInfo callbackInfo) {
37+
PacketEvent.Outgoing outgoingPacketEvent = new PacketEvent.Outgoing(packet);
4038

41-
if (event.isCancelled()) {
42-
ci.cancel();
39+
if (outgoingPacketEvent.post()) {
40+
callbackInfo.cancel();
4341
return;
4442
}
4543

src/main/java/org/cobalt/mixin/player/LookLock_MouseHandlerMixin.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,27 @@ public abstract class LookLock_MouseHandlerMixin {
2020
public abstract void releaseMouse();
2121

2222
@Inject(method = "turnPlayer", at = @At("HEAD"), cancellable = true)
23-
private void onUpdateMouse(CallbackInfo ci) {
23+
private void onUpdateMouse(CallbackInfo callbackInfo) {
2424
if (MovementManager.isLookLocked) {
25-
ci.cancel();
25+
callbackInfo.cancel();
2626
}
2727
}
2828

29-
// might as well fit in ungrab mouse here as well
3029
@Inject(method = "isMouseGrabbed", at = @At("HEAD"), cancellable = true)
31-
private void onIsCursorLocked(CallbackInfoReturnable<Boolean> cir) {
30+
private void onIsCursorLocked(CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
3231
if (MouseUtils.isMouseUngrabbed()) {
3332
if (this.mouseGrabbed) {
3433
this.releaseMouse();
3534
}
3635

37-
cir.setReturnValue(false);
36+
callbackInfoReturnable.setReturnValue(false);
3837
}
3938
}
4039

4140
@Inject(method = "grabMouse", at = @At("HEAD"), cancellable = true)
42-
private void onLockCursor(CallbackInfo ci) {
41+
private void onLockCursor(CallbackInfo callbackInfo) {
4342
if (MouseUtils.isMouseUngrabbed()) {
44-
ci.cancel();
43+
callbackInfo.cancel();
4544
}
4645
}
4746

0 commit comments

Comments
 (0)