From 4e81e91a7aea23b81347accf56f89121451f7e0c Mon Sep 17 00:00:00 2001 From: Appability Date: Wed, 12 Oct 2022 14:30:01 -0700 Subject: ignore carpet (this time stolen from floppa) + surprisingly annoying lateinit stuff --- .../java/com/ambientaddons/mixin/MixinBlock.java | 12 ++++++++++++ .../java/com/ambientaddons/mixin/MixinCarpet.java | 20 ++++++++++++++++++++ src/main/kotlin/com/ambientaddons/AmbientAddons.kt | 4 ++++ src/main/kotlin/com/ambientaddons/config/Config.kt | 7 +++++++ .../ambientaddons/features/dungeon/IgnoreCarpet.kt | 9 +++++++++ src/main/resources/mixins.ambientaddons.json | 4 +++- 6 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/ambientaddons/mixin/MixinBlock.java create mode 100644 src/main/java/com/ambientaddons/mixin/MixinCarpet.java create mode 100644 src/main/kotlin/com/ambientaddons/features/dungeon/IgnoreCarpet.kt (limited to 'src') diff --git a/src/main/java/com/ambientaddons/mixin/MixinBlock.java b/src/main/java/com/ambientaddons/mixin/MixinBlock.java new file mode 100644 index 0000000..a30b15d --- /dev/null +++ b/src/main/java/com/ambientaddons/mixin/MixinBlock.java @@ -0,0 +1,12 @@ +package com.ambientaddons.mixin; + +import net.minecraft.block.Block; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +// credit Floppa Client +@Mixin(Block.class) +public abstract class MixinBlock { + @Shadow + public abstract void setBlockBounds(float minX, float minY, float minZ, float maxX, float maxY, float maxZ); +} diff --git a/src/main/java/com/ambientaddons/mixin/MixinCarpet.java b/src/main/java/com/ambientaddons/mixin/MixinCarpet.java new file mode 100644 index 0000000..20de47c --- /dev/null +++ b/src/main/java/com/ambientaddons/mixin/MixinCarpet.java @@ -0,0 +1,20 @@ +package com.ambientaddons.mixin; + +import com.ambientaddons.features.dungeon.IgnoreCarpet; +import net.minecraft.block.BlockCarpet; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +// credit Floppa Client +@Mixin(BlockCarpet.class) +public abstract class MixinCarpet extends MixinBlock { + @Inject(method = "setBlockBoundsFromMeta", at = @At("HEAD"), cancellable = true) + protected void setBlockBoundsFromMeta(int meta, CallbackInfo ci) { + if (IgnoreCarpet.INSTANCE.shouldIgnoreCarpet()) { + setBlockBounds(0F, 0F, 0F, 1F, 0F, 1F); + ci.cancel(); + } + } +} diff --git a/src/main/kotlin/com/ambientaddons/AmbientAddons.kt b/src/main/kotlin/com/ambientaddons/AmbientAddons.kt index 08cd271..b24aa5c 100644 --- a/src/main/kotlin/com/ambientaddons/AmbientAddons.kt +++ b/src/main/kotlin/com/ambientaddons/AmbientAddons.kt @@ -56,6 +56,10 @@ class AmbientAddons { } companion object { + fun isInitialized(): Boolean { + return ::config.isInitialized + } + val mc: Minecraft = Minecraft.getMinecraft() var currentGui: GuiScreen? = null diff --git a/src/main/kotlin/com/ambientaddons/config/Config.kt b/src/main/kotlin/com/ambientaddons/config/Config.kt index 19a11a6..d62ff8f 100644 --- a/src/main/kotlin/com/ambientaddons/config/Config.kt +++ b/src/main/kotlin/com/ambientaddons/config/Config.kt @@ -14,6 +14,8 @@ object Config : Vigilant( var cancelInteractions = false var closeSecretChests = false + var ignoreCarpet = false + init { category("Pre/Post Dungeon") { @@ -44,6 +46,11 @@ object Config : Vigilant( name = "Block opening secret chests", description = "Cancels opening chests containing secrets." ) + switch( + ::ignoreCarpet, + name = "Ignore carpet hitboxes", + description = "Removes all carpet hitboxes" + ) } } } diff --git a/src/main/kotlin/com/ambientaddons/features/dungeon/IgnoreCarpet.kt b/src/main/kotlin/com/ambientaddons/features/dungeon/IgnoreCarpet.kt new file mode 100644 index 0000000..6283b9c --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/features/dungeon/IgnoreCarpet.kt @@ -0,0 +1,9 @@ +package com.ambientaddons.features.dungeon + +import AmbientAddons.Companion.config + +object IgnoreCarpet { + fun shouldIgnoreCarpet(): Boolean = if (AmbientAddons.isInitialized()) { + config.ignoreCarpet + } else false +} \ No newline at end of file diff --git a/src/main/resources/mixins.ambientaddons.json b/src/main/resources/mixins.ambientaddons.json index 235c713..e8367a6 100644 --- a/src/main/resources/mixins.ambientaddons.json +++ b/src/main/resources/mixins.ambientaddons.json @@ -5,6 +5,8 @@ "compatibilityLevel": "JAVA_8", "client": [ "MixinGuiContainer", - "MixinNetworkManager" + "MixinNetworkManager", + "MixinBlock", + "MixinCarpet" ] } -- cgit