Skip to content

Commit

Permalink
Make Upgrades not Enter GUI if Cannot be Applied
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
IntegerLimit committed Oct 19, 2024
1 parent 8333410 commit 08eb5b0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ enable_find = false
# Whether to enable Thermal Expansion and its deps in runtime. These are used for the excitation coil textures.
# Also sets the Tome of Experience to have Linear XP Scaling.
# If this is set to false, the top of the excitation coil will have a null texture.
enable_thermal = false
enable_thermal = true

# Whether to enable Mouse Tweaks in runtime. Useful for testing interactions with various GUIs.
enable_mouse_tweaks = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.nomiceu.nomilabs.mixin.thermalfoundation;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;

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 cofh.api.tileentity.IUpgradeable;
import cofh.core.util.helpers.ChatHelper;
import cofh.thermalfoundation.item.ItemUpgrade;

/**
* Makes Unapplyable Upgrades Display Fail Message Instead of Entering GUI.
*/
@Mixin(value = ItemUpgrade.class, remap = false)
public class ItemUpgradeMixin {

@Inject(method = "onItemUseFirst", at = @At("HEAD"), cancellable = true)
private void handleUnapplyableUpgrades(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX,
float hitY, float hitZ, EnumHand hand,
CallbackInfoReturnable<EnumActionResult> cir) {
var te = world.getTileEntity(pos);
if (!(te instanceof IUpgradeable upgradeable) || world.isRemote) return;

if (!upgradeable.canUpgrade(player.getHeldItem(hand))) {
ChatHelper.sendIndexedChatMessageToPlayer(player,
new TextComponentTranslation("chat.thermalfoundation.upgrade.install.failure"));
cir.setReturnValue(EnumActionResult.SUCCESS); // So that it doesn't open GUI
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/mixins.nomilabs.thermalfoundation.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ItemTomeExperienceMixin"
"ItemTomeExperienceMixin",
"ItemUpgradeMixin"
],
"client": [],
"server": []
Expand Down

0 comments on commit 08eb5b0

Please sign in to comment.