diff --git a/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetBuilding.java b/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetBuilding.java index 9921f159..66af5efc 100644 --- a/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetBuilding.java +++ b/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetBuilding.java @@ -5,8 +5,8 @@ import com.direwolf20.buildinggadgets.common.blocks.EffectBlock; import com.direwolf20.buildinggadgets.common.items.modes.AbstractMode; import com.direwolf20.buildinggadgets.common.items.modes.BuildingModes; +import com.direwolf20.buildinggadgets.common.network.C2S.PacketBindTool; import com.direwolf20.buildinggadgets.common.network.C2S.PacketRotateMirror; -import com.direwolf20.buildinggadgets.common.network.S2C.LookupResult; import com.direwolf20.buildinggadgets.common.tainted.building.BlockData; import com.direwolf20.buildinggadgets.common.tainted.building.view.BuildContext; import com.direwolf20.buildinggadgets.common.tainted.inventory.IItemIndex; @@ -24,9 +24,9 @@ import com.direwolf20.buildinggadgets.common.util.ref.Reference.TagReference; import com.direwolf20.buildinggadgets.common.world.MockBuilderWorld; import com.google.common.collect.ImmutableMultiset; -import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -130,19 +130,12 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List use(Level world, Player player, InteractionHand hand) { //On item use, if sneaking, select the block clicked on, else build -- This is called when you right click a tool NOT on a block. ItemStack itemstack = player.getItemInHand(hand); - BlockHitResult posLookingAt = VectorHelper.getLookingAt(player, itemstack); player.startUsingItem(hand); if (!world.isClientSide) { - boolean lookingAtInventory = ItemStorage.SIDED.find(world, posLookingAt.getBlockPos(), posLookingAt.getDirection()) != null; // Debug code for free energy //itemstack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.receiveEnergy(15000000, false)); if (player.isShiftKeyDown()) { - if (lookingAtInventory) { - LookupResult.sendToClient((ServerPlayer) player, lookingAtInventory); - return InteractionResultHolder.pass(itemstack); - } - InteractionResultHolder result = selectBlock(itemstack, player); if (!result.getResult().consumesAction()) { player.displayClientMessage(MessageTranslation.INVALID_BLOCK.componentTranslation(result.getObject().getName()).setStyle(Styles.AQUA), true); @@ -154,6 +147,10 @@ public InteractionResultHolder use(Level world, Player player, Intera } else { if (!player.isShiftKeyDown()) { BaseRenderer.updateInventoryCache(); + } else { + if (Screen.hasControlDown()) { + PacketBindTool.send(); + } } } return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemstack); diff --git a/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetCopyPaste.java b/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetCopyPaste.java index be89e733..b5799154 100644 --- a/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetCopyPaste.java +++ b/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetCopyPaste.java @@ -3,14 +3,12 @@ import com.direwolf20.buildinggadgets.client.renders.BaseRenderer; import com.direwolf20.buildinggadgets.client.screen.GuiMod; import com.direwolf20.buildinggadgets.client.screen.tooltip.TemplateData; -import com.direwolf20.buildinggadgets.client.screen.tooltip.TemplateTooltip; import com.direwolf20.buildinggadgets.common.BuildingGadgets; import com.direwolf20.buildinggadgets.common.commands.ForceUnloadedCommand; import com.direwolf20.buildinggadgets.common.commands.OverrideBuildSizeCommand; import com.direwolf20.buildinggadgets.common.commands.OverrideCopySizeCommand; import com.direwolf20.buildinggadgets.common.component.BGComponent; import com.direwolf20.buildinggadgets.common.network.C2S.PacketBindTool; -import com.direwolf20.buildinggadgets.common.network.S2C.LookupResult; import com.direwolf20.buildinggadgets.common.network.Target; import com.direwolf20.buildinggadgets.common.tainted.building.PlacementChecker; import com.direwolf20.buildinggadgets.common.tainted.building.Region; @@ -33,11 +31,9 @@ import com.direwolf20.buildinggadgets.common.util.ref.Reference.TagReference; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableSortedSet; -import com.mojang.blaze3d.platform.InputConstants; import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.fabricmc.fabric.api.util.NbtType; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -47,7 +43,6 @@ import net.minecraft.network.protocol.PacketFlow; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.Container; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.player.Player; @@ -275,11 +270,10 @@ public InteractionResultHolder use(Level world, Player player, Intera player.startUsingItem(hand); BlockHitResult posLookingAt = VectorHelper.getLookingAt(player, stack); + boolean lookingAtInventory = ItemStorage.SIDED.find(world, posLookingAt.getBlockPos(), posLookingAt.getDirection()) != null; if (!world.isClientSide()) { - boolean lookingAtInventory = ItemStorage.SIDED.find(world, posLookingAt.getBlockPos(), posLookingAt.getDirection()) != null; if (player.isShiftKeyDown() && lookingAtInventory) { - LookupResult.sendToClient((ServerPlayer) player, lookingAtInventory); return InteractionResultHolder.pass(stack); } @@ -291,6 +285,11 @@ public InteractionResultHolder use(Level world, Player player, Intera getActivePos(player, stack).ifPresent(pos -> build(stack, world, player, pos, hand)); } } else { + if (player.isShiftKeyDown() && Screen.hasControlDown() && lookingAtInventory) { + PacketBindTool.send(); + return InteractionResultHolder.pass(stack); + } + if (getToolMode(stack) == ToolMode.COPY) { if (player.isShiftKeyDown() && world.getBlockState(posLookingAt.getBlockPos()) == Blocks.AIR.defaultBlockState()) { GuiMod.COPY.openScreen(player); diff --git a/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetExchanger.java b/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetExchanger.java index d2f8f5b9..c731f0c9 100644 --- a/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetExchanger.java +++ b/src/main/java/com/direwolf20/buildinggadgets/common/items/GadgetExchanger.java @@ -7,8 +7,8 @@ import com.direwolf20.buildinggadgets.common.enchants.GadgetSilkTouch; import com.direwolf20.buildinggadgets.common.items.modes.AbstractMode; import com.direwolf20.buildinggadgets.common.items.modes.ExchangingModes; +import com.direwolf20.buildinggadgets.common.network.C2S.PacketBindTool; import com.direwolf20.buildinggadgets.common.network.C2S.PacketRotateMirror; -import com.direwolf20.buildinggadgets.common.network.S2C.LookupResult; import com.direwolf20.buildinggadgets.common.tainted.building.BlockData; import com.direwolf20.buildinggadgets.common.tainted.building.tilesupport.ITileEntityData; import com.direwolf20.buildinggadgets.common.tainted.building.tilesupport.TileSupport; @@ -28,10 +28,10 @@ import com.google.common.collect.ImmutableMultiset; import com.google.common.collect.LinkedHashMultiset; import com.google.common.collect.Multiset; -import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; @@ -143,18 +143,11 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List use(Level world, Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); - BlockHitResult posLookingAt = VectorHelper.getLookingAt(player, itemstack); player.startUsingItem(hand); if (!world.isClientSide) { - boolean lookingAtInventory = ItemStorage.SIDED.find(world, posLookingAt.getBlockPos(), posLookingAt.getDirection()) != null; if (player.isShiftKeyDown()) { - if (lookingAtInventory) { - LookupResult.sendToClient((ServerPlayer) player, lookingAtInventory); - return InteractionResultHolder.pass(itemstack); - } - InteractionResultHolder result = selectBlock(itemstack, player); if (!result.getResult().consumesAction()) { player.displayClientMessage(MessageTranslation.INVALID_BLOCK.componentTranslation(Registry.BLOCK.getKey(result.getObject())).setStyle(Styles.AQUA), true); @@ -169,6 +162,10 @@ public InteractionResultHolder use(Level world, Player player, Intera } else { if (!player.isShiftKeyDown()) { BaseRenderer.updateInventoryCache(); + } else { + if (Screen.hasControlDown()) { + PacketBindTool.send(); + } } } return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemstack); diff --git a/src/main/java/com/direwolf20/buildinggadgets/common/network/ClientPacketHandler.java b/src/main/java/com/direwolf20/buildinggadgets/common/network/ClientPacketHandler.java index 17270fab..87ffdd5a 100644 --- a/src/main/java/com/direwolf20/buildinggadgets/common/network/ClientPacketHandler.java +++ b/src/main/java/com/direwolf20/buildinggadgets/common/network/ClientPacketHandler.java @@ -1,8 +1,7 @@ package com.direwolf20.buildinggadgets.common.network; -import com.direwolf20.buildinggadgets.common.network.S2C.LookupResult; -import com.direwolf20.buildinggadgets.common.network.bidirection.PacketSetRemoteInventoryCache; import com.direwolf20.buildinggadgets.common.network.bidirection.PacketRequestTemplate; +import com.direwolf20.buildinggadgets.common.network.bidirection.PacketSetRemoteInventoryCache; import com.direwolf20.buildinggadgets.common.network.bidirection.SplitPacketUpdateTemplate; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; @@ -12,6 +11,5 @@ public static void registerMessages() { ClientPlayNetworking.registerGlobalReceiver(PacketHandler.PacketRequestTemplate, new PacketRequestTemplate.Client()); ClientPlayNetworking.registerGlobalReceiver(PacketHandler.SplitPacketUpdateTemplate, new SplitPacketUpdateTemplate.Client()); ClientPlayNetworking.registerGlobalReceiver(PacketHandler.PacketSetRemoteInventoryCache, new PacketSetRemoteInventoryCache.Client()); - ClientPlayNetworking.registerGlobalReceiver(PacketHandler.PacketLookupResult, new LookupResult.Client()); } } diff --git a/src/main/java/com/direwolf20/buildinggadgets/common/network/S2C/LookupResult.java b/src/main/java/com/direwolf20/buildinggadgets/common/network/S2C/LookupResult.java deleted file mode 100644 index 5a69211f..00000000 --- a/src/main/java/com/direwolf20/buildinggadgets/common/network/S2C/LookupResult.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.direwolf20.buildinggadgets.common.network.S2C; - -import com.direwolf20.buildinggadgets.common.network.C2S.PacketBindTool; -import com.direwolf20.buildinggadgets.common.network.PacketHandler; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.PacketSender; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.multiplayer.ClientPacketListener; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerPlayer; - -public class LookupResult{ - - public static void sendToClient(ServerPlayer player, boolean result) { - FriendlyByteBuf buf = PacketByteBufs.create(); - buf.writeBoolean(result); - ServerPlayNetworking.send(player, PacketHandler.PacketLookupResult, buf); - } - - - public static class Client implements ClientPlayNetworking.PlayChannelHandler{ - - @Override - public void receive(Minecraft client, ClientPacketListener handler, FriendlyByteBuf buf, PacketSender responseSender) { - boolean result = buf.readBoolean(); - client.execute(() -> { - if(client.player.isShiftKeyDown() && Screen.hasControlDown() && result) - PacketBindTool.send(); - }); - } - } -} - diff --git a/src/main/java/com/direwolf20/buildinggadgets/common/tainted/inventory/InventoryLinker.java b/src/main/java/com/direwolf20/buildinggadgets/common/tainted/inventory/InventoryLinker.java index 0e1bc1d6..6f659314 100644 --- a/src/main/java/com/direwolf20/buildinggadgets/common/tainted/inventory/InventoryLinker.java +++ b/src/main/java/com/direwolf20/buildinggadgets/common/tainted/inventory/InventoryLinker.java @@ -57,9 +57,7 @@ public static Optional> getLinkedInventory(Level world, Inv return Optional.empty(); } - //TODO: Horrible hack i hope can make this better - Storage storage = null; - if(world.getBlockEntity(link.blockPos) instanceof Container) storage = InventoryStorage.of((Container) world.getBlockEntity(link.blockPos), link.face); + Storage storage = ItemStorage.SIDED.find(world, link.blockPos, link.face); if (storage == null) { // Unlink if the storage no longer exists