net.minecraft.util.EnumHand Java Examples

The following examples show how to use net.minecraft.util.EnumHand. 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: BlockAltarConfession.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	ItemStack heldItem = playerIn.getHeldItem(hand);

	//if (isStructureComplete(worldIn, pos)) {
	TileHaloInfuser infuser = getTE(worldIn, pos);
	if (infuser == null) return heldItem.isEmpty();

	if (!infuser.getHalo().isEmpty()) {
		playerIn.setHeldItem(hand, infuser.extractHalo());
		playerIn.openContainer.detectAndSendChanges();
	} else if (heldItem.getItem() == ModItems.FAKE_HALO) {
		infuser.setHalo(heldItem);
		playerIn.setHeldItem(hand, ItemStack.EMPTY);
		playerIn.openContainer.detectAndSendChanges();
	}
	//}
	return heldItem.isEmpty();
}
 
Example #2
Source File: BlockManipulator.java    From OpenModsLib with MIT License 6 votes vote down vote up
public boolean place(IBlockState state, EnumFacing direction, EnumHand hand) {
	if (!world.isBlockLoaded(blockPos)) return false;

	if (spawnProtection) {
		if (!world.isBlockModifiable(player, blockPos)) return false;
	}

	final BlockSnapshot snapshot = BlockSnapshot.getBlockSnapshot(world, blockPos);

	if (!world.setBlockState(blockPos, state, blockPlaceFlags)) return false;

	if (ForgeEventFactory.onPlayerBlockPlace(player, snapshot, direction, hand).isCanceled()) {
		world.restoringBlockSnapshots = true;
		snapshot.restore(true, false);
		world.restoringBlockSnapshots = false;
		return false;
	}

	return true;
}
 
Example #3
Source File: BlockBlueprintArchive.java    From Cyberware with MIT License 6 votes vote down vote up
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
	TileEntity tileentity = worldIn.getTileEntity(pos);
	
	if (tileentity instanceof TileEntityBlueprintArchive)
	{
		/*if (player.isCreative() && player.isSneaking())
		{
			TileEntityScanner scanner = ((TileEntityScanner) tileentity);
			scanner.ticks = CyberwareConfig.SCANNER_TIME - 200;
		}*/
		player.openGui(Cyberware.INSTANCE, 4, worldIn, pos.getX(), pos.getY(), pos.getZ());
	}
	
	return true;
	
}
 
Example #4
Source File: BlockSuperchestPart.java    From YouTubeModdingTutorial with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (player.getHeldItem(hand).getItem() == Items.STICK) {
        BlockSuperchest.toggleMultiBlock(world, pos, state, player);
        return true;
    }
    // Only work if the block is formed
    if (state.getBlock() == ModBlocks.blockSuperchestPart && state.getValue(FORMED) != SuperchestPartIndex.UNFORMED) {
        // Find the controller
        BlockPos controllerPos = BlockSuperchest.getControllerPos(world, pos);
        if (controllerPos != null) {
            IBlockState controllerState = world.getBlockState(controllerPos);
            return controllerState.getBlock().onBlockActivated(world, controllerPos, controllerState, player, hand, facing, hitX, hitY, hitZ);
        }
    }
    return false;
}
 
Example #5
Source File: ItemClayBall.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
	ItemStack itemStackIn = playerIn.getHeldItem(handIn);

	if(itemStackIn.getCount() < 5)
	{
		return new ActionResult(EnumActionResult.FAIL, itemStackIn);
	}

	PlayerInfo pi = PlayerManagerTFC.getInstance().getPlayerInfoFromPlayer(playerIn);
	pi.specialCraftingType = new ItemStack(itemStackIn.getItem());
	pi.specialCraftingTypeAlternate = new ItemStack(itemStackIn.getItem());
	if(!worldIn.isRemote)
		playerIn.openGui(TFC.instance, 0, worldIn, playerIn.getPosition().getX(), playerIn.getPosition().getY(), playerIn.getPosition().getZ());

	return new ActionResult(EnumActionResult.PASS, itemStackIn);
}
 
Example #6
Source File: ItemSeeds.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
	ItemStack stack = playerIn.getHeldItem(hand);
	if(worldIn.isRemote)
		return EnumActionResult.FAIL;

	IBlockState soil = worldIn.getBlockState(pos);
	if(facing == EnumFacing.UP && soil.getBlock() == TFCBlocks.Farmland && worldIn.isAirBlock(pos.up()))
	{
		//worldIn.setBlockState(pos.up(), TFCBlocks.Crop.getDefaultState());
		TileCrop tc = (TileCrop) worldIn.getTileEntity(pos.up());
		tc.setCropType(cropToPlant[stack.getItemDamage()]);
		tc.setFarmerID(playerIn);
	}

	return EnumActionResult.SUCCESS;
}
 
Example #7
Source File: BlockApricotLeaves.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
                                EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (worldIn.isRemote) {
        return true;
    } else {

        int age = state.getValue(STAGE).intValue();
        if (age == 3) {
            IBlockState back = state.withProperty(STAGE, 1);

            worldIn.setBlockState(pos, back, 2);

            spawnAsEntity(worldIn, pos, new ItemStack(ItemLoader.foodsetContain, 1, 14));
        }
        return true;
    }
}
 
Example #8
Source File: ItemSeeds.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    ItemStack itemstack = player.getHeldItem(hand);
    IBlockState state = worldIn.getBlockState(pos);
    if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, itemstack) && state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this) && worldIn.isAirBlock(pos.up()))
    {
        worldIn.setBlockState(pos.up(), content.plant.createState());

        if (player instanceof EntityPlayerMP)
        {
            CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos.up(), itemstack);
        }

        itemstack.shrink(1);
        return EnumActionResult.SUCCESS;
    } else
    {
        return EnumActionResult.FAIL;
    }
}
 
Example #9
Source File: ItemPickupManager.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);

    if (world.isRemote == false)
    {
        // These two lines are to fix the UUID being missing the first time the GUI opens,
        // if the item is grabbed from the creative inventory or from JEI or from /give
        NBTUtils.getUUIDFromItemStack(stack, "UUID", true);
        player.openContainer.detectAndSendChanges();

        player.openGui(EnderUtilities.instance, ReferenceGuiIds.GUI_ID_PICKUP_MANAGER, world,
                (int)player.posX, (int)player.posY, (int)player.posZ);
    }

    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example #10
Source File: GTItemSensorStick.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static EnumActionResult tryParseCoords(IGTCoordinateTile coordTile, World world, EntityPlayer player,
		EnumHand hand) {
	NBTTagCompound nbt = StackUtil.getNbtData(player.getHeldItem(hand));
	if (nbt.getIntArray(POS).length == 4) {
		int[] posArr = nbt.getIntArray(POS);
		if (!coordTile.isInterdimensional() && posArr[3] != world.provider.getDimension()) {
			IC2.platform.messagePlayer(player, "This machine does not support interdimensional communication");
			return EnumActionResult.SUCCESS;
		}
		ItemStack playerStack = player.getHeldItem(hand);
		if (coordTile.insertSensorStick(playerStack)) {
			coordTile.applyCoordinates(new BlockPos(posArr[0], posArr[1], posArr[2]), posArr[3]);
			player.getHeldItem(hand).shrink(1);
			IC2.platform.messagePlayer(player, "Sensor Stick successfully installed into machine!");
			return EnumActionResult.SUCCESS;
		} else {
			IC2.platform.messagePlayer(player, "Sensor Stick already found in machine");
			return EnumActionResult.SUCCESS;
		}
	}
	IC2.platform.messagePlayer(player, "Sensor Card cannot be installed in this!");
	return EnumActionResult.SUCCESS;
}
 
Example #11
Source File: GTHelperFluid.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static boolean doClickableFluidContainerFillThings(EntityPlayer player, EnumHand hand, World world,
		BlockPos pos, IC2Tank tank) {
	ItemStack playerStack = player.getHeldItem(hand);
	if (!playerStack.isEmpty()) {
		FluidActionResult result = FluidUtil.tryFillContainer(playerStack, tank, tank.getCapacity(), player, true);
		if (result.isSuccess()) {
			playerStack.shrink(1);
			ItemStack resultStack = result.getResult();
			if (!resultStack.isEmpty()) {
				if (!player.inventory.addItemStackToInventory(resultStack)) {
					player.dropItem(resultStack, false);
				}
			}
			return true;
		}
	}
	return false;
}
 
Example #12
Source File: ItemRailConfigurator.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
    ItemStack stack = playerIn.getHeldItem(hand);
    if(!worldIn.isRemote) {
        TileEntity te = worldIn.getTileEntity(pos);
        if(te instanceof TileEntityRailLinkBase && playerIn.isSneaking()) {
            TileEntityRailLinkBase railLinkBase = (TileEntityRailLinkBase)te;
            MCPos railPos = getLinkedRail(stack);
            if(railPos != null) {
                if(railLinkBase.setLinkedPos(railPos, playerIn)) {
                    playerIn.sendMessage(new TextComponentString("Linked to " + railPos));
                }
            }
        } else {
            IBlockState state = worldIn.getBlockState(pos);
            IRail r = RailManager.getInstance().getRail(worldIn, pos, state);

            if(r != null) {
                setLinkedRail(stack, new MCPos(worldIn, pos));
                playerIn.sendMessage(new TextComponentString("Pos: " + pos));
            }
        }
    }
    return super.onItemUse(playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
 
Example #13
Source File: ItemInventorySwapper.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (player.isSneaking())
    {
        TileEntity te = world.getTileEntity(pos);

        if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side))
        {
            IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);

            if (world.isRemote == false && inv != null)
            {
                this.swapInventory(player.getHeldItem(hand), inv, player);
            }

            return EnumActionResult.SUCCESS;
        }
    }

    return super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
}
 
Example #14
Source File: PipeBlocking.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY) {
	super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY);
	if(playerIn.getHeldItemMainhand()==null) {
		TileEntity target = worldIn.getTileEntity(pos);
		if(target instanceof TileBasicPipe) {
			if(((TileBasicPipe) target).hasNetwork()) {
				//Add Debug routing on Activation
				return true;
			}
		}
	}
	
	return false;
}
 
Example #15
Source File: TileEntityEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #16
Source File: ItemHandyBag.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);

    if (world.isRemote == false)
    {
        // These two lines are to fix the UUID being missing the first time the GUI opens,
        // if the item is grabbed from the creative inventory or from JEI or from /give
        NBTUtils.getUUIDFromItemStack(stack, "UUID", true);
        player.openContainer.detectAndSendChanges();

        player.openGui(EnderUtilities.instance, ReferenceGuiIds.GUI_ID_HANDY_BAG_RIGHT_CLICK, world,
                (int)player.posX, (int)player.posY, (int)player.posZ);
    }

    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example #17
Source File: PipeBasic.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY) {
	super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY);
	if(playerIn.getHeldItemMainhand()==null) {
		TileEntity target = worldIn.getTileEntity(pos);
		if(target instanceof TileBasicPipe) {
			if(((TileBasicPipe) target).hasNetwork()) {
				//Add Debug routing on Activation
				return true;
			}
		}
	}
	
	return false;
}
 
Example #18
Source File: ItemTraverseWoodDoor.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (facing != EnumFacing.UP) {
        return EnumActionResult.FAIL;
    }
    else {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();

        if (!block.isReplaceable(worldIn, pos)) {
            pos = pos.offset(facing);
        }

        ItemStack itemstack = player.getHeldItem(hand);

        if (player.canPlayerEdit(pos, facing, itemstack) && this.block.canPlaceBlockAt(worldIn, pos)) {
            EnumFacing enumfacing = EnumFacing.fromAngle((double) player.rotationYaw);
            int i = enumfacing.getXOffset();
            int j = enumfacing.getYOffset();
            boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F;
            placeDoor(worldIn, pos, enumfacing, this.block, flag);
            SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player);
            worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            itemstack.shrink(1);
            return EnumActionResult.SUCCESS;
        }
        else {
            return EnumActionResult.FAIL;
        }
    }
}
 
Example #19
Source File: ItemEnderTool.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean useHoeToPlant(ItemStack toolStack, EntityPlayer player, EnumHand hand,
        World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (UtilItemModular.useEnderCharge(toolStack, ENDER_CHARGE_COST, true) == false)
    {
        return false;
    }

    IItemHandler inv = this.getLinkedInventoryWithChecks(toolStack, player);

    if (inv != null)
    {
        for (int slot = 0; slot < inv.getSlots(); slot++)
        {
            if (this.plantItemFromInventorySlot(world, player, hand, inv, slot, pos, side, hitX, hitY, hitZ))
            {
                // Use Ender Charge if planting from a remote inventory
                if (DropsMode.fromStack(toolStack) == DropsMode.REMOTE)
                {
                    UtilItemModular.useEnderCharge(toolStack, ENDER_CHARGE_COST, false);
                }

                Effects.addItemTeleportEffects(world, pos);

                return true;
            }
        }
    }

    return false;
}
 
Example #20
Source File: ItemSurgeryChamber.java    From Cyberware with MIT License 5 votes vote down vote up
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
	if (facing != EnumFacing.UP)
	{
		return EnumActionResult.FAIL;
	}
	else
	{
		IBlockState iblockstate = worldIn.getBlockState(pos);
		Block block = iblockstate.getBlock();

		if (!block.isReplaceable(worldIn, pos))
		{
			pos = pos.offset(facing);
		}

		if (playerIn.canPlayerEdit(pos, facing, stack) && this.block.canPlaceBlockAt(worldIn, pos))
		{
			EnumFacing enumfacing = EnumFacing.fromAngle((double)playerIn.rotationYaw);
			int i = enumfacing.getFrontOffsetX();
			int j = enumfacing.getFrontOffsetZ();
			placeDoor(worldIn, pos, enumfacing, this.block);
			SoundType soundtype = this.block.getSoundType();
			worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
			--stack.stackSize;
			return EnumActionResult.SUCCESS;
		}
		else
		{
			return EnumActionResult.FAIL;
		}
	}
}
 
Example #21
Source File: BlockPhysicsInfuser.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,
    EntityPlayer playerIn,
    EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        playerIn
            .openGui(ValkyrienSkiesMod.INSTANCE, VS_Gui_Enum.PHYSICS_INFUSER.ordinal(), worldIn,
                pos.getX(), pos.getY(), pos.getZ());
    }
    return true;
}
 
Example #22
Source File: EntityUIStar.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public boolean processInitialInteract(EntityPlayer player, EnumHand hand) {
	if(!world.isRemote && tile != null) {
		tile.selectSystem(star.getId() + starIDoffset);
	}
	return true;
}
 
Example #23
Source File: EntitySentry.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);

	setCanPickUpLoot(true);
	setEquipmentBasedOnDifficulty(difficulty);
	setEnchantmentBasedOnDifficulty(difficulty);

	setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.IRON_SWORD, 1));

	addArmor();

	return livingdata;
}
 
Example #24
Source File: EntityChair.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean processInitialInteract(EntityPlayer player, EnumHand hand)
{
    if (player.getEntityWorld().isRemote == false && this.getPassengers().contains(player) == false)
    {
        player.startRiding(this);
        return true;
    }

    return false;
}
 
Example #25
Source File: ItemGeneric.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
	final ItemStack itemStack = player.getHeldItem(hand);
	IMetaItem meta = getMeta(itemStack.getMetadata());
	return meta != null
			? meta.onItemRightClick(itemStack, world, player, hand)
			: ActionResult.newResult(EnumActionResult.PASS, itemStack);
}
 
Example #26
Source File: ItemFood.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack stack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(content.alwaysEdible.get(stack.getMetadata()).orElse(false)))
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    } else
    {
        return new ActionResult<>(EnumActionResult.FAIL, stack);
    }
}
 
Example #27
Source File: BlockShoji.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    state = state.cycleProperty(OPEN);
    worldIn.setBlockState(pos, state, 10);
    worldIn.markBlockRangeForRenderUpdate(pos, pos);
    worldIn.playEvent(playerIn, state.getValue(OPEN) ? 1006 : 1012, pos, 0);
    TileEntityShoji te = (TileEntityShoji) worldIn.getTileEntity(pos);
    if (te != null) {
        te.setOpen(!te.isOpen());
        te.setAnimation(10);
    }
    return true;
}
 
Example #28
Source File: BlockElevator.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    ItemStack stack = EntityUtils.getHeldItemOfType(player, ItemDye.class);

    if (stack.isEmpty() == false)
    {
        EnumDyeColor stackColor = EnumDyeColor.byDyeDamage(stack.getMetadata());

        if (state.getValue(COLOR) != stackColor)
        {
            if (world.isRemote == false)
            {
                world.setBlockState(pos, state.withProperty(COLOR, stackColor), 3);
                world.playSound(null, pos, SoundEvents.ENTITY_ITEMFRAME_ADD_ITEM, SoundCategory.BLOCKS, 1f, 1f);

                if (player.capabilities.isCreativeMode == false)
                {
                    stack.shrink(1);
                }
            }

            return true;
        }

        return false;
    }
    else
    {
        return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
    }
}
 
Example #29
Source File: ItemUpgradeDirectional.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
	ItemStack stack = player.getHeldItem(hand);
	if (!world.isRemote) {
		setSide(stack, null);
		player.sendMessage(ServerUtil.getChatForString(getTooltipName(stack)));
	}
	return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
 
Example #30
Source File: BlockRedstoneEmitter.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos,
		IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY,
		float hitZ) {
	if(!world.isRemote) {
		player.openGui(LibVulpes.instance, GuiHandler.guiId.MODULARNOINV.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
	}
	return true;
}