Skip to content

Commit 3aa7c7f

Browse files
authored
Merge pull request #75 from LuziferSenpai/PriorityCard-CableBusFix
[Fix] Priority Card now applies to the correct cable part
2 parents 8699f6b + 10bd3d7 commit 3aa7c7f

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

src/main/java/lu/kolja/expandedae/item/misc/PriorityCardItem.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package lu.kolja.expandedae.item.misc;
22

3-
import appeng.api.parts.IPartHost;
3+
import appeng.blockentity.networking.CableBusBlockEntity;
44
import appeng.helpers.IPriorityHost;
55
import appeng.items.AEBaseItem;
66
import appeng.util.InteractionUtil;
77
import lu.kolja.expandedae.definition.ExpLang;
88
import net.minecraft.MethodsReturnNonnullByDefault;
9+
import net.minecraft.core.BlockPos;
910
import net.minecraft.network.chat.Component;
1011
import net.minecraft.world.InteractionHand;
1112
import net.minecraft.world.InteractionResult;
@@ -15,6 +16,8 @@
1516
import net.minecraft.world.item.TooltipFlag;
1617
import net.minecraft.world.item.context.UseOnContext;
1718
import net.minecraft.world.level.Level;
19+
import net.minecraft.world.level.block.entity.BlockEntity;
20+
import net.minecraft.world.phys.Vec3;
1821
import org.jetbrains.annotations.Nullable;
1922

2023
import javax.annotation.ParametersAreNonnullByDefault;
@@ -25,14 +28,17 @@
2528
public class PriorityCardItem extends AEBaseItem {
2629
public static final String NBT_PRIO = "priority";
2730
public static final String NBT_MODE = "mode";
31+
2832
public PriorityCardItem(Properties properties) {
2933
super(properties);
3034
}
3135

3236
@Override
3337
public InteractionResult useOn(UseOnContext ctx) {
3438
if (ctx.getLevel().isClientSide) return InteractionResult.FAIL;
35-
var block = ctx.getLevel().getBlockEntity(ctx.getClickedPos());
39+
40+
BlockPos hitPos = ctx.getClickedPos();
41+
var block = ctx.getLevel().getBlockEntity(hitPos);
3642
var tag = ctx.getItemInHand().getOrCreateTag();
3743
var prio = tag.getInt(NBT_PRIO);
3844
var mode = tag.getBoolean(NBT_MODE);
@@ -41,10 +47,15 @@ public InteractionResult useOn(UseOnContext ctx) {
4147
if (block instanceof IPriorityHost prioHost) {
4248
prioHost.setPriority(prio);
4349
be = block.getBlockState().getBlock().getName();
44-
} else if (block instanceof IPartHost partHost && partHost.getPart(ctx.getHorizontalDirection()) instanceof IPriorityHost prioPart) {
45-
prioPart.setPriority(prio);
46-
var partItem = partHost.getPart(ctx.getClickedFace()).getPartItem().asItem();
47-
be = partItem.getName(new ItemStack(partItem));
50+
} else if (block instanceof CableBusBlockEntity cable) {
51+
Vec3 hitVec = ctx.getClickLocation();
52+
Vec3 hitInBlock = new Vec3(hitVec.x - hitPos.getX(), hitVec.y - hitPos.getY(), hitVec.z - hitPos.getZ());
53+
var selected = cable.getCableBus().selectPartLocal(hitInBlock);
54+
if (selected.part instanceof IPriorityHost prioPart) {
55+
prioPart.setPriority(prio);
56+
var partItem = selected.part.getPartItem().asItem();
57+
be = partItem.getName(new ItemStack(partItem));
58+
} else return InteractionResult.FAIL;
4859
} else return InteractionResult.FAIL;
4960
ctx.getPlayer().sendSystemMessage(ExpLang.PRIO_CHANGED.text(be, "§b" + prio));
5061
prio += mode ? 1 : -1;

0 commit comments

Comments
 (0)