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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#getHeldItemOffhand() . These examples are extracted from open source projects. 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 Project: Sakura_mod   File: ItemSheath.java    License: MIT License 6 votes vote down vote up
public void sheath_In(EntityPlayer player) {
	ItemStack item_l = player.getHeldItemMainhand();
	ItemStack item_r = player.getHeldItemOffhand();
	if(item_r.getItem()==ItemLoader.KATANA){
		player.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1F, 1F);
		player.setHeldItem(EnumHand.MAIN_HAND, ItemLoader.KATANA_SHEATH.setBlade(item_r));
		player.setHeldItem(EnumHand.OFF_HAND, ItemStack.EMPTY);
	}else if(item_r.getItem()==ItemLoader.SAKURAKATANA){
		player.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1F, 1F);
		player.setHeldItem(EnumHand.MAIN_HAND, ItemLoader.SAKURAKATANA_SHEATH.setBlade(item_r));
		player.setHeldItem(EnumHand.OFF_HAND, ItemStack.EMPTY);
	}else if(item_l.getItem()==ItemLoader.KATANA){
		player.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1F, 1F);
		player.setHeldItem(EnumHand.OFF_HAND, ItemLoader.KATANA_SHEATH.setBlade(item_l));
		player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
	}else if(item_l.getItem()==ItemLoader.SAKURAKATANA){
		player.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1F, 1F);
		player.setHeldItem(EnumHand.OFF_HAND, ItemLoader.SAKURAKATANA_SHEATH.setBlade(item_l));
		player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
	}	
}
 
Example 2
Source Project: Sakura_mod   File: BlockKitunebi.java    License: MIT License 6 votes vote down vote up
private void setVisibleFlg(World world, BlockPos pos,IBlockState state) {
    world.setBlockState(pos, state.withProperty(ISVISIBLE, false));
	EntityPlayer player = world.getClosestPlayer(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, 5.0D, false);
	if(player ==null){
		world.setBlockState(pos, state.withProperty(ISVISIBLE, false));
		return;
	}
    ItemStack is = player.getHeldItemMainhand();
    ItemStack offis =player.getHeldItemOffhand();
    if (!is.isEmpty()||!offis.isEmpty()) {
    	Item mainItem = is.getItem(),offItem=offis.getItem();
        if (mainItem instanceof ItemBlock||offItem instanceof ItemBlock) {
            if (Block.getBlockFromItem(mainItem) == this||Block.getBlockFromItem(offItem) == this) {
                world.setBlockState(pos, state.withProperty(ISVISIBLE, true));
            }
        }
    }
}
 
Example 3
Source Project: pycode-minecraft   File: PythonWandItem.java    License: MIT License 6 votes vote down vote up
@Nullable
static private PythonCode getCodeFromBook(EntityPlayer player) {
    ItemStack offhand = player.getHeldItemOffhand();
    if (offhand == null) {
        FMLLog.info("... nothing in off hand so pass");
        return null;
    }

    Item offitem = offhand.getItem();
    if (offitem instanceof PythonBookItem || offitem instanceof ItemWritableBook) {
        String content = PythonCode.bookAsString(offhand);
        if (content == null) {
            PythonCode.failz0r(player.worldObj, player.getPosition(), "Could not get pages from the book!?");
            return null;
        }

        PythonCode code = new PythonCode();
        code.setCodeString(content);

        // the following will actually run the code; TODO maybe setContext could be better-named?
        code.setContext(player.worldObj, player, player.getPosition());

        return code;
    }
    return null;
}
 
Example 4
private void renderPlacementPropertiesHud(EntityPlayer player)
{
    ItemStack stack = player.getHeldItemMainhand();

    if (stack.isEmpty() || (stack.getItem() instanceof ItemBlockEnderUtilities) == false)
    {
        stack = player.getHeldItemOffhand();
    }

    if (stack.isEmpty() == false && stack.getItem() instanceof ItemBlockPlacementProperty)
    {
        ItemBlockPlacementProperty item = (ItemBlockPlacementProperty) stack.getItem();

        if (item.hasPlacementProperty(stack))
        {
            renderText(this.getPlacementPropertiesText(item, stack, player), 4, 0, HudAlignment.BOTTOM_LEFT, true, true, this.mc);
        }
    }
}
 
Example 5
protected boolean tryApplyCamouflage(EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (this.hasCamouflageAbility() && player.getHeldItemMainhand().isEmpty())
    {
        // Sneaking with an empty hand, clear the camo block
        if (player.isSneaking() && this.camoState != null)
        {
            this.removeCamouflage();
            return true;
        }

        ItemStack stackOffHand = player.getHeldItemOffhand();

        // Apply camouflage when right clicking with an empty main hand, and a block in the off hand
        if (stackOffHand.isEmpty() == false && stackOffHand.getItem() instanceof ItemBlock)
        {
            return this.applyCamouflage(player, stackOffHand, side, hitX, hitY, hitZ);
        }
    }

    return false;
}
 
Example 6
Source Project: Sakura_mod   File: PacketKeyMessageHandler.java    License: MIT License 5 votes vote down vote up
public ItemStack getHeldItemSheath(EntityPlayer player) {
	ItemStack stack = player.getHeldItemMainhand();
	if (stack.isEmpty() || !(stack.getItem() instanceof ItemSheath)) {
		stack = player.getHeldItemOffhand();
	}
	return stack;
}
 
Example 7
Source Project: Sakura_mod   File: PacketKeyMessageHandler.java    License: MIT License 5 votes vote down vote up
public boolean isPlayerHoldingSheath(EntityPlayer player) {

		if (!(!player.getHeldItemMainhand().isEmpty() || !player.getHeldItemOffhand().isEmpty())) {
			return false;
		}
		ItemStack heldItem = player.getHeldItemMainhand();
		if (heldItem.getItem() instanceof ItemSheath) {
			return true;
		}
		heldItem = player.getHeldItemOffhand();
		return heldItem.getItem() instanceof ItemSheath;
	}
 
Example 8
private ItemStack getHeldShulker(EntityPlayer entity) {
    if(entity.getHeldItemMainhand() != null && entity.getHeldItemMainhand().getItem() instanceof ItemShulkerBox) {
        return entity.getHeldItemMainhand();
    }
    if(entity.getHeldItemOffhand() != null && entity.getHeldItemOffhand().getItem() instanceof ItemShulkerBox) {
        return entity.getHeldItemOffhand();
    }
    return null;
}