Skip to content

Commit

Permalink
Add Mod ID prefix to all mixin methods and fields
Browse files Browse the repository at this point in the history
Made all mixins classes abstract
Merged two redirects in HandledScreenMixin into one
  • Loading branch information
kevinthegreat1 committed Sep 3, 2022
1 parent f7414d1 commit 1e475e3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(ChatScreen.class)
public class ChatScreenMixin {
public abstract class ChatScreenMixin {
@ModifyVariable(method = "sendMessage", at = @At(value = "LOAD", ordinal = 5), argsOnly = true)
private String modifyMessage(String message) {
private String skyblockmod_modifyMessage(String message) {
if (message.startsWith("/")) {
message = SkyblockMod.skyblockMod.message.commands.getOrDefault(message, message);
String[] messageArgs = message.split(" ");
Expand All @@ -22,7 +22,7 @@ private String modifyMessage(String message) {
}

@ModifyVariable(method = "sendMessage", at = @At(value = "LOAD", ordinal = 2), argsOnly = true)
private String modifyMessagePreviewConfirm(String message) {
return modifyMessage(message);
private String skyblockmod_modifyMessagePreviewConfirm(String message) {
return skyblockmod_modifyMessage(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin {
public abstract class ClientPlayNetworkHandlerMixin {
@Shadow
@Final
private MinecraftClient client;

@Inject(method = "onChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/message/MessageHandler;onChatMessage(Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/network/message/MessageType$Parameters;)V"))
private void onChatMessage(ChatMessageS2CPacket packet, CallbackInfo ci) {
private void skyblockmod_onChatMessage(ChatMessageS2CPacket packet, CallbackInfo ci) {
String message = packet.message().getContent().getString();
if (SkyblockMod.skyblockMod.dungeonScore.onChatMessage(message)) {
return;
Expand All @@ -31,13 +31,11 @@ private void onChatMessage(ChatMessageS2CPacket packet, CallbackInfo ci) {
if (SkyblockMod.skyblockMod.quiverWarning.onChatMessage(message)) {
return;
}
if (SkyblockMod.skyblockMod.reparty.onChatMessage(message)) {
return;
}
SkyblockMod.skyblockMod.reparty.onChatMessage(message);
}

@Inject(method = "onPlaySoundId", at = @At(value = "HEAD"))
private void onPlaySoundId(PlaySoundIdS2CPacket packet, CallbackInfo ci) {
private void skyblockmod_onPlaySoundId(PlaySoundIdS2CPacket packet, CallbackInfo ci) {
SkyblockMod.skyblockMod.fishing.onSound(client, packet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(FishingRodItem.class)
public class FishingRodItemMixin {
public abstract class FishingRodItemMixin {
@Inject(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;)V"))
private void onCast(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
private void skyblockmod_onCast(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
if (SkyblockMod.skyblockMod.fishing.on && user.equals(MinecraftClient.getInstance().player)) {
SkyblockMod.skyblockMod.fishing.start(user);
}
}

@Inject(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V", ordinal = 0))
private void onReel(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
private void skyblockmod_onReel(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
if (SkyblockMod.skyblockMod.fishing.on && user.equals(MinecraftClient.getInstance().player)) {
SkyblockMod.skyblockMod.fishing.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(HandledScreen.class)
public class HandledScreenMixin {
final Experiments experiments = SkyblockMod.skyblockMod.experiments;
public abstract class HandledScreenMixin {
private final Experiments skyblockmod_experiments = SkyblockMod.skyblockMod.experiments;

@Inject(method = "drawSlot", at = @At(value = "TAIL"))
private void fillSlot(MatrixStack matrices, Slot slot, CallbackInfo ci) {
if (experiments.type != Experiments.Type.NONE && experiments.state == Experiments.State.SHOW && slot.inventory instanceof SimpleInventory) {
switch (experiments.type) {
private void skyblockmod_fillSlot(MatrixStack matrices, Slot slot, CallbackInfo ci) {
if (skyblockmod_experiments.type != Experiments.Type.NONE && skyblockmod_experiments.state == Experiments.State.SHOW && slot.inventory instanceof SimpleInventory) {
switch (skyblockmod_experiments.type) {
case CHRONOMATRON -> {
Item item = experiments.chronomatronSlots.get(experiments.chronomatronCurrentOrdinal);
Item item = skyblockmod_experiments.chronomatronSlots.get(skyblockmod_experiments.chronomatronCurrentOrdinal);
if (slot.getStack().isOf(item) || Experiments.terracottaToGlass.get(slot.getStack().getItem()) == item) {
matrices.push();
matrices.translate(0, 0, 300);
Expand All @@ -34,13 +34,13 @@ private void fillSlot(MatrixStack matrices, Slot slot, CallbackInfo ci) {
}
}
case SUPERPAIRS -> {
ItemStack itemStack = experiments.superpairsSlots.get(slot.getIndex());
ItemStack itemStack = skyblockmod_experiments.superpairsSlots.get(slot.getIndex());
if (itemStack != null && !ItemStack.areEqual(itemStack, slot.getStack())) {
matrices.push();
matrices.translate(0, 0, 300);
if (ItemStack.areEqual(experiments.superpairsCurrentSlot, itemStack) && slot.getStack().getName().getString().equals("Click a second button!")) {
if (ItemStack.areEqual(skyblockmod_experiments.superpairsCurrentSlot, itemStack) && slot.getStack().getName().getString().equals("Click a second button!")) {
DrawableHelper.fill(matrices, slot.x, slot.y, slot.x + 16, slot.y + 16, -1073676544);
} else if (experiments.superpairsDuplicatedSlots.contains(slot.getIndex())) {
} else if (skyblockmod_experiments.superpairsDuplicatedSlots.contains(slot.getIndex())) {
DrawableHelper.fill(matrices, slot.x, slot.y, slot.x + 16, slot.y + 16, -1056964864);
} else {
DrawableHelper.fill(matrices, slot.x, slot.y, slot.x + 16, slot.y + 16, 1090453504);
Expand All @@ -49,7 +49,7 @@ private void fillSlot(MatrixStack matrices, Slot slot, CallbackInfo ci) {
}
}
case ULTRASEQUENCER -> {
if (slot.getIndex() == experiments.ultrasequencerNextSlot) {
if (slot.getIndex() == skyblockmod_experiments.ultrasequencerNextSlot) {
matrices.push();
matrices.translate(0, 0, 300);
DrawableHelper.fill(matrices, slot.x, slot.y, slot.x + 16, slot.y + 16, -1073676544);
Expand All @@ -60,49 +60,44 @@ private void fillSlot(MatrixStack matrices, Slot slot, CallbackInfo ci) {
}
}

@Redirect(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;getStack()Lnet/minecraft/item/ItemStack;", ordinal = 0))
private ItemStack getStack(Slot slot) {
if (experiments.type != Experiments.Type.NONE && experiments.state == Experiments.State.SHOW && slot.inventory instanceof SimpleInventory) {
switch (experiments.type) {
@Redirect(method = {"drawSlot", "drawMouseoverTooltip"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;getStack()Lnet/minecraft/item/ItemStack;", ordinal = 0))
private ItemStack skyblockmod_getStack(Slot slot) {
if (skyblockmod_experiments.type != Experiments.Type.NONE && skyblockmod_experiments.state == Experiments.State.SHOW && slot.inventory instanceof SimpleInventory) {
switch (skyblockmod_experiments.type) {
case SUPERPAIRS -> {
ItemStack itemStack = experiments.superpairsSlots.get(slot.getIndex());
ItemStack itemStack = skyblockmod_experiments.superpairsSlots.get(slot.getIndex());
return itemStack == null ? slot.getStack() : itemStack;
}
case ULTRASEQUENCER -> {
ItemStack itemStack = experiments.ultrasequencerSlots.get(slot.getIndex());
ItemStack itemStack = skyblockmod_experiments.ultrasequencerSlots.get(slot.getIndex());
return itemStack == null ? slot.getStack() : itemStack;
}
}
}
return slot.getStack();
}

@Redirect(method = "drawMouseoverTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;getStack()Lnet/minecraft/item/ItemStack;"))
private ItemStack getStackTooltip(Slot slot) {
return getStack(slot);
}

@Inject(method = "onMouseClick(Lnet/minecraft/screen/slot/Slot;IILnet/minecraft/screen/slot/SlotActionType;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;clickSlot(IIILnet/minecraft/screen/slot/SlotActionType;Lnet/minecraft/entity/player/PlayerEntity;)V"))
private void onSlotClick(Slot slot, int slotId, int button, SlotActionType actionType, CallbackInfo ci) {
private void skyblockmod_onSlotClick(Slot slot, int slotId, int button, SlotActionType actionType, CallbackInfo ci) {
if (slot != null) {
if (experiments.type != Experiments.Type.NONE && experiments.state == Experiments.State.SHOW && slot.inventory instanceof SimpleInventory) {
switch (experiments.type) {
if (skyblockmod_experiments.type != Experiments.Type.NONE && skyblockmod_experiments.state == Experiments.State.SHOW && slot.inventory instanceof SimpleInventory) {
switch (skyblockmod_experiments.type) {
case CHRONOMATRON -> {
Item item = experiments.chronomatronSlots.get(experiments.chronomatronCurrentOrdinal);
Item item = skyblockmod_experiments.chronomatronSlots.get(skyblockmod_experiments.chronomatronCurrentOrdinal);
if (slot.getStack().isOf(item) || Experiments.terracottaToGlass.get(slot.getStack().getItem()) == item) {
if (++experiments.chronomatronCurrentOrdinal >= experiments.chronomatronSlots.size()) {
experiments.state = Experiments.State.END;
if (++skyblockmod_experiments.chronomatronCurrentOrdinal >= skyblockmod_experiments.chronomatronSlots.size()) {
skyblockmod_experiments.state = Experiments.State.END;
}
}
}
case SUPERPAIRS -> {
experiments.superpairsPrevClickedSlot = slot.getIndex();
experiments.superpairsCurrentSlot = ItemStack.EMPTY;
skyblockmod_experiments.superpairsPrevClickedSlot = slot.getIndex();
skyblockmod_experiments.superpairsCurrentSlot = ItemStack.EMPTY;
}
case ULTRASEQUENCER -> {
if (slot.getIndex() == experiments.ultrasequencerNextSlot) {
int count = experiments.ultrasequencerSlots.get(experiments.ultrasequencerNextSlot).getCount() + 1;
experiments.ultrasequencerSlots.entrySet().stream().filter(entry -> entry.getValue().getCount() == count).findAny().ifPresentOrElse((entry) -> experiments.ultrasequencerNextSlot = entry.getKey(), () -> experiments.state = Experiments.State.END);
if (slot.getIndex() == skyblockmod_experiments.ultrasequencerNextSlot) {
int count = skyblockmod_experiments.ultrasequencerSlots.get(skyblockmod_experiments.ultrasequencerNextSlot).getCount() + 1;
skyblockmod_experiments.ultrasequencerSlots.entrySet().stream().filter(entry -> entry.getValue().getCount() == count).findAny().ifPresentOrElse((entry) -> skyblockmod_experiments.ultrasequencerNextSlot = entry.getKey(), () -> skyblockmod_experiments.state = Experiments.State.END);
}
}
}
Expand Down

0 comments on commit 1e475e3

Please sign in to comment.