Skip to content

Commit

Permalink
A little hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Oganesson897 committed Aug 12, 2024
1 parent a4f7b9c commit edfee7e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/main/java/appeng/items/materials/NamePressItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

import java.util.List;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

import appeng.api.ids.AEComponents;
import appeng.items.AEBaseItem;
Expand All @@ -34,7 +34,7 @@ public NamePressItem(Properties properties) {
super(properties);
}

@OnlyIn(Dist.CLIENT)
@Environment(EnvType.CLIENT)
@Override
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> lines,
TooltipFlag advancedTooltips) {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/appeng/items/materials/UpgradeCardItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.util.List;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand All @@ -28,8 +30,6 @@
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

import appeng.api.parts.IPartHost;
import appeng.api.parts.SelectedPart;
Expand All @@ -40,14 +40,15 @@
import appeng.core.localization.PlayerMessages;
import appeng.items.AEBaseItem;
import appeng.util.InteractionUtil;
import refabricated.patches.IItemExtended;

public class UpgradeCardItem extends AEBaseItem {
public class UpgradeCardItem extends AEBaseItem implements IItemExtended {

public UpgradeCardItem(Properties properties) {
super(properties);
}

@OnlyIn(Dist.CLIENT)
@Environment(EnvType.CLIENT)
@Override
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> lines,
TooltipFlag advancedTooltips) {
Expand Down Expand Up @@ -111,6 +112,6 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
}
}

return super.onItemUseFirst(stack, context);
return IItemExtended.super.onItemUseFirst(stack, context);
}
}
13 changes: 13 additions & 0 deletions src/main/java/refabricated/patches/IItemExtended.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package refabricated.patches;

import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;

public interface IItemExtended {

default InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
return InteractionResult.PASS;
}

}
38 changes: 38 additions & 0 deletions src/main/java/refabricated/patches/IItemStackExtended.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package refabricated.patches;

import net.minecraft.core.BlockPos;
import net.minecraft.core.component.DataComponents;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.AdventureModePredicate;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.state.pattern.BlockInWorld;

public interface IItemStackExtended {

private ItemStack self() {
return (ItemStack) (Object) this;
}

default InteractionResult onItemUseFirst(UseOnContext context) {
Player entityplayer = context.getPlayer();
BlockPos blockpos = context.getClickedPos();
BlockInWorld state = new BlockInWorld(context.getLevel(), blockpos, false);
AdventureModePredicate adventureModePredicate = self().get(DataComponents.CAN_PLACE_ON);
if (entityplayer != null && !entityplayer.getAbilities().mayBuild && (adventureModePredicate == null || !adventureModePredicate.test(state))) {
return InteractionResult.PASS;
} else {
Item item = self().getItem();
InteractionResult result = ((IItemExtended) item).onItemUseFirst(self(), context);
if (entityplayer != null && result == InteractionResult.SUCCESS) {
entityplayer.awardStat(Stats.ITEM_USED.get(item));
}

return result;
}
}

}
6 changes: 5 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"rei_client": ["appeng.integration.modules.rei.ReiPlugin"],
"jade": ["appeng.integration.modules.jade.JadeModule"]
},
"mixins": ["ae2.mixins.json"],
"mixins": ["ae2.mixins.json", "refabricated.mixins.json"],
"depends": {
"fabricloader": ">=0.16.0",
"fabric": ">=0.102.0",
Expand All @@ -35,6 +35,10 @@
"waila:plugins": {
"id": "ae2:wthit",
"initializer": "appeng.integration.modules.wthit.WthitModule"
},
"loom:injected_interfaces": {
"net/minecraft/class_1792": ["refabricated.patches.IItemExtended"],
"net/minecraft/class_1799": ["refabricated.patches.IItemStackExtended"]
}
}
}
12 changes: 12 additions & 0 deletions src/main/resources/refabricated.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": true,
"minVersion": "0.8.3",
"package": "refabricated.mixins",
"compatibilityLevel": "JAVA_11",
"mixins": [
],
"server": [],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit edfee7e

Please sign in to comment.