diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-10-01 17:00:01 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-10-01 17:00:01 +0200 |
commit | ce00374e43f54ab574a8198f94d7a13270d48888 (patch) | |
tree | a6fa18deea59bb66cec166c2a5f412c0ca29beb2 /src/main/java/at/hannibal2/skyhanni | |
parent | 9946e80fa0fb5da41c4ad8e5ace2edad6c519167 (diff) | |
download | skyhanni-ce00374e43f54ab574a8198f94d7a13270d48888.tar.gz skyhanni-ce00374e43f54ab574a8198f94d7a13270d48888.tar.bz2 skyhanni-ce00374e43f54ab574a8198f94d7a13270d48888.zip |
add blaze particle hide feature
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
12 files changed, 111 insertions, 44 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 9c608e81a..b70587509 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -152,6 +152,7 @@ public class SkyHanniMod { registerEvent(new SlayerQuestWarning()); registerEvent(new StatsTuning()); registerEvent(new NonGodPotEffectDisplay()); + registerEvent(new HideBlazeParticles()); Commands.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/events/BlazeParticleEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/BlazeParticleEvent.kt deleted file mode 100644 index cbf709a34..000000000 --- a/src/main/java/at/hannibal2/skyhanni/events/BlazeParticleEvent.kt +++ /dev/null @@ -1,7 +0,0 @@ -package at.hannibal2.skyhanni.events - -import net.minecraft.entity.monster.EntityBlaze -import net.minecraftforge.fml.common.eventhandler.Cancelable - -@Cancelable -class BlazeParticleEvent(val blaze: EntityBlaze): LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/SpawnParticleEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/SpawnParticleEvent.kt index 9cfa12dd6..cb43492cc 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/SpawnParticleEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/SpawnParticleEvent.kt @@ -3,4 +3,5 @@ package at.hannibal2.skyhanni.events import net.minecraftforge.fml.common.eventhandler.Cancelable @Cancelable -class SpawnParticleEvent(val id: Int, val x: Double, val y: Double, val z: Double) : LorenzEvent()
\ No newline at end of file +class SpawnParticleEvent(val particleId: Int, val callerClass: String, val x: Double, val y: Double, val z: Double) : + LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/HideBlazeParticles.kt b/src/main/java/at/hannibal2/skyhanni/features/HideBlazeParticles.kt new file mode 100644 index 000000000..1216afe6a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/HideBlazeParticles.kt @@ -0,0 +1,28 @@ +package at.hannibal2.skyhanni.features + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.SpawnParticleEvent +import at.hannibal2.skyhanni.utils.EntityUtils.getEntitiesNearby +import at.hannibal2.skyhanni.utils.LorenzVec +import net.minecraft.client.Minecraft +import net.minecraft.entity.monster.EntityBlaze +import net.minecraft.util.EnumParticleTypes +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class HideBlazeParticles { + + @SubscribeEvent + fun onSpawnParticle(event: SpawnParticleEvent) { + val particleId = event.particleId + if (!SkyHanniMod.feature.misc.hideBlazeParticles) return + + val particleType = EnumParticleTypes.values().find { it.particleID == particleId } + if (particleType != EnumParticleTypes.SMOKE_LARGE) return + + val location = LorenzVec(event.x, event.y, event.z) + val clazz = EntityBlaze::class.java + if (Minecraft.getMinecraft().theWorld.getEntitiesNearby(clazz, location, 3.0).isNotEmpty()) { + event.isCanceled = true + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangHideParticles.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangHideParticles.kt index feb13b2eb..266ec3da8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangHideParticles.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangHideParticles.kt @@ -37,7 +37,16 @@ class AshfangHideParticles { if (!isEnabled()) return if (!hideParticles) return - event.isCanceled = true + + when (event.callerClass) { + "net.minecraft.block.BlockFire", + "net.minecraft.entity.monster.EntityBlaze", + "net.minecraft.entity.projectile.EntityFireball", + -> { + event.isCanceled = true + } + } + } private fun isEnabled() = LorenzUtils.inSkyblock && SkyHanniMod.feature.ashfang.hideParticles diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerClearView.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerClearView.kt index b595f3cfa..5455d3067 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerClearView.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerClearView.kt @@ -47,7 +47,15 @@ class BlazeSlayerClearView { @SubscribeEvent fun onSpawnParticle(event: SpawnParticleEvent) { if (isEnabled()) { - event.isCanceled = true + when (event.callerClass) { + "net.minecraft.block.BlockFire", + "net.minecraft.entity.monster.EntityBlaze", + "net.minecraft.entity.projectile.EntityFireball", + -> { + event.isCanceled = true + return + } + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/EntityBlazeHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/EntityBlazeHook.kt deleted file mode 100644 index 9b7e09cc7..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/EntityBlazeHook.kt +++ /dev/null @@ -1,9 +0,0 @@ -package at.hannibal2.skyhanni.mixins.hooks - -import at.hannibal2.skyhanni.events.BlazeParticleEvent -import net.minecraft.entity.monster.EntityBlaze - -fun onBlockBlazeParticle(mixinBlaze: Any): Boolean { - val blaze = mixinBlaze as EntityBlaze - return BlazeParticleEvent(blaze).postAndCatch() -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderGlobalHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderGlobalHook.kt new file mode 100644 index 000000000..0ae72fddf --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderGlobalHook.kt @@ -0,0 +1,33 @@ +package at.hannibal2.skyhanni.mixins.hooks + +import at.hannibal2.skyhanni.events.SpawnParticleEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo + +class RenderGlobalHook { + companion object { + @JvmStatic + fun spawnParticle( + particleId: Int, + x: Double, + y: Double, + z: Double, + ci: CallbackInfo, + ) { + val callerClass = LorenzUtils.getCallerClass( + "at.hannibal2.skyhanni.mixins.hooks.RenderGlobalHook\$Companion", + "at.hannibal2.skyhanni.mixins.hooks.RenderGlobalHook", + "net.minecraft.client.renderer.RenderGlobal", + "net.minecraft.world.World", + "net.minecraft.client.network.NetHandlerPlayClient", + "net.minecraft.network.play.server.S2APacketParticles", + ) ?: "null" + + if (SpawnParticleEvent(particleId, callerClass, x, y, z).postAndCatch()) { + ci.cancel() + return + } + + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityBlaze.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityBlaze.java deleted file mode 100644 index 2565e4c69..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinEntityBlaze.java +++ /dev/null @@ -1,20 +0,0 @@ -package at.hannibal2.skyhanni.mixins.transformers; - -import at.hannibal2.skyhanni.mixins.hooks.EntityBlazeHookKt; -import net.minecraft.entity.monster.EntityBlaze; -import net.minecraft.util.EnumParticleTypes; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(EntityBlaze.class) -public abstract class MixinEntityBlaze { - - @Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnParticle(Lnet/minecraft/util/EnumParticleTypes;DDDDDD[I)V")) - private void onBlazeSpawnParticle(World instance, EnumParticleTypes particleType, double xCoord, double yCoord, double zCoord, double xOffset, double yOffset, double zOffset, int[] p_175688_14_) { - if (!EntityBlazeHookKt.onBlockBlazeParticle(this)) { - instance.spawnParticle(particleType, xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, p_175688_14_); - } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderGlobal.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderGlobal.java index 64f9b1c9a..e658c3c02 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderGlobal.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderGlobal.java @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.mixins.transformers; -import at.hannibal2.skyhanni.events.SpawnParticleEvent; +import at.hannibal2.skyhanni.mixins.hooks.RenderGlobalHook; import net.minecraft.client.renderer.RenderGlobal; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -11,9 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class MixinRenderGlobal { @Inject(method = "spawnParticle(IZDDDDDD[I)V", at = @At("HEAD"), cancellable = true) - private void spawnParticle(int id, boolean ignoreRange, double x, double y, double z, double xOffset, double yOffset, double zOffset, int[] p_180442_15_, CallbackInfo ci) { - if (new SpawnParticleEvent(id, x, y, z).postAndCatch()) { - ci.cancel(); - } + private void spawnParticle(int particleId, boolean ignoreRange, double x, double y, double z, double xOffset, double yOffset, double zOffset, int[] p_180442_15_, CallbackInfo ci) { + RenderGlobalHook.spawnParticle(particleId, x, y, z, ci); } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt index 47575c3f5..ad96a9510 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt @@ -1,9 +1,11 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth +import net.minecraft.client.multiplayer.WorldClient import net.minecraft.entity.EntityLiving import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand +import net.minecraft.entity.monster.EntityBlaze import net.minecraft.entity.player.EntityPlayer import net.minecraft.util.AxisAlignedBB @@ -101,4 +103,12 @@ object EntityUtils { .firstOrNull { it.name == "textures" } ?.value } + + fun WorldClient.getEntitiesNearby( + clazz: Class<EntityBlaze>, + location: LorenzVec, + radius: Double + ): MutableList<EntityBlaze> = getEntities(clazz) { entity -> + entity?.getLorenzVec()?.let { it.distance(location) < radius } ?: false + } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 90b60a7c3..c4c9cedca 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -113,4 +113,19 @@ object LorenzUtils { fun consoleLog(text: String) { SkyHanniMod.consoleLog(text) } + + // Taken and modified from https://stackoverflow.com/a/11306854/5507634 + fun getCallerClass(vararg skip: String): String? { + val stElements = Thread.currentThread().stackTrace + for (i in 1 until stElements.size) { + val ste = stElements[i] + val className = ste.className + if (className != LorenzUtils::class.java.name && className.indexOf("java.lang.Thread") != 0) { + if (className !in skip) { + return className + } + } + } + return null + } }
\ No newline at end of file |