Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Fix #7843. - Allow player to clear the link when Pressing Shift + Right-click #7947

Open
wants to merge 3 commits into
base: mc1.20.1/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,9 @@ public int getDirectSignal(BlockState pBlockState, BlockGetter pBlockAccess, Blo

@Override
public boolean canBeReplaced(BlockState pState, BlockPlaceContext pUseContext) {
if (pUseContext.isSecondaryUseActive())
return false;
if (!AllBlocks.FACTORY_GAUGE.isIn(pUseContext.getItemInHand()))
return false;
Vec3 location = pUseContext.getClickLocation();
if (location == null)
return false;

BlockPos pos = pUseContext.getClickedPos();
PanelSlot slot = getTargetedSlot(pos, pState, location);
FactoryPanelBlockEntity blockEntity = getBlockEntity(pUseContext.getLevel(), pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.ClipContext.Fluid;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;

import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult.Type;
public class LogisticallyLinkedBlockItem extends BlockItem {

public LogisticallyLinkedBlockItem(Block pBlock, Properties pProperties) {
Expand All @@ -36,7 +40,7 @@ public static boolean isTuned(ItemStack pStack) {
return pStack.hasTag() && pStack.getTag()
.contains(BLOCK_ENTITY_TAG);
}

@Nullable
public static UUID networkFromStack(ItemStack pStack) {
if (!isTuned(pStack))
Expand Down Expand Up @@ -112,4 +116,15 @@ public static void assignFrequency(ItemStack stack, Player player, UUID frequenc
stack.setTag(stackTag);
}

public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
ItemStack itemstack = player.getItemInHand(usedHand);
if (level.isClientSide) return InteractionResultHolder.pass(itemstack);
BlockHitResult hitResult = getPlayerPOVHitResult(level, player, Fluid.NONE);
if (itemstack.getTag() != null && !itemstack.getTag().contains(BLOCK_ENTITY_TAG))
return InteractionResultHolder.fail(itemstack);
if (player.isShiftKeyDown() && hitResult.getType() == Type.MISS && itemstack.getTag() != null)
itemstack.getTag().remove(BLOCK_ENTITY_TAG);
return InteractionResultHolder.success(itemstack);
}

}