Skip to content

Commit

Permalink
Fixed more
Browse files Browse the repository at this point in the history
  • Loading branch information
Oganesson897 committed Aug 12, 2024
1 parent 08078e6 commit 28f113d
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 33 deletions.
4 changes: 3 additions & 1 deletion src/main/java/appeng/hooks/AEToolItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
import net.minecraft.world.item.context.UseOnContext;

public interface AEToolItem {
InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context);
default InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
return InteractionResult.PASS;
};
}
6 changes: 3 additions & 3 deletions src/main/java/appeng/items/materials/UpgradeCardItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.List;

import appeng.hooks.AEToolItem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.Component;
Expand All @@ -40,9 +41,8 @@
import appeng.core.localization.PlayerMessages;
import appeng.items.AEBaseItem;
import appeng.util.InteractionUtil;
import starry.refabricated.ae2.patches.IItemExtended;

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

public UpgradeCardItem(Properties properties) {
super(properties);
Expand Down Expand Up @@ -112,6 +112,6 @@ public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
}
}

return IItemExtended.super.onItemUseFirst(stack, context);
return AEToolItem.super.onItemUseFirst(stack, context);
}
}
4 changes: 2 additions & 2 deletions src/main/java/appeng/items/parts/FacadeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package appeng.items.parts;

import appeng.hooks.AEToolItem;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -48,9 +49,8 @@
import appeng.core.definitions.AEItems;
import appeng.facade.FacadePart;
import appeng.items.AEBaseItem;
import starry.refabricated.ae2.patches.IItemExtended;

public class FacadeItem extends AEBaseItem implements IFacadeItem, IItemExtended {
public class FacadeItem extends AEBaseItem implements IFacadeItem, AEToolItem {

public FacadeItem(Properties properties) {
super(properties);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/appeng/items/tools/MemoryCardItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.util.List;
import java.util.Set;

import appeng.hooks.AEToolItem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.Nullable;

import net.minecraft.ChatFormatting;
Expand All @@ -44,8 +47,6 @@
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenCustomHashMap;
Expand Down Expand Up @@ -277,7 +278,7 @@ private static void restoreUpgrades(Player player, ExportedUpgrades desiredUpgra
}

@Override
@OnlyIn(Dist.CLIENT)
@Environment(EnvType.CLIENT)
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> lines,
TooltipFlag advancedTooltips) {

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/appeng/items/tools/NetworkToolItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Optional;

import appeng.hooks.AEToolItem;
import org.jetbrains.annotations.Nullable;

import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -64,7 +65,7 @@
import appeng.util.inv.InternalInventoryHost;
import appeng.util.inv.filter.IAEItemFilter;

public class NetworkToolItem extends AEBaseItem implements IMenuItem {
public class NetworkToolItem extends AEBaseItem implements IMenuItem, AEToolItem {

public NetworkToolItem(Properties properties) {
super(properties);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package starry.refabricated.ae2.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(MultiPlayerGameMode.class)
public class MultiPlayerGameModeMixin {

@ModifyVariable(method = "performUseItemOn", at = @At(value = "STORE"), ordinal = 1)
private boolean injected(boolean x, @Local(argsOnly = true) LocalPlayer player, @Local BlockPos blockpos) {
return x && !(player.getMainHandItem().doesSneakBypassUse(player.level(), blockpos, player) && player.getOffhandItem().doesSneakBypassUse(player.level(), blockpos, player));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package starry.refabricated.ae2.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(ServerPlayerGameMode.class)
public class ServerPlayerGameModeMixin {

@ModifyVariable(method = "useItemOn", at = @At(value = "STORE"), ordinal = 1)
private boolean injected(boolean x, @Local(argsOnly = true) ServerPlayer player, @Local(argsOnly = true) Level level, @Local BlockPos blockpos) {
return x && !(player.getMainHandItem().doesSneakBypassUse(level, blockpos, player) && player.getOffhandItem().doesSneakBypassUse(level, blockpos, player));
}

}
10 changes: 6 additions & 4 deletions src/main/java/starry/refabricated/ae2/patches/IItemExtended.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package starry.refabricated.ae2.patches;

import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
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;
}

default boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
return !oldStack.equals(newStack); // !ItemStack.areItemStacksEqual(oldStack, newStack);
}

default boolean doesSneakBypassUse(ItemStack stack, net.minecraft.world.level.LevelReader level, BlockPos pos, Player player) {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,8 @@ 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;
}
default boolean doesSneakBypassUse(net.minecraft.world.level.LevelReader level, BlockPos pos, Player player) {
return self().isEmpty() || self().getItem().doesSneakBypassUse(self(), level, pos, player);
}

}
8 changes: 5 additions & 3 deletions src/main/resources/ae2.refabricated.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
"mixins": [
"MinecraftServerMixin",
"PlayerMixin",
"ServerLevelMixin"
"ServerLevelMixin",
"ServerPlayerGameModeMixin"
],
"server": [],
"injectors": {
"defaultRequire": 1
},
"client": [
"client.MouseHandlerMixin",
"client.ItemInHandRendererMixin"
"MultiPlayerGameModeMixin",
"client.ItemInHandRendererMixin",
"client.MouseHandlerMixin"
]
}

0 comments on commit 28f113d

Please sign in to comment.