Java Code Examples for net.minecraft.entity.player.EntityPlayer#setCurrentItemOrArmor()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#setCurrentItemOrArmor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityDrone.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean interact(EntityPlayer player){
    ItemStack equippedItem = player.getCurrentEquippedItem();
    if(!worldObj.isRemote && equippedItem != null) {
        if(equippedItem.getItem() == Itemss.GPSTool) {
            ChunkPosition gpsLoc = ItemGPSTool.getGPSLocation(equippedItem);
            if(gpsLoc != null) {
                getNavigator().tryMoveToXYZ(gpsLoc.chunkPosX, gpsLoc.chunkPosY, gpsLoc.chunkPosZ, 0.1D);
            }
        } else {
            int dyeIndex = TileEntityPlasticMixer.getDyeIndex(equippedItem);
            if(dyeIndex >= 0) {
                setDroneColor(ItemDye.field_150922_c[dyeIndex]);
                equippedItem.stackSize--;
                if(equippedItem.stackSize <= 0) {
                    player.setCurrentItemOrArmor(0, null);
                }
            }
        }
    }
    return false;
}
 
Example 2
Source File: BlockPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
    if(player.isSneaking() || getGuiID() == null || isRotatable() && player.getCurrentEquippedItem() != null && (player.getCurrentEquippedItem().getItem() == Itemss.manometer || ModInteractionUtils.getInstance().isModdedWrench(player.getCurrentEquippedItem().getItem()))) return false;
    else {
        if(!world.isRemote) {
            TileEntity te = world.getTileEntity(x, y, z);

            List<ItemStack> returnedItems = new ArrayList<ItemStack>();
            if(te != null && !FluidUtils.tryInsertingLiquid(te, player.getCurrentEquippedItem(), player.capabilities.isCreativeMode, returnedItems)) {
                player.openGui(PneumaticCraft.instance, getGuiID().ordinal(), world, x, y, z);
            } else {
                if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().stackSize <= 0) {
                    player.setCurrentItemOrArmor(0, null);
                }
                for(ItemStack returnedItem : returnedItems) {
                    returnedItem = returnedItem.copy();
                    if(player.getCurrentEquippedItem() == null) {
                        player.setCurrentItemOrArmor(0, returnedItem);
                    } else {
                        player.inventory.addItemStackToInventory(returnedItem);
                    }
                }
            }
        }

        return true;
    }
}
 
Example 3
Source File: DroneAIBlockInteract.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
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 /*+ 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);

        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;
    }
}