Search in sources :

Example 6 with PlayerInteractEvent

use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project PneumaticCraft by MineMaarten.

the class DroneAIBlockInteract method rightClick.

private boolean rightClick(ChunkPosition pos) {
    int xCoord = pos.chunkPosX;
    int yCoord = pos.chunkPosY;
    int zCoord = pos.chunkPosZ;
    ForgeDirection faceDir = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
    EntityPlayer player = drone.getFakePlayer();
    World worldObj = drone.getWorld();
    int dx = faceDir.offsetX;
    int dy = faceDir.offsetY;
    int dz = faceDir.offsetZ;
    int x = xCoord;
    int y = yCoord;
    int z = zCoord;
    player.setPosition(x + 0.5, y + 0.5 - player.eyeHeight, z + 0.5);
    player.rotationPitch = faceDir.offsetY * -90;
    switch(faceDir) {
        case NORTH:
            player.rotationYaw = 180;
            break;
        case SOUTH:
            player.rotationYaw = 0;
            break;
        case WEST:
            player.rotationYaw = 90;
            break;
        case EAST:
            player.rotationYaw = -90;
    }
    try {
        PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(player, Action.RIGHT_CLICK_AIR, x, y, z, faceDir.ordinal(), worldObj);
        if (event.isCanceled())
            return false;
        Block block = worldObj.getBlock(x, y, z);
        ItemStack stack = player.getCurrentEquippedItem();
        if (stack != null && stack.getItem().onItemUseFirst(stack, player, worldObj, x, y, z, faceDir.ordinal(), dx, dy, dz))
            return false;
        if (!worldObj.isAirBlock(x, y, z) && block.onBlockActivated(worldObj, x, y, z, player, faceDir.ordinal(), dx, dy, dz))
            return false;
        if (stack != null) {
            boolean isGoingToShift = false;
            if (stack.getItem() instanceof ItemReed || stack.getItem() instanceof ItemRedstone) {
                isGoingToShift = true;
            }
            int useX = isGoingToShift ? xCoord : x;
            int useY = isGoingToShift ? yCoord : y;
            int useZ = isGoingToShift ? zCoord : z;
            if (stack.getItem().onItemUse(stack, player, worldObj, useX, useY, useZ, faceDir.ordinal(), dx, dy, dz))
                return false;
            ItemStack copy = stack.copy();
            player.setCurrentItemOrArmor(0, stack.getItem().onItemRightClick(stack, worldObj, player));
            if (!copy.isItemEqual(stack))
                return true;
        }
        return false;
    } catch (Throwable e) {
        Log.error("DroneAIBlockInteract crashed! Stacktrace: ");
        e.printStackTrace();
        return false;
    }
}
Also used : PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) ItemRedstone(net.minecraft.item.ItemRedstone) ItemReed(net.minecraft.item.ItemReed)

Example 7 with PlayerInteractEvent

use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project PneumaticCraft by MineMaarten.

the class TileEntityUniversalSensor method onEvent.

public void onEvent(Event event) {
    ISensorSetting sensor = SensorHandler.instance().getSensorFromPath(sensorSetting);
    if (sensor != null && sensor instanceof IEventSensorSetting && getPressure(ForgeDirection.UNKNOWN) > PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR) {
        int newRedstoneStrength = ((IEventSensorSetting) sensor).emitRedstoneOnEvent(event, this, getRange(), sensorGuiText);
        if (newRedstoneStrength != 0)
            eventTimer = ((IEventSensorSetting) sensor).getRedstonePulseLength();
        if (invertedRedstone)
            newRedstoneStrength = 15 - newRedstoneStrength;
        if (eventTimer > 0 && ThirdPartyManager.computerCraftLoaded) {
            if (event instanceof PlayerInteractEvent) {
                PlayerInteractEvent e = (PlayerInteractEvent) event;
                notifyComputers(newRedstoneStrength, e.x, e.y, e.z);
            } else {
                notifyComputers(newRedstoneStrength);
            }
        }
        if (newRedstoneStrength != redstoneStrength) {
            redstoneStrength = newRedstoneStrength;
            updateNeighbours();
        }
    }
}
Also used : IEventSensorSetting(pneumaticCraft.api.universalSensor.IEventSensorSetting) ISensorSetting(pneumaticCraft.api.universalSensor.ISensorSetting) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent)

Aggregations

PlayerInteractEvent (net.minecraftforge.event.entity.player.PlayerInteractEvent)7 ItemStack (net.minecraft.item.ItemStack)5 TileEntity (net.minecraft.tileentity.TileEntity)3 Block (net.minecraft.block.Block)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemRedstone (net.minecraft.item.ItemRedstone)2 ItemReed (net.minecraft.item.ItemReed)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 TileEntityFactory (powercrystals.minefactoryreloaded.tile.base.TileEntityFactory)2 FMLClientHandler (cpw.mods.fml.client.FMLClientHandler)1 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 PlayerLoggedInEvent (cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent)1 PlayerLoggedOutEvent (cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent)1 ClientConnectedToServerEvent (cpw.mods.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent)1 Side (cpw.mods.fml.relauncher.Side)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 IOException (java.io.IOException)1 WeakReference (java.lang.ref.WeakReference)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1