-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Upgrades not Enter GUI if Cannot be Applied
Fixes #30
- Loading branch information
1 parent
8333410
commit 08eb5b0
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/nomiceu/nomilabs/mixin/thermalfoundation/ItemUpgradeMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters