From 4ab5cee193fa807577bd24de88ce22591e491866 Mon Sep 17 00:00:00 2001 From: Alex Thomson Date: Tue, 25 Sep 2018 21:26:23 +1200 Subject: [PATCH] Redirect Inventory debug messages Remove MixinForgeHooks_Harvest as it's fixed upstream --- build.gradle | 4 +- .../lxgaming/sledgehammer/Sledgehammer.java | 6 +- .../configuration/category/MixinCategory.java | 8 +-- .../forge/common/MixinForgeHooks_Harvest.java | 48 -------------- .../mixin/plugin/ForgePlugin.java | 6 +- .../mixin/plugin/SpongePlugin.java | 64 +++++++++++++++++++ .../MixinBasicInventoryPacketState.java | 33 ++++++++++ .../lxgaming/sledgehammer/util/Reference.java | 2 +- .../lxgaming/sledgehammer/util/Toolbox.java | 4 ++ .../resources/mixins.sledgehammer.forge.json | 1 - ...e.json => mixins.sledgehammer.sponge.json} | 4 +- .../mixins.sledgehammer.spongevanilla.json | 14 ---- 12 files changed, 115 insertions(+), 79 deletions(-) delete mode 100644 src/main/java/io/github/lxgaming/sledgehammer/mixin/forge/common/MixinForgeHooks_Harvest.java create mode 100644 src/main/java/io/github/lxgaming/sledgehammer/mixin/plugin/SpongePlugin.java create mode 100644 src/main/java/io/github/lxgaming/sledgehammer/mixin/sponge/common/event/tracking/phase/packet/inventory/MixinBasicInventoryPacketState.java rename src/main/resources/{mixins.sledgehammer.spongeforge.json => mixins.sledgehammer.sponge.json} (61%) delete mode 100644 src/main/resources/mixins.sledgehammer.spongevanilla.json diff --git a/build.gradle b/build.gradle index 90290f2..b0cc440 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ targetCompatibility = 1.8 group = "io.github.lxgaming" archivesBaseName = "Sledgehammer" -version = "1.12.2-1.2.12" +version = "1.12.2-1.2.13" minecraft { version = "1.12.2-14.23.4.2705" @@ -80,7 +80,7 @@ jar { attributes( "FMLCorePluginContainsFMLMod": true, "ForceLoadAsMod": true, - "MixinConfigs": "mixins.sledgehammer.core.json,mixins.sledgehammer.forge.json,mixins.sledgehammer.spongeforge.json,mixins.sledgehammer.spongevanilla.json", + "MixinConfigs": "mixins.sledgehammer.core.json,mixins.sledgehammer.forge.json,mixins.sledgehammer.sponge.json", "TweakClass": "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder": 0 ) diff --git a/src/main/java/io/github/lxgaming/sledgehammer/Sledgehammer.java b/src/main/java/io/github/lxgaming/sledgehammer/Sledgehammer.java index 345277d..27e4077 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/Sledgehammer.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/Sledgehammer.java @@ -76,13 +76,11 @@ private void registerMappings() { // Mixin Forge getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.forge.common.MixinForgeHooks_Advancement", MixinCategory::isAdvancementStacktrace); - getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.forge.common.MixinForgeHooks_Harvest", MixinCategory::isHarvestBlock); getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.forge.entity.passive.MixinEntityVillager", MixinCategory::isTravelingMerchant); getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.forge.world.storage.MixinWorldInfo", MixinCategory::isCeremonyRain); - // Mixin SpongeForge - - // Mixin SpongeVanilla + // Mixin Sponge + getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.sponge.common.event.tracking.phase.packet.inventory.MixinBasicInventoryPacketState", MixinCategory::isInventoryDebug); } public void debugMessage(String format, Object... arguments) { diff --git a/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MixinCategory.java b/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MixinCategory.java index 6915e6d..dc0f64c 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MixinCategory.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/configuration/category/MixinCategory.java @@ -37,8 +37,8 @@ public class MixinCategory { @Setting(value = "ceremony-rain", comment = "Prevents Totemic from changing the weather") private boolean ceremonyRain = false; - @Setting(value = "harvest-block", comment = "Prevents ClassCastException caused by Sponge assuming things") - private boolean harvestBlock = false; + @Setting(value = "inventory-debug", comment = "Redirects inventory debugging messages") + private boolean inventoryDebug = false; @Setting(value = "network-system", comment = "Fixes potential deadlock on shutdown") private boolean networkSystem = false; @@ -66,8 +66,8 @@ public boolean isCeremonyRain() { return ceremonyRain; } - public boolean isHarvestBlock() { - return harvestBlock; + public boolean isInventoryDebug() { + return inventoryDebug; } public boolean isNetworkSystem() { diff --git a/src/main/java/io/github/lxgaming/sledgehammer/mixin/forge/common/MixinForgeHooks_Harvest.java b/src/main/java/io/github/lxgaming/sledgehammer/mixin/forge/common/MixinForgeHooks_Harvest.java deleted file mode 100644 index 74419e2..0000000 --- a/src/main/java/io/github/lxgaming/sledgehammer/mixin/forge/common/MixinForgeHooks_Harvest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2018 Alex Thomson - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.github.lxgaming.sledgehammer.mixin.forge.common; - -import io.github.lxgaming.sledgehammer.Sledgehammer; -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.common.ForgeHooks; -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.CallbackInfoReturnable; -import org.spongepowered.common.event.tracking.PhaseTracker; - -@Mixin(value = ForgeHooks.class, priority = 1337, remap = false) -public abstract class MixinForgeHooks_Harvest { - - @Inject(method = "canHarvestBlock", - at = @At(value = "INVOKE", - target = "Lorg/spongepowered/common/event/tracking/IPhaseState;isInteraction()Z" - ), - cancellable = true - ) - private static void onCanHarvestBlock(Block block, EntityPlayer entityPlayer, IBlockAccess blockAccess, BlockPos blockPos, CallbackInfoReturnable callbackInfoReturnable) { - // Prevents ClassCastException caused by Sponge assuming the IBlockAccess is an instanceof IMixinWorld - if (!PhaseTracker.getInstance().getCurrentPhaseData().state.isInteraction() && !(blockAccess instanceof World)) { - callbackInfoReturnable.setReturnValue(false); - Sledgehammer.getInstance().debugMessage("Harvest denied at {}, {}, {}", blockPos.getX(), blockPos.getY(), blockPos.getZ()); - } - } -} \ No newline at end of file diff --git a/src/main/java/io/github/lxgaming/sledgehammer/mixin/plugin/ForgePlugin.java b/src/main/java/io/github/lxgaming/sledgehammer/mixin/plugin/ForgePlugin.java index 7a97651..85a9973 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/mixin/plugin/ForgePlugin.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/mixin/plugin/ForgePlugin.java @@ -37,11 +37,11 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - if (Toolbox.isClassPresent("net.minecraftforge.fml.relauncher.CoreModManager") || Toolbox.isClassPresent("cpw.mods.fml.relauncher.CoreModManager")) { - return super.shouldApplyMixin(targetClassName, mixinClassName); - } else { + if (!Toolbox.isForgeEnvironment()) { return false; } + + return super.shouldApplyMixin(targetClassName, mixinClassName); } @Override diff --git a/src/main/java/io/github/lxgaming/sledgehammer/mixin/plugin/SpongePlugin.java b/src/main/java/io/github/lxgaming/sledgehammer/mixin/plugin/SpongePlugin.java new file mode 100644 index 0000000..d2f450e --- /dev/null +++ b/src/main/java/io/github/lxgaming/sledgehammer/mixin/plugin/SpongePlugin.java @@ -0,0 +1,64 @@ +/* + * Copyright 2018 Alex Thomson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.github.lxgaming.sledgehammer.mixin.plugin; + +import io.github.lxgaming.sledgehammer.util.Toolbox; +import org.apache.commons.lang3.StringUtils; +import org.spongepowered.asm.lib.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Set; + +public class SpongePlugin extends AbstractPlugin { + + @Override + public void onLoad(String mixinPackage) { + super.onLoad(mixinPackage); + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + if (StringUtils.startsWith(mixinClassName, "io.github.lxgaming.sledgehammer.mixin.sponge.mod.") && !Toolbox.isForgeEnvironment()) { + return false; + } + + return super.shouldApplyMixin(targetClassName, mixinClassName); + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } +} \ No newline at end of file diff --git a/src/main/java/io/github/lxgaming/sledgehammer/mixin/sponge/common/event/tracking/phase/packet/inventory/MixinBasicInventoryPacketState.java b/src/main/java/io/github/lxgaming/sledgehammer/mixin/sponge/common/event/tracking/phase/packet/inventory/MixinBasicInventoryPacketState.java new file mode 100644 index 0000000..3e0a7b2 --- /dev/null +++ b/src/main/java/io/github/lxgaming/sledgehammer/mixin/sponge/common/event/tracking/phase/packet/inventory/MixinBasicInventoryPacketState.java @@ -0,0 +1,33 @@ +/* + * Copyright 2018 Alex Thomson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.github.lxgaming.sledgehammer.mixin.sponge.common.event.tracking.phase.packet.inventory; + +import io.github.lxgaming.sledgehammer.Sledgehammer; +import org.apache.logging.log4j.Logger; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.common.event.tracking.phase.packet.inventory.BasicInventoryPacketState; + +@Mixin(value = BasicInventoryPacketState.class, priority = 1337, remap = false) +public abstract class MixinBasicInventoryPacketState { + + @Redirect(method = "unwind", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;info(Ljava/lang/String;)V")) + private void onLoadAdvancementsError(Logger logger, String message) { + Sledgehammer.getInstance().debugMessage("{} - {}", message); + } +} \ No newline at end of file diff --git a/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java b/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java index 661c479..7ca70ad 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/util/Reference.java @@ -20,7 +20,7 @@ public class Reference { public static final String PLUGIN_ID = "sledgehammer"; public static final String PLUGIN_NAME = "Sledgehammer"; - public static final String PLUGIN_VERSION = "1.12.2-1.2.12"; + public static final String PLUGIN_VERSION = "1.12.2-1.2.13"; public static final String DESCRIPTION = "Smashes the stupid out of the server."; public static final String AUTHORS = "LX_Gaming"; public static final String SOURCE = "https://github.com/LXGaming/Sledgehammer/"; diff --git a/src/main/java/io/github/lxgaming/sledgehammer/util/Toolbox.java b/src/main/java/io/github/lxgaming/sledgehammer/util/Toolbox.java index edbdba7..82a40b9 100644 --- a/src/main/java/io/github/lxgaming/sledgehammer/util/Toolbox.java +++ b/src/main/java/io/github/lxgaming/sledgehammer/util/Toolbox.java @@ -66,6 +66,10 @@ public static Text convertColor(String string) { return TextSerializers.FORMATTING_CODE.deserialize(string); } + public static boolean isForgeEnvironment() { + return Toolbox.isClassPresent("net.minecraftforge.fml.relauncher.CoreModManager") || Toolbox.isClassPresent("cpw.mods.fml.relauncher.CoreModManager"); + } + /** * Removes non-printable characters (excluding new line and carriage return) in the provided {@link java.lang.String String}. * diff --git a/src/main/resources/mixins.sledgehammer.forge.json b/src/main/resources/mixins.sledgehammer.forge.json index 3a76bc8..5ab3791 100644 --- a/src/main/resources/mixins.sledgehammer.forge.json +++ b/src/main/resources/mixins.sledgehammer.forge.json @@ -8,7 +8,6 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "common.MixinForgeHooks_Advancement", - "common.MixinForgeHooks_Harvest", "entity.passive.MixinEntityVillager", "world.storage.MixinWorldInfo" ], diff --git a/src/main/resources/mixins.sledgehammer.spongeforge.json b/src/main/resources/mixins.sledgehammer.sponge.json similarity index 61% rename from src/main/resources/mixins.sledgehammer.spongeforge.json rename to src/main/resources/mixins.sledgehammer.sponge.json index fddfb66..9353f6c 100644 --- a/src/main/resources/mixins.sledgehammer.spongeforge.json +++ b/src/main/resources/mixins.sledgehammer.sponge.json @@ -1,9 +1,9 @@ { "required": true, "minVersion": "0.7.4", - "package": "io.github.lxgaming.sledgehammer.mixin.spongeforge", + "package": "io.github.lxgaming.sledgehammer.mixin.sponge", "refmap": "mixins.sledgehammer.refmap.json", - "plugin": "io.github.lxgaming.sledgehammer.mixin.plugin.ForgePlugin", + "plugin": "io.github.lxgaming.sledgehammer.mixin.plugin.SpongePlugin", "target": "@env(DEFAULT)", "compatibilityLevel": "JAVA_8", "mixins": [ diff --git a/src/main/resources/mixins.sledgehammer.spongevanilla.json b/src/main/resources/mixins.sledgehammer.spongevanilla.json deleted file mode 100644 index 54ba505..0000000 --- a/src/main/resources/mixins.sledgehammer.spongevanilla.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "minVersion": "0.7.4", - "package": "io.github.lxgaming.sledgehammer.mixin.spongevanilla", - "refmap": "mixins.sledgehammer.refmap.json", - "plugin": "io.github.lxgaming.sledgehammer.mixin.plugin.CorePlugin", - "target": "@env(DEFAULT)", - "compatibilityLevel": "JAVA_8", - "mixins": [ - ], - "injectors": { - "defaultRequire": 1 - } -} \ No newline at end of file