|
1 | 1 | package net.neganote.gtutilities.client.event; |
2 | 2 |
|
| 3 | +import appeng.api.implementations.blockentities.IColorableBlockEntity; |
| 4 | +import appeng.api.util.AEColor; |
| 5 | +import com.gregtechceu.gtceu.GTCEu; |
| 6 | +import com.gregtechceu.gtceu.api.blockentity.IPaintable; |
| 7 | +import com.gregtechceu.gtceu.api.pipenet.IPipeNode; |
3 | 8 | import net.minecraft.client.Minecraft; |
4 | 9 | import net.minecraft.sounds.SoundEvents; |
5 | 10 | import net.minecraft.world.InteractionHand; |
| 11 | +import net.minecraft.world.item.DyeColor; |
6 | 12 | import net.minecraft.world.item.ItemStack; |
| 13 | +import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; |
| 14 | +import net.minecraft.world.phys.BlockHitResult; |
7 | 15 | import net.minecraft.world.phys.HitResult; |
8 | 16 | import net.minecraftforge.api.distmarker.Dist; |
9 | 17 | import net.minecraftforge.client.event.InputEvent; |
@@ -81,4 +89,69 @@ public static void onRightClick(InputEvent.InteractionKeyMappingTriggered event) |
81 | 89 | event.setCanceled(true); |
82 | 90 | mc.setScreen(new ColorRadialMenuScreen(InteractionHand.MAIN_HAND)); |
83 | 91 | } |
| 92 | + |
| 93 | + @SubscribeEvent |
| 94 | + public static void onKeyInput(InputEvent.InteractionKeyMappingTriggered event) { |
| 95 | + if (!event.isPickBlock()) return; |
| 96 | + |
| 97 | + var mc = Minecraft.getInstance(); |
| 98 | + if (mc.player == null) return; |
| 99 | + |
| 100 | + var player = mc.player; |
| 101 | + var stack = player.getMainHandItem(); |
| 102 | + if (!(stack.getItem() instanceof InfiniteSprayCanItem)) return; |
| 103 | + event.setCanceled(true); |
| 104 | + |
| 105 | + var target = mc.hitResult; |
| 106 | + if (target == null || target.getType() != HitResult.Type.BLOCK) return; |
| 107 | + |
| 108 | + var level = player.level(); |
| 109 | + var blockHit = (BlockHitResult) target; |
| 110 | + var pos = blockHit.getBlockPos(); |
| 111 | + var be = level.getBlockEntity(pos); |
| 112 | + |
| 113 | + if (GTCEu.Mods.isAE2Loaded() && be instanceof IColorableBlockEntity colorable) { |
| 114 | + if (colorable.getColor().equals(AEColor.TRANSPARENT)) { |
| 115 | + UtilsNetwork.CHANNEL.sendToServer(new SelectColorPacket(InteractionHand.MAIN_HAND, -1)); |
| 116 | + return; |
| 117 | + } |
| 118 | + |
| 119 | + for (AEColor color : AEColor.values()) { |
| 120 | + if (color.equals(colorable.getColor())) { |
| 121 | + UtilsNetwork.CHANNEL.sendToServer(new SelectColorPacket(InteractionHand.MAIN_HAND, color.ordinal())); |
| 122 | + return; |
| 123 | + } |
| 124 | + } |
| 125 | + } else if (be instanceof IPipeNode pipe) { |
| 126 | + if (!pipe.isPainted()) { |
| 127 | + UtilsNetwork.CHANNEL.sendToServer(new SelectColorPacket(InteractionHand.MAIN_HAND, -1)); |
| 128 | + } else { |
| 129 | + for (int i = 0; i < DyeColor.values().length; i++) { |
| 130 | + DyeColor color = DyeColor.byId(i); |
| 131 | + if (color.getMapColor().col == pipe.getPaintingColor()) { |
| 132 | + UtilsNetwork.CHANNEL.sendToServer(new SelectColorPacket(InteractionHand.MAIN_HAND, i)); |
| 133 | + return; |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + } else if (be instanceof IPaintable paintable) { |
| 138 | + if (!paintable.isPainted()) { |
| 139 | + UtilsNetwork.CHANNEL.sendToServer(new SelectColorPacket(InteractionHand.MAIN_HAND, -1)); |
| 140 | + } else { |
| 141 | + for (int i = 0; i < DyeColor.values().length; i++) { |
| 142 | + DyeColor color = DyeColor.byId(i); |
| 143 | + if (color.getMapColor().col == paintable.getRealColor()) { |
| 144 | + UtilsNetwork.CHANNEL.sendToServer(new SelectColorPacket(InteractionHand.MAIN_HAND, i)); |
| 145 | + return; |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + } else if (be instanceof ShulkerBoxBlockEntity shulkerBox) { |
| 150 | + if (shulkerBox.getColor() == null) { |
| 151 | + UtilsNetwork.CHANNEL.sendToServer(new SelectColorPacket(InteractionHand.MAIN_HAND, -1)); |
| 152 | + } else { |
| 153 | + UtilsNetwork.CHANNEL.sendToServer(new SelectColorPacket(InteractionHand.MAIN_HAND, shulkerBox.getColor().ordinal())); |
| 154 | + } |
| 155 | + } |
| 156 | + } |
84 | 157 | } |
0 commit comments