Java Code Examples for net.minecraft.util.EnumActionResult#FAIL
The following examples show how to use
net.minecraft.util.EnumActionResult#FAIL .
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: EasyPlaceUtils.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
public static boolean handleEasyPlaceWithMessage(Minecraft mc) { if (isHandling) { return false; } isHandling = true; EnumActionResult result = handleEasyPlace(mc); isHandling = false; // Only print the warning message once per right click if (isFirstClickEasyPlace && result == EnumActionResult.FAIL) { InfoUtils.showMessage(Configs.InfoOverlays.EASY_PLACE_WARNINGS.getOptionListValue(), MessageType.WARNING, 1000, "litematica.message.easy_place_fail"); } isFirstClickEasyPlace = false; return result != EnumActionResult.PASS; }
Example 2
Source File: ItemTofuHoe.java From TofuCraftReload with MIT License | 6 votes |
@Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack itemstack = player.getHeldItem(hand); if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack)) { return EnumActionResult.FAIL; } else { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (block == BlockLoader.MOMENTOFU || block == BlockLoader.tofuTerrain) { this.setBlock(itemstack, player, worldIn, pos, BlockLoader.TOFUFARMLAND.getDefaultState()); return EnumActionResult.SUCCESS; } return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); } }
Example 3
Source File: GTItemDuctTape.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
@Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { TileEntity tileEntity = worldIn.getTileEntity(pos); if (player.isSneaking()) { return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); } else if (tileEntity instanceof IInsulationModifieableConductor) { IInsulationModifieableConductor wire = (IInsulationModifieableConductor) tileEntity; if (wire.tryAddInsulation()) { player.getHeldItem(hand).damageItem(1, player); IC2.audioManager.playOnce(player, Ic2Sounds.painterUse); return EnumActionResult.SUCCESS; } else { return EnumActionResult.FAIL; } } else { return EnumActionResult.FAIL; } }
Example 4
Source File: CoverPlaceBehavior.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { TileEntity tileEntity = world.getTileEntity(pos); ICoverable coverable = tileEntity == null ? null : tileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_COVERABLE, null); if (coverable == null) { return EnumActionResult.PASS; } EnumFacing coverSide = ICoverable.rayTraceCoverableSide(coverable, player); if (coverable.getCoverAtSide(coverSide) != null || !coverable.canPlaceCoverOnSide(coverSide)) { return EnumActionResult.PASS; } if (!world.isRemote) { ItemStack itemStack = player.getHeldItem(hand); boolean result = coverable.placeCoverOnSide(coverSide, itemStack, coverDefinition); if (result && !player.capabilities.isCreativeMode) { itemStack.shrink(1); } return result ? EnumActionResult.SUCCESS : EnumActionResult.FAIL; } return EnumActionResult.SUCCESS; }
Example 5
Source File: ScaffoldModule.java From seppuku with GNU General Public License v3.0 | 6 votes |
private void placeBlock(BlockPos pos) { final Minecraft mc = Minecraft.getMinecraft(); BlockPos[][] posit = {{pos.add(0, 0, 1), pos.add(0, 0, -1)}, {pos.add(0, 1, 0), pos.add(0, -1, 0)}, {pos.add(1, 0, 0),pos.add(-1, 0, 0)}}; EnumFacing[][] facing = {{EnumFacing.NORTH, EnumFacing.SOUTH}, {EnumFacing.DOWN, EnumFacing.UP}, {EnumFacing.WEST, EnumFacing.EAST}}; // Facing reversed as blocks are placed while facing in the opposite direction for (int i=0; i<6; i++) { final Block block = mc.world.getBlockState(posit[i/2][i%2]).getBlock(); final boolean activated = block.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0); if (block != null && block != Blocks.AIR && !(block instanceof BlockLiquid)) { if (activated) mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)); if (mc.playerController.processRightClickBlock(mc.player, mc.world, posit[i/2][i%2], facing[i/2][i%2], new Vec3d(0d, 0d, 0d), EnumHand.MAIN_HAND) != EnumActionResult.FAIL) mc.player.swingArm(EnumHand.MAIN_HAND); if (activated) mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING)); } } }
Example 6
Source File: ItemSeeds.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
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 7
Source File: PythonBookItem.java From pycode-minecraft with MIT License | 5 votes |
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemstack, World world, EntityPlayer playerIn, EnumHand hand) { FMLLog.info("Book onItemRightClick stack=%s, hand=%s", itemstack, hand); // don't activate the GUI if in offhand; don't do *anything* if (hand == EnumHand.OFF_HAND) return new ActionResult(EnumActionResult.FAIL, itemstack); PyCode.proxy.openBook(playerIn, itemstack); return new ActionResult(EnumActionResult.SUCCESS, itemstack); }
Example 8
Source File: ColorSprayBehaviour.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if (!player.canPlayerEdit(pos, side, stack)) { return EnumActionResult.FAIL; } if (!tryPaintBlock(world, pos, side)) { return EnumActionResult.PASS; } useItemDurability(player, hand, stack, empty.copy()); return EnumActionResult.SUCCESS; }
Example 9
Source File: LighterBehaviour.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if (!player.canPlayerEdit(pos, side, stack)) { return EnumActionResult.FAIL; } if (!tryIgniteBlock(world, pos.offset(side))) { return EnumActionResult.PASS; } useItemDurability(player, hand, stack, ItemStack.EMPTY); return EnumActionResult.SUCCESS; }
Example 10
Source File: CrowbarBehaviour.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); IBlockState blockState = world.getBlockState(blockPos); if (GTUtility.doDamageItem(stack, cost, true)) { if (blockState.getBlock() instanceof BlockRailBase) { if (world.isRemote) { //always return success on client side return EnumActionResult.SUCCESS; } else if (player.isSneaking()) { if (tryBreakRailBlock(blockState, world, blockPos, player)) { GTUtility.doDamageItem(stack, cost, false); return EnumActionResult.SUCCESS; } return EnumActionResult.FAIL; } else { if (tryRotateRailBlock(blockState, world, blockPos)) { GTUtility.doDamageItem(stack, cost, false); return EnumActionResult.SUCCESS; } return EnumActionResult.FAIL; } } TileEntity tileEntity = world.getTileEntity(blockPos); ICoverable coverable = tileEntity == null ? null : tileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_COVERABLE, null); EnumFacing coverSide = coverable == null ? null : ICoverable.rayTraceCoverableSide(coverable, player); if (coverSide != null && coverable.getCoverAtSide(coverSide) != null) { if (world.isRemote) { //always return success on client side return EnumActionResult.SUCCESS; } boolean result = coverable.removeCover(coverSide); GTUtility.doDamageItem(stack, cost, false); return result ? EnumActionResult.SUCCESS : EnumActionResult.PASS; } } return EnumActionResult.PASS; }
Example 11
Source File: ItemEngineeringTable.java From Cyberware with MIT License | 5 votes |
/** * 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 12
Source File: ItemSyringe.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if (getItemUseAction(stack) == EnumAction.BOW) { if (world.isRemote && (Minecraft.getMinecraft().currentScreen != null)) { return new ActionResult<>(EnumActionResult.FAIL, stack); } else { player.setActiveHand(hand); return new ActionResult<>(EnumActionResult.PASS, stack); } } else return new ActionResult<>(EnumActionResult.FAIL, stack); }
Example 13
Source File: ItemSurgeryChamber.java From Cyberware with MIT License | 5 votes |
/** * 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 14
Source File: ItemBroom.java From Sakura_mod with MIT License | 5 votes |
/** * Called when a Block is right-clicked with this Item */ @Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack itemstack = player.getHeldItem(hand); if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack)) { return EnumActionResult.FAIL; } IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (facing != EnumFacing.DOWN && worldIn.getBlockState(pos.up()).getMaterial() == Material.AIR && ((worldIn.getBlockState(pos).getMaterial() == Material.GROUND||worldIn.getBlockState(pos).getMaterial() ==Material.GRASS) && !(block instanceof BlockFarmland||block instanceof BlockGrassPath))) { IBlockState iblockstate1 = Blocks.GRASS_PATH.getDefaultState(); worldIn.playSound(player, pos, SoundEvents.BLOCK_GRASS_STEP, SoundCategory.BLOCKS, 1.2F, 1.2F); worldIn.playSound(player, pos, SoundEvents.BLOCK_GRASS_PLACE, SoundCategory.BLOCKS, 1.2F, 1.2F); if (!worldIn.isRemote) { worldIn.setBlockState(pos, iblockstate1, 11); itemstack.damageItem(1, player); } return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; }
Example 15
Source File: ItemSlab.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack itemstack = player.getHeldItem(hand); if (!itemstack.isEmpty() && player.canPlayerEdit(pos.offset(facing), facing, itemstack)) { int subtype = getMetadata(itemstack); IBlockState currentState = worldIn.getBlockState(pos); if (currentState.getBlock() == singleSlab) { int subtype1 = this.singleSlabCS.getSubtype(currentState); net.minecraft.block.BlockSlab.EnumBlockHalf half = currentState.getValue(net.minecraft.block.BlockSlab.HALF); if ((facing == EnumFacing.UP && half == net.minecraft.block.BlockSlab.EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && half == net.minecraft.block.BlockSlab.EnumBlockHalf.TOP) && subtype1 == subtype) { IBlockState stateDouble = this.makeState(subtype1); AxisAlignedBB axisalignedbb = stateDouble == null ? Block.NULL_AABB : stateDouble.getCollisionBoundingBox(worldIn, pos); if (stateDouble != null && axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, stateDouble, 11)) { SoundType soundtype = stateDouble.getBlock().getSoundType(stateDouble, 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; } } return this.tryPlace(player, itemstack, worldIn, pos.offset(facing), subtype) ? EnumActionResult.SUCCESS : super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); } else { return EnumActionResult.FAIL; } }
Example 16
Source File: ItemGrowingTofu.java From TofuCraftReload with MIT License | 5 votes |
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { ItemStack itemstack = playerIn.getHeldItem(handIn); if (playerIn.canEat(false)) { playerIn.setActiveHand(handIn); return new ActionResult<>(EnumActionResult.SUCCESS, itemstack); } else { return new ActionResult<>(EnumActionResult.FAIL, itemstack); } }
Example 17
Source File: ItemFood.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
@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 18
Source File: CoverShutter.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override public EnumActionResult onRightClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) { return EnumActionResult.FAIL; }
Example 19
Source File: ItemSnow.java From customstuff4 with GNU General Public License v3.0 | 4 votes |
@Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack itemstack = player.getHeldItem(hand); if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack)) { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); BlockPos blockpos = pos; if ((facing != EnumFacing.UP || block != this.block) && !block.isReplaceable(worldIn, pos)) { blockpos = pos.offset(facing); iblockstate = worldIn.getBlockState(blockpos); block = iblockstate.getBlock(); } if (block == this.block) { int i = iblockstate.getValue(BlockSnow.LAYERS); if (i < 8) { IBlockState iblockstate1 = iblockstate.withProperty(BlockSnow.LAYERS, i + 1); AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, blockpos); if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(blockpos)) && worldIn.setBlockState(blockpos, iblockstate1, 10)) { SoundType soundtype = this.block.getSoundType(iblockstate1, worldIn, pos, player); worldIn.playSound(player, blockpos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); if (player instanceof EntityPlayerMP) { CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack); } itemstack.shrink(1); return EnumActionResult.SUCCESS; } } } return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); } else { return EnumActionResult.FAIL; } }
Example 20
Source File: ItemRiceSeed.java From TofuCraftReload with MIT License | 4 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { ItemStack itemstack = playerIn.getHeldItem(handIn); RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true); if (raytraceresult == null) { return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack); } else { if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos blockpos = raytraceresult.getBlockPos(); if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack)) { return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack); } BlockPos blockpos1 = blockpos.up(); IBlockState iblockstate = worldIn.getBlockState(blockpos); if (iblockstate.getMaterial() == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1)) { // special case for handling block placement with water lilies net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1); worldIn.setBlockState(blockpos1, BlockLoader.RICECROP.getDefaultState()); if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP, handIn).isCanceled()) { blocksnapshot.restore(true, false); return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack); } worldIn.setBlockState(blockpos1, BlockLoader.RICECROP.getDefaultState(), 11); if (playerIn instanceof EntityPlayerMP) { CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)playerIn, blockpos1, itemstack); } if (!playerIn.capabilities.isCreativeMode) { itemstack.shrink(1); } playerIn.addStat(StatList.getObjectUseStats(this)); worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack); } } return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack); } }