private void updatePlantSaplings() { ItemStack sapling = this.getStackInSlot(0); if (this.isSaplingValid(sapling) && targetPos.getY() == this.pos.getY() //only at same level as machine && world.isAirBlock(this.targetPos) && world.isSideSolid(targetPos.down(), EnumFacing.UP)) { if (fakePlayer.get().getHeldItemOffhand().isEmpty()) { fakePlayer.get().setHeldItem(EnumHand.OFF_HAND, sapling); } //player uses the sapling with offhand fakePlayer.get().interactionManager.processRightClickBlock(fakePlayer.get(), world, sapling, EnumHand.OFF_HAND, this.targetPos.down(), EnumFacing.UP, 0.5F, 0.5F, 0.5F); } }
public static boolean placeBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nullable EnumFacing facing, @Nonnull ItemStack stack) { if (!world.isBlockLoaded(pos)) return false; FakePlayer player = new FakePlayer((WorldServer) world, placer); player.setPosition(pos.getX(), pos.getY(), pos.getZ()); player.setHeldItem(EnumHand.MAIN_HAND, stack); player.setSneaking(true); if (!hasEditPermission(pos, player)) return false; if (!world.isBlockLoaded(pos)) return false; if (world.getTileEntity(pos) == null) { if (facing == null) { for (EnumFacing enumFacing : EnumFacing.VALUES) { EnumActionResult result = player.interactionManager.processRightClickBlock( player, world, stack, EnumHand.MAIN_HAND, pos, enumFacing, 0, 0, 0); if (result != EnumActionResult.FAIL) return true; } } else { EnumActionResult result = player.interactionManager.processRightClickBlock( player, world, stack, EnumHand.MAIN_HAND, pos, facing, 0, 0, 0); return result != EnumActionResult.FAIL; } } return false; }
@Override public IHarvestResult harvestBlock(@Nonnull IFarmer farm, @Nonnull final BlockPos pos, @Nonnull IBlockState state) { if (!canHarvest(farm, pos, state) || !farm.checkAction(FarmingAction.HARVEST, FarmingTool.HOE)) { return null; } if (!farm.hasTool(FarmingTool.HOE)) { farm.setNotification(FarmNotification.NO_HOE); return null; } final HarvestResult result = new HarvestResult(); final World world = farm.getWorld(); EntityPlayerMP joe = farm.startUsingItem(FarmingTool.HOE); joe.interactionManager.processRightClickBlock(joe, joe.world, joe.getHeldItemMainhand(), EnumHand.MAIN_HAND, pos, EnumFacing.DOWN, 0, 0, 0); NNList.wrap(farm.endUsingItem(FarmingTool.HOE)).apply(new Callback<ItemStack>() { @Override public void apply(@Nonnull ItemStack drop) { result.getDrops().add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, drop.copy())); } }); farm.registerAction(FarmingAction.HARVEST, FarmingTool.HOE, state, pos); result.getHarvestedBlocks().add(pos); return result; }
boolean wasEmpty = fakePlayer.get().getHeldItemMainhand().isEmpty(); EnumActionResult result = fakePlayer.get().interactionManager.processRightClickBlock(fakePlayer.get(), world, fakePlayer.get().getHeldItemMainhand(), EnumHand.MAIN_HAND, targetPos, EnumFacing.UP, .5F, .5F, .5F);
float hitZ = (float) hit.hitVec.z - (float) pos.getZ(); EnumActionResult result = player.interactionManager.processRightClickBlock(player, world, stack, hand, pos, hit.sideHit, hitX, hitY, hitZ); if (result == EnumActionResult.SUCCESS) return MethodResult.result(true, "block"); result = player.interactionManager.processRightClickBlock(player, world, stack, hand, pos, hit.sideHit.getOpposite(), hitX, hitY, hitZ); if (result == EnumActionResult.SUCCESS) return MethodResult.result(true, "block");
player.interactionManager.processRightClickBlock(player, player.world, null, EnumHand.MAIN_HAND, pos, EnumFacing.UP, 0f, 0f, 0f);
ItemStack heldBefore = fake.getHeldItemMainhand(); setHandItemWithoutAnnoyingSound(fake, EnumHand.MAIN_HAND, stack.copy()); fake.interactionManager.processRightClickBlock(fake, world, fake.getHeldItemMainhand(), EnumHand.MAIN_HAND, offsetPos, side.getOpposite(), 0.5F, 0.5F, 0.5F); ItemStack result = fake.getHeldItem(EnumHand.MAIN_HAND); setHandItemWithoutAnnoyingSound(fake, EnumHand.MAIN_HAND, heldBefore);