Skip to content

Commit

Permalink
Allow toolbelt to fix maintenance in-world and prevent merge crafting
Browse files Browse the repository at this point in the history
  • Loading branch information
M-W-K committed Nov 8, 2024
1 parent 03c55bc commit f374049
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gregtech.api.items.IDyeableItem;
import gregtech.api.items.gui.ItemUIFactory;
import gregtech.api.items.toolitem.behavior.IToolBehavior;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.mui.GTGuiTextures;
import gregtech.api.mui.GTGuis;
import gregtech.api.unification.material.Material;
Expand All @@ -12,6 +13,7 @@
import gregtech.api.unification.material.properties.ToolProperty;
import gregtech.api.util.LocalizationUtils;
import gregtech.common.items.behaviors.ColorSprayBehaviour;
import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMaintenanceHatch;
import gregtech.core.network.packets.PacketToolbeltSelectionChange;

import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -393,9 +395,15 @@ public void setSelectedTool(@Nullable Integer slot, ItemStack stack) {
@NotNull BlockPos pos, @NotNull EnumFacing side, float hitX,
float hitY, float hitZ, @NotNull EnumHand hand) {
EnumActionResult result = IDyeableItem.super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
if (result == EnumActionResult.PASS)
if (result == EnumActionResult.PASS) {
ToolStackHandler handler = getHandler(player.getHeldItem(hand));
if (handler.getSelectedSlot() == null && world.getTileEntity(pos) instanceof MetaTileEntityHolder holder &&
holder.getMetaTileEntity() instanceof MetaTileEntityMaintenanceHatch maintenance) {
maintenance.fixMaintenanceProblems(player);
return EnumActionResult.SUCCESS;
}
return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
else return result;
} else return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void update() {
*
* @param entityPlayer the player performing the fixing
*/
private void fixMaintenanceProblems(@Nullable EntityPlayer entityPlayer) {
public void fixMaintenanceProblems(@Nullable EntityPlayer entityPlayer) {
if (!(this.getController() instanceof IMaintenance))
return;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gregtech.mixins.minecraft;

import gregtech.api.items.toolitem.IGTTool;
import gregtech.api.items.toolitem.ItemGTToolbelt;
import gregtech.api.items.toolitem.ToolHelper;

import net.minecraft.inventory.InventoryCrafting;
Expand Down Expand Up @@ -36,7 +37,8 @@ public class RecipeRepairItemMixin {
ItemStack itemstack1 = list.get(0);
if (itemstack.getItem() instanceof IGTTool first &&
itemstack1.getItem() instanceof IGTTool second) {
if (first.isElectric() || second.isElectric()) {
if (first.isElectric() || second.isElectric() ||
first instanceof ItemGTToolbelt || second instanceof ItemGTToolbelt) {
cir.setReturnValue(false);
} else {
cir.setReturnValue(first.getToolMaterial(itemstack) == second.getToolMaterial(itemstack1));
Expand Down

0 comments on commit f374049

Please sign in to comment.