Search in sources :

Example 1 with PlayerInteractEvent

use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project MineFactoryReloaded by powercrystals.

the class BlockRedNetCable method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset) {
    PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, x, y, z, side);
    if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.useBlock == Result.DENY) {
        return false;
    }
    TileEntity te = world.getBlockTileEntity(x, y, z);
    if (te instanceof TileEntityRedNetCable) {
        TileEntityRedNetCable cable = (TileEntityRedNetCable) te;
        int subHit = getPartClicked(player, 3.0F, cable);
        if (subHit < 0) {
            return false;
        }
        side = _partSideMappings[subHit];
        ItemStack s = player.inventory.getCurrentItem();
        if (side >= 0) {
            if (MFRUtil.isHoldingHammer(player)) {
                if (!world.isRemote) {
                    int nextColor;
                    if (!player.isSneaking()) {
                        nextColor = cable.getSideColor(ForgeDirection.getOrientation(side)) + 1;
                        if (nextColor > 15)
                            nextColor = 0;
                    } else {
                        nextColor = cable.getSideColor(ForgeDirection.getOrientation(side)) - 1;
                        if (nextColor < 0)
                            nextColor = 15;
                    }
                    cable.setSideColor(ForgeDirection.getOrientation(side), nextColor);
                    world.markBlockForUpdate(x, y, z);
                    return true;
                }
            } else if (s != null && s.itemID == Item.dyePowder.itemID) {
                if (!world.isRemote) {
                    cable.setSideColor(ForgeDirection.getOrientation(side), 15 - s.getItemDamage());
                    world.markBlockForUpdate(x, y, z);
                    return true;
                }
            }
        } else if (MFRUtil.isHoldingHammer(player)) {
            byte mode = cable.getMode();
            mode++;
            if (mode > 2) {
                mode = 0;
            }
            cable.setMode(mode);
            if (!world.isRemote) {
                PacketDispatcher.sendPacketToAllAround(x, y, z, 50, world.provider.dimensionId, cable.getDescriptionPacket());
                if (mode == 0) {
                    player.sendChatToPlayer("Set cable to standard connection mode");
                } else if (mode == 1) {
                    player.sendChatToPlayer("Set cable to forced-connection mode");
                } else if (mode == 2) {
                    player.sendChatToPlayer("Set cable to cable-only connection mode");
                }
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) TileEntityRedNetCable(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable) ItemStack(net.minecraft.item.ItemStack)

Example 2 with PlayerInteractEvent

use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project MineFactoryReloaded by powercrystals.

the class BlockRedNetPanel method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset) {
    PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, x, y, z, side);
    if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.useBlock == Result.DENY) {
        return false;
    }
    ItemStack s = player.inventory.getCurrentItem();
    TileEntity te = world.getBlockTileEntity(x, y, z);
    if (MFRUtil.isHoldingHammer(player) && te instanceof TileEntityFactory && ((TileEntityFactory) te).canRotate()) {
        ((TileEntityFactory) te).rotate();
        world.markBlockForUpdate(x, y, z);
        return true;
    } else if (te instanceof TileEntityFactory && ((TileEntityFactory) te).getContainer(player.inventory) != null) {
        player.openGui(MineFactoryReloadedCore.instance(), 0, world, x, y, z);
        return true;
    } else if (te instanceof TileEntityRedNetHistorian && s != null && s.itemID == Item.dyePowder.itemID) {
        ((TileEntityRedNetHistorian) te).setSelectedSubnet(15 - s.getItemDamage());
        world.markBlockForUpdate(x, y, z);
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFactory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactory) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) ItemStack(net.minecraft.item.ItemStack) TileEntityRedNetHistorian(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetHistorian)

Example 3 with PlayerInteractEvent

use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project MineFactoryReloaded by powercrystals.

the class BlockFactoryMachine method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float xOffset, float yOffset, float zOffset) {
    PlayerInteractEvent e = new PlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, x, y, z, side);
    if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.useBlock == Result.DENY) {
        return false;
    }
    TileEntity te = world.getBlockTileEntity(x, y, z);
    if (te == null) {
        return false;
    }
    if (te instanceof ITankContainerBucketable && LiquidContainerRegistry.isEmptyContainer(entityplayer.inventory.getCurrentItem()) && ((ITankContainerBucketable) te).allowBucketDrain()) {
        if (MFRLiquidMover.manuallyDrainTank((ITankContainerBucketable) te, entityplayer)) {
            return true;
        }
    } else if (te instanceof ITankContainerBucketable && LiquidContainerRegistry.isFilledContainer(entityplayer.inventory.getCurrentItem()) && ((ITankContainerBucketable) te).allowBucketFill()) {
        if (MFRLiquidMover.manuallyFillTank((ITankContainerBucketable) te, entityplayer)) {
            return true;
        }
    }
    if (MFRUtil.isHoldingHammer(entityplayer) && te instanceof TileEntityFactory && ((TileEntityFactory) te).canRotate()) {
        ((TileEntityFactory) te).rotate();
        world.markBlockForUpdate(x, y, z);
        return true;
    } else if (te instanceof TileEntityFactory && ((TileEntityFactory) te).getContainer(entityplayer.inventory) != null) {
        if (!world.isRemote) {
            entityplayer.openGui(MineFactoryReloadedCore.instance(), 0, world, x, y, z);
        }
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFactory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactory) ITankContainerBucketable(powercrystals.minefactoryreloaded.core.ITankContainerBucketable) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent)

Example 4 with PlayerInteractEvent

use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project BluePower by Qmunity.

the class TileDeployer method rightClick.

/**
     * Be sure to set up the fake player's hotbar with the right clicked items. starting with hotbar slot 0.
     * @param player
     * @param useItems this method will set the current selected slot of the fake player to 0, and move on to the next slot useItems - 1 times.
     *          So to use the first slot only, pass 1, to use the full hotbar, 9.
     * @return
     */
protected boolean rightClick(FakePlayer player, int useItems) {
    if (useItems > 9)
        throw new IllegalArgumentException("Hotbar is 9 items in width! You're trying " + useItems + "!");
    ForgeDirection faceDir = getFacingDirection();
    int dx = faceDir.offsetX;
    int dy = faceDir.offsetY;
    int dz = faceDir.offsetZ;
    int x = xCoord + dx;
    int y = yCoord + dy;
    int z = zCoord + dz;
    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);
        List<EntityLivingBase> detectedEntities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1));
        Entity entity = detectedEntities.isEmpty() ? null : detectedEntities.get(worldObj.rand.nextInt(detectedEntities.size()));
        if (entity != null) {
            for (int i = 0; i < useItems; i++) {
                player.inventory.currentItem = i;
                ItemStack stack = player.getCurrentEquippedItem();
                if (canDeployItem(stack) && stack.getItem().itemInteractionForEntity(stack, player, (EntityLivingBase) entity))
                    return true;
                if (entity instanceof EntityAnimal && ((EntityAnimal) entity).interact(player))
                    return true;
            }
        }
        for (int i = 0; i < useItems; i++) {
            player.inventory.currentItem = i;
            ItemStack stack = player.getCurrentEquippedItem();
            if (canDeployItem(stack) && stack.getItem().onItemUseFirst(stack, player, worldObj, x, y, z, faceDir.ordinal(), dx, dy, dz))
                return true;
        }
        for (int i = 0; i < useItems; i++) {
            player.inventory.currentItem = i;
            if (!worldObj.isAirBlock(x, y, x) && block.onBlockActivated(worldObj, x, y, z, player, faceDir.ordinal(), dx, dy, dz))
                return true;
        }
        for (int i = 0; i < useItems; i++) {
            player.inventory.currentItem = i;
            ItemStack stack = player.getCurrentEquippedItem();
            boolean isGoingToShift = false;
            if (stack != null) {
                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 (canDeployItem(stack) && stack.getItem().onItemUse(stack, player, worldObj, useX, useY, useZ, faceDir.ordinal(), dx, dy, dz))
                return true;
        }
        for (int i = 0; i < useItems; i++) {
            player.inventory.currentItem = i;
            ItemStack stack = player.getCurrentEquippedItem();
            if (canDeployItem(stack)) {
                ItemStack copy = stack.copy();
                player.setCurrentItemOrArmor(0, stack.getItem().onItemRightClick(stack, worldObj, player));
                if (!copy.isItemEqual(stack))
                    return true;
            }
        }
        return false;
    } catch (Throwable e) {
        BluePower.log.error("Deployer crashed! Stacktrace: ");
        e.printStackTrace();
        return true;
    }
}
Also used : Entity(net.minecraft.entity.Entity) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) ItemRedstone(net.minecraft.item.ItemRedstone) ItemReed(net.minecraft.item.ItemReed) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) EntityAnimal(net.minecraft.entity.passive.EntityAnimal)

Example 5 with PlayerInteractEvent

use of net.minecraftforge.event.entity.player.PlayerInteractEvent in project LogisticsPipes by RS485.

the class LogisticsEventListener method onPlayerInteract.

@SubscribeEvent
public void onPlayerInteract(final PlayerInteractEvent event) {
    if (MainProxy.isServer(event.entityPlayer.worldObj)) {
        if (event.action == Action.LEFT_CLICK_BLOCK) {
            final TileEntity tile = event.entityPlayer.worldObj.getTileEntity(event.x, event.y, event.z);
            if (tile instanceof LogisticsTileGenericPipe) {
                if (((LogisticsTileGenericPipe) tile).pipe instanceof CoreRoutedPipe) {
                    if (!((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).canBeDestroyedByPlayer(event.entityPlayer)) {
                        event.setCanceled(true);
                        event.entityPlayer.addChatComponentMessage(new ChatComponentTranslation("lp.chat.permissiondenied"));
                        ((LogisticsTileGenericPipe) tile).scheduleNeighborChange();
                        event.entityPlayer.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
                        ((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).delayTo = System.currentTimeMillis() + 200;
                        ((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).repeatFor = 10;
                    } else {
                        ((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).setDestroyByPlayer();
                    }
                }
            }
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK) {
            WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(event.entityPlayer.worldObj, event.x, event.y, event.z);
            TileEntity tileEntity = worldCoordinates.getTileEntity();
            if (tileEntity instanceof TileEntityChest || SimpleServiceLocator.ironChestProxy.isIronChest(tileEntity)) {
                //@formatter:off
                List<WeakReference<ModuleQuickSort>> list = worldCoordinates.getAdjacentTileEntities().filter(adjacent -> adjacent.tileEntity instanceof LogisticsTileGenericPipe).filter(adjacent -> ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof PipeLogisticsChassi).filter(adjacent -> ((PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getPointedOrientation() == adjacent.direction.getOpposite()).map(adjacent -> (PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).flatMap(pipeLogisticsChassi -> Arrays.stream(pipeLogisticsChassi.getModules().getModules())).filter(logisticsModule -> logisticsModule instanceof ModuleQuickSort).map(logisticsModule -> new WeakReference<>((ModuleQuickSort) logisticsModule)).collect(Collectors.toList());
                if (!list.isEmpty()) {
                    LogisticsEventListener.chestQuickSortConnection.put(event.entityPlayer, list);
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Action(net.minecraftforge.event.entity.player.PlayerInteractEvent.Action) Arrays(java.util.Arrays) ModuleQuickSort(logisticspipes.modules.ModuleQuickSort) MainProxy(logisticspipes.proxy.MainProxy) VersionChecker(logisticspipes.ticks.VersionChecker) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) Configs(logisticspipes.config.Configs) ChestGuiOpened(logisticspipes.network.packets.chassis.ChestGuiOpened) ChatComponentText(net.minecraft.util.ChatComponentText) LogisticsHUDRenderer(logisticspipes.renderer.LogisticsHUDRenderer) LogisticsGuiOverrenderer(logisticspipes.renderer.LogisticsGuiOverrenderer) Map(java.util.Map) FMLClientHandler(cpw.mods.fml.client.FMLClientHandler) PlayerLoggedInEvent(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent) PlayerLoggedOutEvent(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent) ClientConnectedToServerEvent(cpw.mods.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent) EntityItem(net.minecraft.entity.item.EntityItem) ChestGuiClosed(logisticspipes.network.packets.chassis.ChestGuiClosed) Side(cpw.mods.fml.relauncher.Side) SideOnly(cpw.mods.fml.relauncher.SideOnly) UnWatch(net.minecraftforge.event.world.ChunkWatchEvent.UnWatch) WorldEvent(net.minecraftforge.event.world.WorldEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PacketHandler(logisticspipes.network.PacketHandler) Collectors(java.util.stream.Collectors) List(java.util.List) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent) PlayerIdentifier(logisticspipes.utils.PlayerIdentifier) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Queue(java.util.Queue) PlayerConfig(logisticspipes.config.PlayerConfig) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) Setter(lombok.Setter) Getter(lombok.Getter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) GuiReopenPacket(logisticspipes.network.packets.gui.GuiReopenPacket) HashMap(java.util.HashMap) PlayerConfigToClientPacket(logisticspipes.network.packets.PlayerConfigToClientPacket) Watch(net.minecraftforge.event.world.ChunkWatchEvent.Watch) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ItemStack(net.minecraft.item.ItemStack) IItemAdvancedExistance(logisticspipes.interfaces.IItemAdvancedExistance) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) EntityClientPlayerMP(net.minecraft.client.entity.EntityClientPlayerMP) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) WeakHashMap(java.util.WeakHashMap) IOException(java.io.IOException) GuiChest(net.minecraft.client.gui.inventory.GuiChest) GuiOpenEvent(net.minecraftforge.client.event.GuiOpenEvent) QuickSortChestMarkerStorage(logisticspipes.utils.QuickSortChestMarkerStorage) TileEntity(net.minecraft.tileentity.TileEntity) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) AllArgsConstructor(lombok.AllArgsConstructor) TileEntityChest(net.minecraft.tileentity.TileEntityChest) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) WeakReference(java.lang.ref.WeakReference) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ModuleQuickSort(logisticspipes.modules.ModuleQuickSort) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

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