mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-11-16 18:45:01 +00:00
Co-authored-by: Martin Robertz <[email protected]> Co-authored-by: Kogepan229 <[email protected]> Co-authored-by: EnderProyects <[email protected]>
62 lines
1.9 KiB
Java
62 lines
1.9 KiB
Java
package appeng.client;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.entity.EntityClientPlayerMP;
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import appeng.core.CommonHelper;
|
|
import appeng.core.sync.network.NetworkHandler;
|
|
import appeng.core.sync.packets.PacketPickBlock;
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
import cpw.mods.fml.common.gameevent.InputEvent;
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public class KeyBindHandler {
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
@SubscribeEvent
|
|
public void onKeyInput(InputEvent.KeyInputEvent event) {
|
|
if (CommonHelper.proxy.isKeyPressed(ActionKey.PICK_BLOCK)) {
|
|
handlePickBlock();
|
|
}
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
@SubscribeEvent
|
|
public void onMouseInput(InputEvent.MouseInputEvent event) {
|
|
if (CommonHelper.proxy.isKeyPressed(ActionKey.PICK_BLOCK)) {
|
|
handlePickBlock();
|
|
}
|
|
}
|
|
|
|
private void handlePickBlock() {
|
|
Minecraft minecraft = Minecraft.getMinecraft();
|
|
if (minecraft.currentScreen != null) return; // Don't act if a GUI is open
|
|
|
|
EntityClientPlayerMP player = minecraft.thePlayer;
|
|
if (player == null) return;
|
|
|
|
// Use vanilla pick block when in creative
|
|
if (player.capabilities.isCreativeMode) {
|
|
return;
|
|
}
|
|
|
|
// Get the block the player is currently looking at
|
|
MovingObjectPosition movingObject = minecraft.objectMouseOver;
|
|
if (movingObject == null || movingObject.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) {
|
|
return;
|
|
}
|
|
|
|
final var packet = new PacketPickBlock(
|
|
movingObject.blockX,
|
|
movingObject.blockY,
|
|
movingObject.blockZ,
|
|
movingObject.sideHit,
|
|
movingObject.hitVec);
|
|
NetworkHandler.instance.sendToServer(packet);
|
|
}
|
|
|
|
}
|