Skip to content

Commit

Permalink
Fix ClassCastException caused by Sponge assuming things
Browse files Browse the repository at this point in the history
  • Loading branch information
LXGaming committed Aug 10, 2018
1 parent 5cba84e commit 53fa0a8
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ targetCompatibility = 1.8

group = "io.github.lxgaming"
archivesBaseName = "Sledgehammer"
version = "1.2.2-1.12.2"
version = "1.2.3-1.12.2"

minecraft {
version = "1.12.2-14.23.4.2705"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ private void registerMappings() {

// Mixin Forge
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.forge.common.MixinDimensionManager", MixinCategory::isDimensionManager);
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.forge.common.MixinForgeHooks", MixinCategory::isAdvancementStacktrace);
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class MixinCategory {
@Setting(value = "dimension-manager", comment = "Fixes https://github.com/SpongePowered/SpongeForge/issues/2173 (Fixed in SpongeForge-1.12.2-2703-7.1.0-BETA-3124)")
private boolean dimensionManager = false;

@Setting(value = "harvest-block", comment = "Prevents ClassCastException caused by Sponge assuming things")
private boolean harvestBlock = false;

@Setting(value = "interact-events", comment = "Fixes https://github.com/SpongePowered/SpongeCommon/issues/2013")
private boolean interactEvents = false;

Expand Down Expand Up @@ -80,6 +83,10 @@ public boolean isDimensionManager() {
return dimensionManager;
}

public boolean isHarvestBlock() {
return harvestBlock;
}

public boolean isInteractEvents() {
return interactEvents;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(value = ForgeHooks.class, priority = 1337, remap = false)
public abstract class MixinForgeHooks {
public abstract class MixinForgeHooks_Advancement {

@Redirect(method = "lambda$loadAdvancements$0", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;error(Ljava/lang/String;Ljava/lang/Throwable;)V"))
private static void onLoadAdvancementsError(Logger logger, String message, Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.ForgeHooks;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.chat.ChatTypes;
import org.spongepowered.api.text.format.TextColors;
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;
import org.spongepowered.common.interfaces.world.IMixinWorld;

@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<Boolean> callbackInfoReturnable) {
// Prevents ClassCastException caused by Sponge assuming the IBlockAccess is an instanceof IMixinWorld
if (!PhaseTracker.getInstance().getCurrentPhaseData().state.isInteraction() && !(blockAccess instanceof IMixinWorld)) {
callbackInfoReturnable.setReturnValue(false);

// Using ACTION_BAR to prevent chat spam
((Player) entityPlayer).sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "Harvest denied at (", blockPos.getX(), ", ", blockPos.getY(), ", ", blockPos.getZ(), ")"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.2-1.12.2";
public static final String PLUGIN_VERSION = "1.2.3-1.12.2";
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/";
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/mixins.sledgehammer.forge.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"common.MixinDimensionManager",
"common.MixinForgeHooks",
"common.MixinForgeHooks_Advancement",
"common.MixinForgeHooks_Harvest",
"entity.passive.MixinEntityVillager",
"world.storage.MixinWorldInfo"
],
Expand Down

0 comments on commit 53fa0a8

Please sign in to comment.