Skip to content

Commit

Permalink
Merge branch 'Skytils:2.x-legacyfabricexp' into 2.x-legacyfabricexp
Browse files Browse the repository at this point in the history
  • Loading branch information
Desco1 authored Jul 15, 2024
2 parents 132c3d5 + 7a6798a commit eb88d6c
Show file tree
Hide file tree
Showing 22 changed files with 481 additions and 308 deletions.
40 changes: 40 additions & 0 deletions events/src/main/java/gg/skytils/event/mixins/MixinMinecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,28 @@

package gg.skytils.event.mixins;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import gg.skytils.event.EventsKt;
import gg.skytils.event.impl.TickEvent;
import gg.skytils.event.impl.play.KeyboardInputEvent;
import gg.skytils.event.impl.play.MouseInputEvent;
import gg.skytils.event.impl.play.BlockInteractEvent;
import gg.skytils.event.impl.play.WorldUnloadEvent;
import gg.skytils.event.impl.screen.ScreenOpenEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Vec3;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -53,6 +66,28 @@ private void tick(CallbackInfo ci) {
EventsKt.postSync(new TickEvent());
}

@WrapOperation(method = "runTick", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;next()Z"))
private boolean mouseInput(Operation<Boolean> original) {
while(original.call()) {
if (EventsKt.postCancellableSync(new MouseInputEvent(Mouse.getEventX(), Mouse.getEventY(), Mouse.getEventButton()))) {
continue;
}
return true;
}
return false;
}

@WrapOperation(method = "runTick", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Keyboard;next()Z"))
private boolean keyboardInput(Operation<Boolean> original) {
while(original.call()) {
if (EventsKt.postCancellableSync(new KeyboardInputEvent(Keyboard.getEventKey()))) {
continue;
}
return true;
}
return false;
}

@Inject(method = "displayGuiScreen", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;currentScreen:Lnet/minecraft/client/gui/GuiScreen;", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER), cancellable = true)
private void openScreen(CallbackInfo ci, @Local(argsOnly = true) LocalRef<GuiScreen> screen) {
ScreenOpenEvent event = new ScreenOpenEvent(screen.get());
Expand All @@ -69,4 +104,9 @@ private void worldChange(WorldClient worldClientIn, String loadingMessage, Callb
EventsKt.postSync(new WorldUnloadEvent(this.theWorld));
}
}

@WrapOperation(method = "rightClickMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;onPlayerRightClick(Lnet/minecraft/client/entity/EntityPlayerSP;Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/BlockPos;Lnet/minecraft/util/EnumFacing;Lnet/minecraft/util/Vec3;)Z"))
private boolean onBlockInteract(PlayerControllerMP instance, EntityPlayerSP iblockstate, WorldClient world, ItemStack itemStack, BlockPos pos, EnumFacing enumFacing, Vec3 hitVec, Operation<Boolean> original) {
return !EventsKt.postCancellableSync(new BlockInteractEvent(itemStack, pos)) && original.call(instance, iblockstate, world, itemStack, pos, enumFacing, hitVec);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void handleKeyboardInput(CallbackInfo ci) {
}

@Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true)
public void handleMouseInput(CallbackInfo ci) {
if (EventsKt.postCancellableSync(new ScreenMouseInputEvent((GuiScreen) (Object) this, Mouse.getEventX(), Mouse.getEventY(), Mouse.getEventButton()))) {
public void handleMouseInput(int mouseX, int mouseY, int mouseButton, CallbackInfo ci) {
if (EventsKt.postCancellableSync(new ScreenMouseInputEvent((GuiScreen) (Object) this, mouseX, mouseY, mouseButton))) {
ci.cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@

package gg.skytils.event.mixins.render;

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.Local;
import gg.skytils.event.EventsKt;
import gg.skytils.event.impl.render.SelectionBoxDrawEvent;
import gg.skytils.event.impl.render.WorldDrawEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MovingObjectPosition;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -32,4 +39,10 @@ public class MixinGameRenderer {
public void renderWorld(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) {
EventsKt.postSync(new WorldDrawEvent(partialTicks));
}

@WrapWithCondition(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;drawSelectionBox(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/util/MovingObjectPosition;IF)V"))
public boolean renderSelectionBox(RenderGlobal instance, EntityPlayer d1, MovingObjectPosition d2, int f, float blockpos, @Local(argsOnly = true) float partialTicks) {
SelectionBoxDrawEvent event = new SelectionBoxDrawEvent(Minecraft.getMinecraft().objectMouseOver, partialTicks);
return !EventsKt.postCancellableSync(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package gg.skytils.event.mixins.render;

import gg.skytils.event.EventsKt;
import gg.skytils.event.impl.render.LivingEntityPostRenderEvent;
import gg.skytils.event.impl.render.LivingEntityPreRenderEvent;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.EntityLivingBase;
Expand All @@ -36,4 +37,9 @@ private void onRender(T entity, double x, double y, double z, float entityYaw, f
ci.cancel();
}
}

@Inject(method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V", at = @At("TAIL"))
private void onRenderPost(T entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
EventsKt.postSync(new LivingEntityPostRenderEvent(entity));
}
}
27 changes: 27 additions & 0 deletions events/src/main/kotlin/gg/skytils/event/impl/play/input.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Skytils - Hypixel Skyblock Quality of Life Mod
* Copyright (C) 2020-2024 Skytils
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package gg.skytils.event.impl.play

import gg.skytils.event.CancellableEvent

abstract class InputEvent : CancellableEvent()

class MouseInputEvent(val x: Int, val y: Int, val button: Int) : InputEvent()

class KeyboardInputEvent(val keyCode: Int) : InputEvent()
11 changes: 10 additions & 1 deletion events/src/main/kotlin/gg/skytils/event/impl/play/world.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@

package gg.skytils.event.impl.play

import gg.skytils.event.CancellableEvent
import gg.skytils.event.Event
import net.minecraft.item.ItemStack
import net.minecraft.util.BlockPos
import net.minecraft.world.World

/**
* [gg.skytils.event.mixins.MixinMinecraft.worldChange]
*/
class WorldUnloadEvent(val world: World) : Event()
class WorldUnloadEvent(val world: World) : Event()

/**
* Represents right-clicking on a block
* [gg.skytils.event.mixins.MixinMinecraft.onBlockInteract]
*/
class BlockInteractEvent(val item: ItemStack, val pos: BlockPos) : CancellableEvent()
6 changes: 6 additions & 0 deletions events/src/main/kotlin/gg/skytils/event/impl/render/entity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package gg.skytils.event.impl.render

import gg.skytils.event.CancellableEvent
import gg.skytils.event.Event
import net.minecraft.client.renderer.culling.ICamera
import net.minecraft.client.renderer.entity.RendererLivingEntity
import net.minecraft.entity.Entity
Expand All @@ -30,6 +31,11 @@ import net.minecraft.entity.EntityLivingBase
*/
class LivingEntityPreRenderEvent<T : EntityLivingBase>(val entity: T, val renderer: RendererLivingEntity<T>, val x: Double, val y: Double, val z: Double, val partialTicks: Float) : CancellableEvent()

/**
* [gg.skytils.event.mixins.render.MixinRendererLivingEntity.onRenderPost]
*/
class LivingEntityPostRenderEvent(val entity: Entity) : Event()

/**
* [gg.skytils.event.mixins.render.MixinRenderManager.shouldRender]
*
Expand Down
6 changes: 5 additions & 1 deletion events/src/main/kotlin/gg/skytils/event/impl/render/world.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@

package gg.skytils.event.impl.render

import gg.skytils.event.CancellableEvent
import gg.skytils.event.Event
import net.minecraft.util.MovingObjectPosition

/**
* [gg.skytils.event.mixins.render.MixinGameRenderer.renderWorld]
*/
class WorldDrawEvent(val partialTicks: Float) : Event()
class WorldDrawEvent(val partialTicks: Float) : Event()

class SelectionBoxDrawEvent(val target: MovingObjectPosition, val partialTicks: Float) : CancellableEvent()
23 changes: 11 additions & 12 deletions mod/src/main/kotlin/gg/skytils/skytilsmod/Skytils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,11 @@ object Skytils : CoroutineScope, EventSubscriber {

arrayOf(
this,
ChatTabs,
NamespacedCommands,
DamageSplash,
FavoritePets,
Funny,
GardenFeatures,
GlintCustomizer,
ItemFeatures,
KeyShortcuts,
KuudraChestProfit,
KuudraFeatures,
LividFinder,
LockOrb,
MasterMode7Features,
MayorDiana,
MayorJerry,
MayorJerryTracker,
MiningFeatures,
MinionFeatures,
MiscFeatures,
Expand Down Expand Up @@ -344,6 +332,7 @@ object Skytils : CoroutineScope, EventSubscriber {
BrewingFeatures,
Catlas,
ChangeAllToSameColorSolver,
ChatTabs,
CHTreasureChestHelper,
CHWaypoints,
ClickInOrderSolver,
Expand All @@ -357,11 +346,21 @@ object Skytils : CoroutineScope, EventSubscriber {
DungeonTimer,
EnchantNames,
FarmingFeatures,
GardenFeatures,
GriffinBurrows,
IceFillSolver,
IcePathSolver,
ItemCycle,
ItemFeatures,
KeyShortcuts,
KuudraChestProfit,
KuudraFeatures,
LividFinder,
LockOrb,
MasterMode7Features,
MayorDiana,
MayorJerry,
MayorJerryTracker,
QuiverStuff,
PartyFeatures,
Ping,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
package gg.skytils.skytilsmod.features.impl.crimson

import gg.essential.universal.ChatColor
import gg.essential.universal.UKeyboard
import gg.skytils.event.EventPriority
import gg.skytils.event.EventSubscriber
import gg.skytils.event.impl.play.WorldUnloadEvent
import gg.skytils.event.register
import gg.skytils.skytilsmod.Skytils
import gg.skytils.skytilsmod._event.PacketReceiveEvent
import gg.skytils.skytilsmod.core.tickTimer
import gg.skytils.skytilsmod.events.impl.CheckRenderEntityEvent
import gg.skytils.skytilsmod.events.impl.PacketEvent
import gg.skytils.skytilsmod.utils.*
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.network.play.server.S02PacketChat
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.input.Keyboard

object KuudraFeatures {
object KuudraFeatures : EventSubscriber {
var kuudraOver = false
var myFaction: CrimsonFaction? = null
private val factionRegex = Regex("§r§.§l(?<faction>\\w+) Reputation:§r")
Expand All @@ -47,23 +48,26 @@ object KuudraFeatures {
}
}

@SubscribeEvent
fun onWorldLoad(event: WorldEvent.Unload) {
override fun setup() {
register(::onWorldLoad)
register(::onCheckRender)
register(::onPacket, EventPriority.Highest)
}

fun onWorldLoad(event: WorldUnloadEvent) {
kuudraOver = false
}

@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
if (event.entity !is EntityArmorStand || SBInfo.mode != SkyblockIsland.KuudraHollow.mode) return
if (Skytils.config.kuudraHideNonNametags && !kuudraOver && !Keyboard.isKeyDown(Keyboard.KEY_LMENU)) {
if (Skytils.config.kuudraHideNonNametags && !kuudraOver && !UKeyboard.isKeyDown(UKeyboard.KEY_LMENU)) {
if (event.entity.isInvisible && !event.entity.alwaysRenderNameTag) {
event.isCanceled = true
}
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onPacket(event: PacketEvent.ReceiveEvent) {
fun onPacket(event: PacketReceiveEvent<*>) {
if (SBInfo.mode != SkyblockIsland.KuudraHollow.mode) return
if (event.packet is S02PacketChat) {
if (event.packet.chatComponent.unformattedText.stripControlCodes().trim() == "KUUDRA DOWN!") {
Expand Down
Loading

0 comments on commit eb88d6c

Please sign in to comment.