下面列出了怎么用net.minecraft.util.EnumActionResult的API类实例代码及写法,或者点击链接到github查看源代码。
@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);
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);
RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, false);
if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && worldIn.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.END_PORTAL_FRAME) {
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
}
if (worldIn.isRemote) {
int j = worldIn.rand.nextInt(2) * 2 - 1;
int k = worldIn.rand.nextInt(2) * 2 - 1;
double d0 = playerIn.getPosition().getX() + 0.25D * j;
double d1 = playerIn.getPosition().getY() + 1D;
double d2 = playerIn.getPosition().getZ() + 0.25D * k;
double d3 = worldIn.rand.nextFloat() * j * 0.1D;
double d4 = (worldIn.rand.nextFloat() * 0.055D) + 0.015D;
double d5 = worldIn.rand.nextFloat() * k * 0.1D;
SakuraMain.proxy.spawnParticle(SakuraParticleType.LEAVESSAKURA, d0, d1, d2, d3, -d4, d5);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
private void handlePlaceRequest(final Minecraft minecraft, final PlacementRequest placementRequest) {
final BlockPos structurePosition = placementRequest.getStructurePosition();
final IBlockState structureBlockState = minecraft.world.getBlockState(structurePosition);
final boolean blockActivated = structureBlockState.getBlock().onBlockActivated(minecraft.world,
structurePosition, structureBlockState, minecraft.player, EnumHand.MAIN_HAND,
EnumFacing.UP, 0.0f, 0.0f, 0.0f);
if (blockActivated)
minecraft.player.connection.sendPacket(new CPacketEntityAction(minecraft.player,
CPacketEntityAction.Action.START_SNEAKING));
if (minecraft.playerController.processRightClickBlock(minecraft.player, minecraft.world,
structurePosition, placementRequest.getPlaceDirection(),
Vec3d.ZERO, EnumHand.MAIN_HAND) != EnumActionResult.FAIL)
minecraft.player.swingArm(EnumHand.MAIN_HAND);
if (blockActivated)
minecraft.player.connection.sendPacket(new CPacketEntityAction(minecraft.player,
CPacketEntityAction.Action.STOP_SNEAKING));
}
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));
}
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
if(!world.isRemote) {
String text = Math.random() >= 0.01 ? "Dab" : "Neat (is a mod by Vazkii)";
world.getMinecraftServer().getPlayerList().sendMessage(new TextComponentTranslation("chat.type.text", player.getName(), text));
if(Dabbbbb.whenUBoppin) {
for(int i = 0; i < 10; i++) {
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 1, (i / 10f) + 0.5f);
}
player.motionY += 10;
player.velocityChanged = true;
}
}
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack heldStack = player.getHeldItem(hand);
if (!player.capabilities.isCreativeMode) heldStack.shrink(1);
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_SKELETON_DEATH, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!world.isRemote) {
WorldInfo worldinfo = world.getWorldInfo();
worldinfo.setCleanWeatherTime(0);
worldinfo.setRainTime(1200);
worldinfo.setThunderTime(1200);
worldinfo.setRaining(true);
worldinfo.setThundering(false);
} else player.sendMessage(new TextComponentString("Dark clouds start forming in the sky"));
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, heldStack);
}
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand){
if(!world.isRemote) {
TileEntity te = world.getTileEntity(pos);
if(te != null) {
CapabilityDestinationProvider cap = te.getCapability(CapabilityDestinationProvider.INSTANCE, null);
if(cap != null) {
List<IDestinationProvider> providers = cap.getApplicableDestinationProviders();
List<IDestinationProvider> guiProviders = new ArrayList<>();
for(IDestinationProvider provider : providers)
if(provider.hasGui(te)) guiProviders.add(provider);
if(guiProviders.size() > 1) {
player.openGui(Signals.instance, EnumGuiId.SELECT_DESTINATION_PROVIDER.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
return EnumActionResult.SUCCESS;
} else if(!guiProviders.isEmpty()) {
guiProviders.get(0).openGui(te, player);
return EnumActionResult.SUCCESS;
}
}
}
}
return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
}
@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);
}
@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(!world.isRemote) {
TileEntity te = world.getTileEntity(pos);
if(te instanceof TileEntityStationMarker) {
TileEntityStationMarker stationMarker = (TileEntityStationMarker)te;
String stationName = stationMarker.getStationName();
appendDestination(stack, stationName);
String concatDestinations = getConcattedDestinations(stack);
player.sendMessage(new TextComponentTranslation("signals.message.added_destination", TextFormatting.GOLD + stationName + TextFormatting.WHITE, TextFormatting.GOLD + concatDestinations + TextFormatting.WHITE));
return EnumActionResult.SUCCESS;
}
}
return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!facing.equals(EnumFacing.UP))
return EnumActionResult.PASS;
if (player.canPlayerEdit(pos, facing, stack) && player.canPlayerEdit(pos.add(0, 1, 0), facing, stack)) {
IBlockState soil = world.getBlockState(pos);
if (soil != null && soil.getBlock().canSustainPlant(soil, world, pos, EnumFacing.UP, this)
&& world.isAirBlock(pos.add(0, 1, 0))
&& this.getPlant(world, pos) != null)
{
world.setBlockState(pos.add(0, 1, 0), this.getPlant(world, pos));
--stack.stackSize;
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}
@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;
}
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (world.isRemote || world.isAirBlock(pos)) {
return EnumActionResult.PASS;
}
ItemStack stack = player.getHeldItem(hand);
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity != null) {
IControllable controllable = tileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_CONTROLLABLE, side);
if (controllable != null) {
if (controllable.isWorkingEnabled()) {
controllable.setWorkingEnabled(false);
} else {
controllable.setWorkingEnabled(true);
}
GTUtility.doDamageItem(stack, cost, false);
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX,
float hitY, float hitZ, EnumHand hand) {
if (IC2.platform.isRendering()) {
IC2.audioManager.playOnce(player, Ic2Sounds.wrenchUse);
return EnumActionResult.SUCCESS;
}
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof IGTCoordinateTile) {
return tryParseCoords((IGTCoordinateTile) tileEntity, world, player, hand);
} else {
NBTTagCompound nbt = StackUtil.getOrCreateNbtData(player.getHeldItem(hand));
nbt.setIntArray(POS, new int[] { pos.getX(), pos.getY(), pos.getZ(), world.provider.getDimension() });
String blockName = world.getBlockState(pos).getBlock().getLocalizedName();
nbt.setString(BLOCK, blockName);
IC2.platform.messagePlayer(player, "Coordinates set to " + blockName);
}
return EnumActionResult.SUCCESS;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
if (playerIn.isSneaking() && playerIn.isCreative()) {
for (int i = 0; i < playerIn.inventory.getSizeInventory(); i++) {
Item item = playerIn.inventory.getStackInSlot(i).getItem();
if (!(item instanceof GTItemDestructoPack || item instanceof GTItemCreativeScanner
|| item instanceof GTItemSurvivalScanner || item instanceof GTItemMagnifyingGlass)) {
playerIn.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
}
}
return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
}
if (IC2.platform.isSimulating()) {
IC2.platform.launchGui(playerIn, this.getInventory(playerIn, handIn, playerIn.getHeldItem(handIn)), handIn);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
}
@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;
}
}
public ActionResult<ItemStack> tryPickUpFluid(@Nonnull World world, @Nonnull EntityPlayer player,
@Nonnull EnumHand hand, ItemStack itemstack, FluidStack fluidStack) {
RayTraceResult mop = this.rayTrace(world, player, true);
ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, itemstack, mop);
if (ret != null)
return ret;
if (mop == null) {
return ActionResult.newResult(EnumActionResult.PASS, itemstack);
}
BlockPos clickPos = mop.getBlockPos();
if (world.isBlockModifiable(player, clickPos)) {
FluidActionResult result = FluidUtil.tryPickUpFluid(itemstack, player, world, clickPos, mop.sideHit);
if (result.isSuccess()) {
ItemHandlerHelper.giveItemToPlayer(player, result.getResult());
itemstack.shrink(1);
return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack);
}
}
return ActionResult.newResult(EnumActionResult.FAIL, itemstack);
}
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
if (playerIn.isSneaking() && handIn == EnumHand.MAIN_HAND) {
ItemStack playerStack = playerIn.getHeldItemMainhand();
NBTTagCompound nbt = StackUtil.getOrCreateNbtData(playerStack);
if (nbt.hasKey(COLOR)) {
int i = nbt.getInteger(COLOR);
if (i + 1 > 15) {
nbt.setInteger(COLOR, 0);
} else {
nbt.setInteger(COLOR, i + 1);
}
} else {
nbt.setInteger(COLOR, 0);
}
if (!IC2.platform.isSimulating()) {
IC2.audioManager.playOnce(playerIn, Ic2Sounds.cutterUse);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
}
return ActionResult.newResult(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
}
@Override
public EnumActionResult onItemUseFirst(EntityPlayer playerIn, World world, BlockPos pos, EnumFacing side,
float hitX, float hitY, float hitZ, EnumHand handIn) {
if (!playerIn.isSneaking() && handIn == EnumHand.MAIN_HAND) {
ItemStack playerStack = playerIn.getHeldItemMainhand();
NBTTagCompound nbt = StackUtil.getNbtData(playerStack);
if (nbt.hasKey(COLOR)) {
EnumDyeColor dye = EnumDyeColor.byDyeDamage(nbt.getInteger(COLOR));
if (colorBlock(world.getBlockState(pos), world, pos, null, dye)) {
if (playerStack.getItemDamage() < playerStack.getMaxDamage()) {
playerStack.damageItem(1, playerIn);
if (!IC2.platform.isSimulating()) {
IC2.audioManager.playOnce(playerIn, Ic2Sounds.painterUse);
}
} else {
playerIn.setHeldItem(handIn, GTMaterialGen.get(GTItems.sprayCanEmpty));
if (!IC2.platform.isSimulating()) {
playerIn.playSound(SoundEvents.ENTITY_ITEM_BREAK, 1.0F, 1.0F);
}
}
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.PASS;
}
@Override
public EnumActionResult onItemUse(ItemStack stackIn, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return EnumActionResult.PASS;
}
if (stackIn.stackSize != 0) {
float yaw = player.getHorizontalFacing().getHorizontalAngle();
NBTTagCompound compound = stackIn.getTagCompound();
HandEntity entity = new HandEntity(world, compound,
pos.getX() + .5, pos.getY() + 1.0, pos.getZ() + .5, yaw);
world.spawnEntityInWorld(entity);
--stackIn.stackSize;
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.FAIL;
}
}
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;
}
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;
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
{
stack.stackSize--;
world.playSound(player, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!world.isRemote)
{
ItemStack thrown = stack.copy();
thrown.stackSize = 1;
ProjectileStone projectile = new ProjectileStone(world, player);
projectile.setStack(thrown);
projectile.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 0.5F);
world.spawnEntity(projectile);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
EntityBomb bomb = new EntityBomb(world, player);
bomb.setBombItem(stack);
bomb.setPosition(player.posX, player.posY + player.eyeHeight, player.posZ);
bomb.shoot(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);
stack.shrink(1);
world.spawnEntity(bomb);
bomb.velocityChanged = true;
}
player.getCooldownTracker().setCooldown(this, 20);
return new ActionResult<>(EnumActionResult.PASS, stack);
}
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
if (!playerIn.capabilities.isCreativeMode)
{
--stack.stackSize;
}
int xp = 0;
if (stack.hasTagCompound())
{
NBTTagCompound c = stack.getTagCompound();
if (c.hasKey("xp"))
{
xp = c.getInteger("xp");
}
}
playerIn.addExperience(xp);
return new ActionResult(EnumActionResult.SUCCESS, stack);
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (playerIn.isSneaking())
{
EnumActionResult res = super.onItemUse(stack, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
if (res == EnumActionResult.SUCCESS && playerIn.isCreative())
{
playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null;
}
return res;
}
else
{
playerIn.openGui(Cyberware.INSTANCE, 6, worldIn, 0, 0, 0);
}
return EnumActionResult.SUCCESS;
}
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
ItemStack itemstack = playerIn.getHeldItem(handIn);
if (playerIn.canEat(true)||playerIn.isCreative())
{
playerIn.setActiveHand(handIn);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
else
{
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
}
}
@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);
}
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
ItemStack item = playerIn.getHeldItem(hand);
if(item.getItem() == this &&!item.isEmpty()) {
if (side != EnumFacing.UP) {
return EnumActionResult.PASS;
} else if (playerIn.canPlayerEdit(pos, side, item) && playerIn.canPlayerEdit(pos.up(), side, item)) {
IBlockState soil = worldIn.getBlockState(pos);
if (soil != null && worldIn.isAirBlock(pos.up())) {
boolean isPlanted = false;
if (soil.getBlock() == BlockLoader.TOFUFARMLAND||soil.getBlock()==Blocks.SOUL_SAND) {
worldIn.setBlockState(pos.up(), BlockLoader.SOYBEAN_NETHER.getDefaultState());
isPlanted = true;
}
if (isPlanted) {
item.shrink(1);
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.PASS;
}
} else {
return EnumActionResult.PASS;
}
//return EnumActionResult.PASS;
}
return EnumActionResult.PASS;
}
else
{
return EnumActionResult.PASS;
}
}
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);
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
ItemStack stack = playerIn.getHeldItem(handIn);
playerIn.getCooldownTracker().setCooldown(stack.getItem(), 100);
playerIn.playSound(TofuSounds.TOFUBUGLE, 20.0F, 1.0F);
playerIn.addStat(StatList.getObjectUseStats(this));
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}